.NET 4.0 for Bricscad Pro

Just a FYI to anyone that has been using the .NET wrappers I wrote, you can find the latest version here. www.cadext.com/downloads/RxNetSetup.exe this is for use with .NET 4.0 / Visual studio 2010, the free express versions will work just fine.

 

PM me at daniel#cadext.com if you run into any issues.

Comments

  • I will post a sample project on my site in the next couple of days. Here are a few snippits to get you thinking  

     

     

    // system using statmentsusing   System;using   System.Collections.Generic;using   System.Linq;using   System.Text;// our using statments using   BricscadApp;using   BricscadDb;using   RxNet.ApplicationServices;using   RxNet.Runtime;using   RxNet.RxGlobal;using   RxNet.Geometry;using   RxNet.DatabaseServices; namespace   RxNetSample{  //command classes should be static  public static class Commands{  // command methods should be static and have a  // command method attribute [ CommandMethod("test01")]  public static void test01(){  // get the instance of Bricscad and the active document.  var app = Application.AcadApplication as AcadApplication;  var doc = app.ActiveDocument;  try{  // add a line  var pnt1 = new double[] { 0.0, 0.0, 0.0 };  var pnt2 = new double[] { 10.0, 10.0, 0.0 };  var line = doc.ModelSpace.AddLine(pnt1, pnt2);}  catch (System.Exception ex){doc.Utility.Prompt( String.Format("\n{0}", ex.Message));}}   // delete all lines in modelspace that are  // less than 0.001 in length[ CommandMethod("test02")]  public static void test02(){  var app = Application.AcadApplication as AcadApplication;  foreach (var e in app.ActiveDocument.ModelSpace.OfType< AcadLine>().Where(line => line.Length < 0.001))e.Delete();}  // a linq sample[ CommandMethod("test03")]  public static void test03(){  var app = Application.AcadApplication as AcadApplication;  var layers =  from layer in app.ActiveDocument.Layers.Cast<AcadLayer>()  where layer.Name != "0"   select layer;  foreach(var layer in layers)layer.LayerOn =  false;}}}
  •  


    // system using statments
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    // our using statments 
    using BricscadApp;
    using BricscadDb;
    using RxNet.ApplicationServices;
    using RxNet.Runtime;
    using RxNet.RxGlobal;
    using RxNet.Geometry;
    using RxNet.DatabaseServices;

    namespace RxNetSample
    {
      //command classes should be static
      public static class Commands
      {
        // command methods should be static and have a
        // command method attribute
        [CommandMethod("test01")]
        public static void test01()
        {
          // get the instance of Bricscad and the active document.
          var app = Application.AcadApplication as AcadApplication;
          var doc = app.ActiveDocument;
          try
          {
            // add a line
            var pnt1 = new double[] { 0.0, 0.0, 0.0 };
            var pnt2 = new double[] { 10.0, 10.0, 0.0 };
            var line = doc.ModelSpace.AddLine(pnt1, pnt2);
          }
          catch (System.Exception ex)
          {
            doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
          }
        }

        // delete all lines in modelspace that are
        // less than 0.001 in length
        [CommandMethod("test02")]
        public static void test02()
        {
          var app = Application.AcadApplication as AcadApplication;
          foreach (var e in app.ActiveDocument.ModelSpace.
            OfType<AcadLine>().Where(line => line.Length < 0.001))
           e.Delete();
        }
        // a linq sample
        [CommandMethod("test03")]
        public static void test03()
        {
          var app = Application.AcadApplication as AcadApplication;
          var layers =
            from layer in app.ActiveDocument.Layers.Cast<AcadLayer>()
            where layer.Name != "0"
            select layer;
          foreach(var layer in layers)
             layer.LayerOn = false;
        }
      }
    }
    PASTE CODE HERE

     

  • Here is an example of how to take use of multiple threads in your .NET 4 module. First let me say that Bricscad is not multi-thread safe, neither is Acad or any other cad for that matter, so you should not try to do any API calls from spawned threads, however you can, spawn threads for doing IO, database queries, or build multi-threaded data crunchers, the path is collect the data you need from the dwg -> multi-threaded crunch -> synchronize -> return the data. In this example I iterate though modelspace collecting point coordinates and do a little crunching

     

    //Parallel
        [CommandMethod("test04")]
        public static void test04()
        {
          var app = Application.AcadApplication as AcadApplication;
          var doc = app.ActiveDocument;
          var mspace = doc.ModelSpace;
          var locs = new SynchronizedCollection<Point3d>();
          var points = new List<AcadPoint>();
          foreach(AcadEntity ent in mspace)
          {
            AcadPoint point = ent as AcadPoint;
            if (point != null)
              points.Add(point);
          }
          points.ForEach(X => locs.Add(new Point3d((double[])X.Coordinates)));
          Stopwatch stwp = new Stopwatch();
          stwp.Start();
          Point3d org = Point3d.kOrigin;
          Parallel.For(0, locs.Count, i =>
          {
            Point3d tmp = locs[i];
            Matrix3d mat = Matrix3d.Displacement(tmp.GetAsVector());
            tmp = tmp.TransformBy(mat.Inverse());
            tmp = tmp.ScaleBy(1.3,org);
            locs[i] = tmp;
          });
          stwp.Stop();
          for (int i = 0; i < points.Count; i++)
            points[i].Coordinates = (double[])locs[i];
          TimeSpan ts = stwp.Elapsed;
          doc.Utility.Prompt(Convert.ToString(ts.TotalMilliseconds));
        }
        //single
        [CommandMethod("test05")]
        public static void test05()
        {
          var app = Application.AcadApplication as AcadApplication;
          var doc = app.ActiveDocument;
          var mspace = doc.ModelSpace;
          var locs = new List<Point3d>();
          var points = new List<AcadPoint>();
          foreach (AcadEntity ent in mspace)
          {
            AcadPoint point = ent as AcadPoint;
            if (point != null)
              points.Add(point);
          }
          points.ForEach(X => locs.Add(new Point3d((double[])X.Coordinates)));
          Stopwatch stwp = new Stopwatch();
          stwp.Start();
          Point3d org = Point3d.kOrigin;
          for (int i = 0; i < locs.Count; i++)
          {
            Point3d tmp = locs[i];
            Matrix3d mat = Matrix3d.Displacement(tmp.GetAsVector());
            tmp = tmp.TransformBy(mat.Inverse());
            tmp = tmp.ScaleBy(1.3, org);
            locs[i] = tmp;
          }
          stwp.Stop();
          for (int i = 0; i < points.Count; i++)
            points[i].Coordinates = (double[])locs[i];
          TimeSpan ts = stwp.Elapsed;
          doc.Utility.Prompt(Convert.ToString(ts.TotalMilliseconds));
        }

     

    TEST04 multi-thread
    13.9042 - Milliseconds - 50,000 points

    TEST05 single-thread
    29.2167 - Milliseconds - 50,000 points

    TEST04 multi-thread
    145.3845 - Milliseconds - 500,000 points

    TEST05 single-thread
    282.3018 - Milliseconds - 500,000 points

  • And a sample for you lispers : )
    (pfunc1) 64645.1593 Milliseconds
    (pfunc2) 12415.1541 Milliseconds 

       [LispFunction("pfunc1")]
        public static string pfunc1(ResultBuffer args)
        {
          Stopwatch stwp = new Stopwatch();
          stwp.Start();
          Int64 num_steps = 100000000;
          decimal sum = 0.0M;
          decimal step = 1.0M / (decimal)num_steps;
          for (Int64 i = 0; i < num_steps; i++)
          {
            decimal x = (i + 0.5M) * step;
            sum = sum + 4.0M / (1.0M + x * x);
          }
          stwp.Stop();
          TimeSpan ts = stwp.Elapsed;
          return Convert.ToString(ts.TotalMilliseconds);
        }

        [LispFunction("pfunc2")]
        public static string pfunc2(ResultBuffer args)
        {
          Stopwatch stwp = new Stopwatch();
          stwp.Start();
          Int64 num_steps = 100000000;
          decimal sum = 0.0M;
          decimal step = 1.0M / (decimal)num_steps;
          object monitor = new object();
          Parallel.ForEach(Partitioner.Create(0, num_steps), () => 0.0M,
                          (range, state, local) =>
          {
            for (Int64 i = range.Item1; i < range.Item2; i++)
            {
              decimal  x = (i + 0.5M) * step;
              local += 4.0M / (1.0M + x * x);
            }
            return local;
          }, local => { lock (monitor) sum += local; });
           stwp.Stop();
          TimeSpan ts = stwp.Elapsed;
          return Convert.ToString(ts.TotalMilliseconds);
        }
  • Hi Daniel, are any of your previous versions available for download still?  I have been trying at the swamp all day but the site seems to be down?

     

    Regards,

  • Dainiel,

    Dan M is currently travelling, so may not respond for a couple of days.

    The Swamp IS up now. http://www.theswamp.org/index.php?topic=29100.0 may be the thread you want.

     

    Regards, Kerry

  • Thanks Kerry, I appreciate it.  Unfortunately if the swamp was back online it is down again now so I will have to try again later!

    Regards,

     

    Daniel

  • Daniel,

    Did you get what you needed?

    Daniel

  • Yes, thanks Dan.  Even managed to get my first .NET program written in Delphi prism to work!  Such a pity we have to rely on COM at the moment as I'd love to get my hands dirty on some lower level stuff.  I just can't afford the time to learn another language.  Your c# examples have been a huge help getting this far though.

    Regards,

    Daniel

  • Daniel, I get the following after Bricscad startup:

    Loading .NET 4.0
    :Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

       at CRxNetApp.internalNetload(CRxNetApp* , CStringT<wchar_t\,StrTraitMFC_DLL<wchar_t\,ATL::ChTraitsCRT<wchar_t> > >* path)

    Haven't netloaded anything written in 2010 yet, but thought you should know.  I have C#, C++ and VB.NET Express editions installed, up-to-date running in XP

    Bricscad V10.4 Beta.  When installing the Expresses Editions it said it installed Net version 4, and I have compiled a couple sample exe's from the ide that ran, so I

    guess they are there.

     

    Many thanks for all the tools and samples you provide.

  • Hi Jerry,

    Please do the following steps:
    1, Uninstall the RxNet
    2, Delete all references to RxNet in Bricscad->tools->settings->Program options->support search file path.
    3,  install RxNet from the link above

    Let me know if this takes care of the problem

    Daniel

  • Same message.  The unistall was done through Control Panel. Paths cleared.  Opps, maybe I should reboot?

  • That wasn't it either.  The way it is after reinstall the path has 2 references to RxNet which seems correct.

    Maybe I need to does some registry cleaning before the reinstall?

    Can you tell me where to hunt.  Probally wont get to it til later.  Thanks for your help.

  • hmm, run this and tell me what it says (findfile "rxnet.dll")

  • command: (findfile "rxnet.dll")
    "C:\\Program Files\\Bricsys\\Bricscad V10\\support\\rxnet.dll"

  • Ah ha!, trash that one and the other DLLs that came with it

  • SUCCESS!!

    Thanks mucho.

  • Fantastic!

    I'll make a few modifications so this problem won't happen again. Just holler if you need anything else!

     

    Dan

  • I am looking at doing some intersection routines in C# express using RxNet and am curious as to the syntax of Vector3D.DotProduct & Vector3D.CrossProduct.  I have usually seen them in the form which requires two vector args.  Is your form MyVec1.CrossProduct(MyVec2)?  Just want to feel a little comfortable before I begin converting some old fortran. 

    And another matter, are there equivilent functions for (pointclosestocurve), (curvefirstderiv...) any way can't get there syntax at the moment but I think you know the group of lisp functions to which I'm referring.

    Thanks for helping me stumble along in net.

    Jerry

     

  • Right, your probably used to static functions that would require two vectors as arguments. With the .NET wrappers, you can always look at the DRX/BRX documentation for direction

     

    OdGeVector3d OdGeVector3d::crossProduct (const OdGeVector3d& vect) const

    // Returns the cross product of this vector and the specified vector.

     

     My plan was to wrap all the Geo goodies first, until I found that this is already done by the ODA. At this point they will probably be implemented by Bricsys before I would be able to write them.

    a sample

    [ CommandMethod("test07")]  public static void test07(){  try{  Vector3d x = Vector3d.XAxis;  Vector3d y = Vector3d.XYxis;  // Returns the cross product of this vector and the specified vector.  Vector3d z = x.CrossProduct(y);RxNet.RxGlobal. GlobalFunctions.Printf("\n{0}-{1}-{2}",x,y,z);}  catch (System.Exception ex){RxNet.RxGlobal. GlobalFunctions.Printf("\n{0}\n{1}",ex.Message,ex.StackTrace);}}

     

    returns (1,0,0)-(0,1,0)-(0,0,1)

  •   [CommandMethod("test07")]
        public static void test07()
        {
          try
          {
            Vector3d x = Vector3d.XAxis;
            Vector3d y = Vector3d.XYxis;
            // Returns the cross product of this vector and the specified vector.
            Vector3d z = x.CrossProduct(y);
            RxNet.RxGlobal.GlobalFunctions.Printf("\n{0}-{1}-{2}",x,y,z);
          }
          catch (System.Exception ex)
          {
            RxNet.RxGlobal.GlobalFunctions.Printf("\n{0}\n{1}",ex.Message,ex.StackTrace);
          }
        }
  • Hi there,

     

    we have quite some internal routines for autocad using .NET/netload command.

    will they run under bricscad?

    (some of them make use os the dznamic block option - ACAD2008 - do you have plans to implement the editing of dynamic blocks as well?)

     

    Thanks,

    hristo

  • Hello,

    Is any .NET manual or tutorial available for Bricscad?

    Regards, Vaidas
  • Hello Vaidas,

    I'm having a pretty good time with the examples that ship with Bricscad : Bricscad V12\API\dotNet\CsBrxMgd (4.0 if you like) or have a look at TheSwamp (http://www.theswamp.org/index.php?topic=32381.0)
    Loads of active people and useful links over there.

    Arno 
  • Thank you Arno,

    I'll pass your comment to the developer who is testing Bricscad and asks for more information.

    Regards, Vaidas
This discussion has been closed.