Author Topic: Bricscad && .NET  (Read 91848 times)

0 Members and 2 Guests are viewing this topic.

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Bricscad && .NET
« Reply #75 on: May 24, 2010, 08:44:52 AM »
Thanks Dan, works like a charm.  I can see I have lots of hours ahead squiggling with grdraw.  But first for some sleep.

Jerry J

  • Newt
  • Posts: 48
Re: Bricscad && .NET
« Reply #76 on: July 18, 2010, 07:31:05 AM »
Daniel,

Well I finally got around to playing with grread in C#.  I needed to use the grclear() function to delete the tracking lines, which I P/invoked per some of your samples and it worked fine... well not really.  It doesn't exactly work like lisp code.

Here is the code from your sample that I was just playing with..

Code: [Select]
        [CommandMethod("doit")]
        public static void test03()
        {
            var app = Application.AcadApplication as AcadApplication;
            var doc = app.ActiveDocument;
            double[] pt1 = new double[] { 0.0, 0.0, 0.0 };
            double[] pt2 = new double[] { 0.0, 0.0, 0.0 };

            try
                {
                bool doloop = true;
                Point3d last = Point3d.kOrigin;
                while (doloop)
                    {
                    GrReadResult res = GlobalFunctions.GrRead(1);
                    if (res.AnswerType == 5)
                        {
                        Point3d next = (Point3d)res.Buffer.Value;
                        GlobalFunctions.GrDraw(last, next, 6, 0);
                        }
                    if (res.AnswerType == 3)
                        {
                        PInvokeMethods.sds_grclear();
                        Point3d next = (Point3d)res.Buffer.Value;
                        pt1[0] = last.X; pt1[1] = last.Y; pt1[2] = last.Z;
                        pt2[0] = next.X; pt2[1] = next.Y; pt2[2] = next.Z;
                        doc.ModelSpace.AddLine(pt1, pt2);
                        last = next;
                        }
                        //doc.Utility.Prompt(String.Format("\n{0},{1}", res.AnswerType , res.Buffer));
                     if (res.Status == PromptStatus.Cancel)
                            doloop = false;

                     PInvokeMethods.sds_grclear();
                     }                   
                }               
            catch (System.Exception ex)
                {
                doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
                }
        }

and this is the method invoking call

