.NET and Bricscad
Hi all, I have updated my netloader modules for Bricscad, I have posted them over at TheSwamp http://www.theswamp.org/index.php?topic=21601.msg297496#msg297496Here are a couple of quick samples in C#.
using System;using System.Collections.Generic;using BricscadApp;using BricscadDb;using DRXNET.OdRx;namespace DRXNET_DBG_05{ public class SampleComCommands { [CommandMethod("MyForm")] public static void LoadMyForm() { try { MyForm frm = new MyForm(); DRXNET.OdAp.Application.ShowModalForm(frm); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } [CommandMethod("AddLayer")] public static void AddLayer() { try { string LayerName = "MyNewLayer"; AcadApplication application = DRXNET.OdAp.Application.AcadApplication as AcadApplication; if (application == null) throw new System.Exception("Could Not Get Application"); AcadDocument document = application.ActiveDocument; AcadDatabase Database = document.Database; AcadLayers layers = Database.Layers; bool flag = false; foreach (AcadLayer l in layers) { if (l.Name.ToLower() == LayerName.ToLower()) flag = true; } if (flag == false) { AcadLayer layer = layers.Add(LayerName); layer.color = AcColor.acBlue; layer.Description = "Cool New Layer"; layer.Lineweight = ACAD_LWEIGHT.acLnWt009; System.Windows.Forms.MessageBox.Show ("Added layer: " + layer.Name + "\nDescription: " + layer.Description, "Message Box"); } else { System.Windows.Forms.MessageBox.Show("Error: Layer " + LayerName + " Exists", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Exception"); } } [CommandMethod("GetDistance")] public static void GetDistance() { try { AcadApplication application = DRXNET.OdAp.Application.AcadApplication as AcadApplication; if (application == null) throw new System.Exception("Could Not Get Application"); AcadDocument document = application.ActiveDocument; double[] pt1 = (double[])document.Utility.GetPoint(null, "GetPoint"); double dist = document.Utility.GetDistance(pt1, "Get Next Point"); System.Windows.Forms.MessageBox.Show(dist.ToString()); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } [CommandMethod("addlayout")] public static void addlayout() { try { AcadApplication application = DRXNET.OdAp.Application.AcadApplication as AcadApplication; if (application == null) throw new System.Exception("Could Not Get Application"); AcadDocument document = application.ActiveDocument; AcadLayout myLayout = document.Layouts.Add("MyLayout"); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } [CommandMethod("MyPolyline")] public static void MyPolyline() { try { AcadApplication application = DRXNET.OdAp.Application.AcadApplication as AcadApplication; if (application == null) throw new System.Exception("Could Not Get Application"); AcadDocument Doc = application.ActiveDocument; AcadDatabase Db = Doc.Database; List ptcollection = new List() { new double[]{0,0}, new double[]{0,100}, new double[]{100,100}, new double[]{100,0}, new double[]{0,0} }; List vertexList = new List(10); ptcollection.ForEach(p => vertexList.AddRange(p)); AcadLWPolyline pline = Db.ModelSpace.AddLightWeightPolyline(vertexList.ToArray()); object omin; object omax; pline.GetBoundingBox(out omin, out omax); double[] min = (double[])omin; double[] max = (double[])omax; pline.Rotate(new double[] { (max[0] - min[0]), (max[1] - min[1]) }, 0.785398163); pline.Update(); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } [CommandMethod("MySel")] public static void MySel() { try { AcadApplication application = DRXNET.OdAp.Application.AcadApplication as AcadApplication; if (application == null) throw new System.Exception("Could Not Get Application"); AcadDocument Doc = application.ActiveDocument; AcadSelectionSet selection = Doc.SelectionSets.Add("MySel"); try { int[] var = new int[] { 0 }; object[] val = new object[] { "POINT,LINE,CIRCLE" }; selection.SelectOnScreen(var, val); List entlist = new List(); foreach (var e in selection) entlist.Add((AcadEntity)e); entlist.ForEach(e => Doc.Utility.Prompt (String.Format("\n({0},{1})", e.ObjectName, e.Layer))); } catch { System.Windows.Forms.MessageBox.Show("\nError Getting Selection set: "); } finally { selection.Delete(); } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } }}
0
Comments
-
daniel,
hi! i would like to where can i find DRXNET.OdRx. I am using Bricscad V12 professional.
Thanks.
0 -
Marlon; download the zip file from the above link and then reference the relevant DRXNET_2.0X_8.DLL in your project. The DRXNET.OdRx namespace will then be available for use.
Regards,
0 -
this probably won't work for V12, BTY Bricscad Pro+ now has more to offer built-in than said routine .NET wise, have a look at the samples that shipped with your installation : )
0
This discussion has been closed.