[DllImport("Bricscad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
  static internal extern int sds_grclear();

This works except none of the lines (cad segments) are visible during the grread loop.  The temp line is created and erased as expected from similar lisp codings, but the drawing is not visible.  Not sure how to overcome this situation. Wonder if you have any thoughts on the matter.

On another issue, how do you use 3dPoint.toArray  ie, pt1 = last.toArray says NG need a delegate or something?

Anyway having fun playing in net and appreciate your schooling.

Jerry

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #77 on: July 18, 2010, 07:58:58 PM »
The problem is that grclear clears the whole graphics screen, if you try your routine on a drawing that's already has stuff in it, everything gets cleared.

Personally, I would take a different approach, example  (shows how to use the Point3d.ToArray() as well)
 

Code: [Select]
[CommandMethod("doit")]
    public static void test04()
    {
      var app = Application.AcadApplication as AcadApplication;
      var doc = app.ActiveDocument;
      try
      {
        bool doloop = true;
        Point3d last = Point3d.kOrigin;
        Point3d next = Point3d.kOrigin;
        int res = GlobalFunctions.GetPoint("\nGet Point: ", out next);
        if (res == 5100)
        {
          last = next;
          while (doloop)
          {
            res = GlobalFunctions.GetPoint(last, "\nGet Next Point: ", out next);

            if (res == 5100)
            {
              doc.ModelSpace.AddLine(last.ToArray(), next.ToArray());
              last = next;
            }
            else
            {
              doloop = false;
            }
          }
        }
      }
      catch (System.Exception ex)
      {
        doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
      }
    }
« Last Edit: July 18, 2010, 08:14:03 PM by eAmbiguousOutput »

Jerry J

  • Newt
  • Posts: 48
Re: Bricscad && .NET
« Reply #78 on: July 18, 2010, 09:58:57 PM »
Actually, what I am trying to do is replicate something I pieced together in lisp.  As follows

Code: [Select]
(defun C:GradeLine()
(setvar "LASTPOINT" (getpoint "\nLocate beginning grade point: "))
(setq omod (getvar "OSMODE"))
(setvar "OSMODE" 0)
(grgrade)
(setvar "OSMODE" omod)
)

(defun grgrade()
(setq pt (getvar "LASTPOINT"))
(setq grd "0.00")
(setq txtht (* (getvar "VIEWSIZE") 0.013))

(setq ent
(entmakex (list '(0 . "MTEXT")
                                '(100 . "AcDbEntity")
                                '(100 . "AcDbMText")
                                '(8 . "0")
                                '(62 . 250)
                                '(90 . 2)
                                '(63 . 7)
'(441 . 0)
                                '(45 . 1.15)
'(1 . "0.0")
)
)
)
(setq x (entget (entlast)))
(setq objtxt (vlax-ename->vla-object ent))
(while (eq (car (setq input (grread t 4 4))) 5)
(setq snappoint (osnap (cadr input) "_near"))
(redraw)
(if snappoint
(progn
(grdraw pt snappoint -1 0)
(setq grd (* (/ (- (caddr snappoint) (caddr pt)) (distance snappoint pt)) 100.0))
(setq x (subst (cons 63 256) (assoc 63 x) x))
(setq x (subst (cons 90 1) (assoc 90 x) x))
(entmod x)
(setq grdtxt (rtos grd 2 1))
(vlax-put-property objtxt 'TextString grdtxt)
(vlax-put-property objtxt 'InsertionPoint snappoint)
(setq txtht (* (getvar "VIEWSIZE") 0.013))
(vlax-put-property objtxt 'Height txtht)
;(setvar "MODEMACRO" grdtxt)
)
(progn
(setq x (subst (cons 63 7) (assoc 63 x) x))
(setq x (subst (cons 90 2) (assoc 90 x) x))
(entmod x)
(setq grdtxt "*")
(vlax-put-property objtxt 'TextString grdtxt)
(vlax-put-property objtxt 'InsertionPoint (cadr input))
(setq txtht (* (getvar "VIEWSIZE") 0.013))
(vlax-put-property objtxt 'Height txtht)
)
)
)
(setq input nil)
 (entmake
 (list (cons 0 "TEXT") (cons 10 snappoint) (cons 40 3.0) (cons 1 (rtos grd 2 2)))
 )
(entmake
(list (cons 0 "LINE") (cons 10 pt) (cons 11 snappoint))
)
(entdel ent)
;(setvar "MODEMACRO" "")
(setq ret (MsgBox "Continue Grades?" "Grading" 33 10))
(if (= ret 1)
(progn
(setvar "LASTPOINT" snappoint)
(gc)
(grgrade)
)
)
)

but now that I look at it, I was using (redraw) not (grclear).  In com I only see regen or am I missing it somewhere.
Anyway thanks for the look.

I should mention that this routine is for displaying grades between contours on the fly so as to allow preliminary layout of structures in steep terrain.
« Last Edit: July 18, 2010, 10:30:00 PM by Jerry J »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #79 on: July 18, 2010, 10:37:06 PM »
try this

Code: [Select]
namespace ExEcModule
{
  public static class Commands
  {
    [DllImport("Bricscad.exe", CallingConvention = CallingConvention.Cdecl)]
    static internal extern int sds_redraw(IntPtr ptr, int mode);

    [CommandMethod("doito")]
    public static void test03()
    {
      var app = Application.AcadApplication as AcadApplication;
      var doc = app.ActiveDocument;
      try
      {
        bool doloop = true;
        Point3d last = Point3d.kOrigin;
        while (doloop)
        {
          GrReadResult res = GlobalFunctions.GrRead(1);
         
          switch (res.AnswerType)
          {
            case 5:
              {
                sds_redraw(IntPtr.Zero,1);
                Point3d next = (Point3d)res.Buffer.Value;
                GlobalFunctions.GrDraw(last, next, 6, 0);
              }
              break;
            case 3:
              {
                Point3d next = (Point3d)res.Buffer.Value;
                doc.ModelSpace.AddLine(last.ToArray(), next.ToArray());
                last = next;
              }
              break;
            default:
              break;
          }

          if (res.Status == PromptStatus.Cancel)
            doloop = false;

          sds_redraw(IntPtr.Zero, 1);
        }

      }
      catch (System.Exception ex)
      {
        doc.Utility.Prompt(String.Format("\n{0}", ex.Message));
      }
    }
  }
}

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #80 on: July 18, 2010, 10:45:31 PM »
I wanted to give you an example using draggen, but I didn't wrap it.  :-o
I will get in there and add some of these items this week.

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Bricscad && .NET
« Reply #81 on: July 22, 2010, 07:55:34 AM »
Dan, with reference to this post http://www.theswamp.org/index.php?topic=33910.msg392471#msg392471 . Can you suggest how I go about debugging? I have no idea what could be conflicting with my program as the method names I've used are quite obscure and so I don't believe this is the issue.  However, all routines that I run come up with the same error.  I have also uninstalled all addons except your doctabs and rxnet itself.  The confounding thing is the code used to run!  Any help would be appreciated.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #82 on: July 22, 2010, 08:25:57 AM »
I'm a little confused, by routine do you mean lisp routines or .net routines?
do you have a file in your Program files\RxNet\VX called RxLoader.txt?
is so is it loading anything?
Are you running the .NET4 version or .NET2 version?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #83 on: July 22, 2010, 09:23:38 AM »
I have uploaded new builds that should a give a tad more info if an exception is thrown.

A tip, put a try catch at "every" command function, if you don't your code will be harder to debug example


Code: [Select]
   //gets the name of everything that loaded for .NET
    [CommandMethod("GetNetItems")]
    public static void GetNetItems(int i)
    {
      try
      {
        foreach (string assem in RxNet.ApplicationServices.ApplicationData.loadedAssemblies)
        {
          RxNet.RxGlobal.GlobalFunctions.Printf("\nAssembly name {0}", assem);
        }

        foreach (KeyValuePair<string,object> cmd in RxNet.ApplicationServices.ApplicationData.loadedCmdMethods)
        {
          RxNet.RxGlobal.GlobalFunctions.Printf("\ncommand name {0}", cmd.Key);
        }

        foreach (KeyValuePair<string, short> cmd in RxNet.ApplicationServices.ApplicationData.loadedLispMethods)
        {
          RxNet.RxGlobal.GlobalFunctions.Printf("\nLisp name {0}", cmd.Key);
        }
       
      }
      catch (System.Exception ex)
      {
        RxNet.RxGlobal.GlobalFunctions.Printf("\n{0}\n{1}",ex.Message,ex.StackTrace);
      }
    }

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #84 on: July 22, 2010, 10:15:57 AM »
See if you can follow this, look at the section for debugging and make the appropriate changes I.e path to Bricscad.exe
this will allow you to setp though the code
« Last Edit: July 22, 2010, 10:19:35 AM by eAmbiguousOutput »

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Bricscad && .NET
« Reply #85 on: July 22, 2010, 06:35:40 PM »
First of all thanks for the advice Daniel.  Turned out to be a newbie mistake which I will elaborate on a bit later when I have more time.  Seems I have become accustomed to my own infalibility  :lol: Adding The try.. catch statements found the error quick smart --> really don't know why I didn't go there first without prompting doh!@##$

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #86 on: July 23, 2010, 01:19:23 AM »
Awesome, glad you found the problem  :-)

Helios

  • Guest
Re: Bricscad && .NET
« Reply #87 on: September 08, 2010, 10:59:00 AM »
Daniel,

finally got the time to port a few of our existing routines to C# and use your RxNet wrapper to get the communications going.
I love the speed!  :lol:
Tasks that used to take several minutes complete in seconds...
I wonder why so few have downloaded and tried this stuff so far.

One question:
I have put a reference to my DLL in RxLoader.Txt and actually expected V9 to load it automatically.
For some reason that does not hapen?

Cheers,
Arno

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #88 on: September 09, 2010, 06:30:13 AM »
Hi Arno!

Whew! it's been a while since I've touched the V9 version, let me fire a copy up and see what's going on  :-)

Daniel



It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8755
  • AKA Daniel
Re: Bricscad && .NET
« Reply #89 on: September 10, 2010, 12:28:56 AM »

Hi Arno
 
So we have the case where its working on my machine, but not yours  :laugh:

Where are you putting the RxLoader.Txt file?  It needs to be in the same folder as RxNet.dll. 
If this isn't the issue, do a do a search on your computer for RxNet.dll.
The loader searches for this via find file,  and will load the first one it finds, so it could be loading the incorrect one.

If this isn't the issue, let me know and I'll dig deeper.