Author Topic: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace  (Read 13053 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #15 on: May 08, 2008, 08:36:59 PM »
resbuf **_buffer perhaps???

Nice work as always Daniel.

<edit> or even IntPtr ptr(*_buffer);??

Tried them, even tried &*_buffer, but it would throw an exception.  Probably why it’s undocumented  :mrgreen:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #16 on: May 08, 2008, 08:40:29 PM »
thanks a million Daniel... and to think that i was going to try and do that :-)
...
every now and then i get the following error:

You’re Welcome.
I got that exception too,  I’ll goof around with it a little more and see if I can’t find out why    :-o

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #17 on: May 08, 2008, 09:59:09 PM »
give this a try

Code: [Select]
   bool Utilities::NEntSelPEx
    (
    String^ prompt,
    [Out]ObjectId %objectid,
    Point3d %point,
    int pickflag,
    [Out]Matrix3d %matrix,
    [Out]ResultBuffer ^%buffer,
    unsigned int transSpaceFlag,
    int %gsmarker
    )
  {
    CString _prompt(prompt);
    ads_name _name;
    ads_point _point = {point.X,point.Y,point.Z};
    ads_matrix _matrix;
    resbuf *_buffer = NULL;
    int _gsmarker = gsmarker;

    if(acedNEntSelPEx(_prompt,_name,_point,pickflag,_matrix,&_buffer,transSpaceFlag,&_gsmarker) == RTNORM)
    {

      objectid = ObjectId(_name[0]);
      point = Point3d(_point[0],_point[1],_point[2]);

      array<double> ^_tmparray = gcnew array<double>(16)
      {
        _matrix[0][0],_matrix[0][1],_matrix[0][2],_matrix[0][3],
        _matrix[1][0],_matrix[1][1],_matrix[1][2],_matrix[1][3],
        _matrix[2][0],_matrix[2][1],_matrix[2][2],_matrix[2][3],
        _matrix[3][0],_matrix[3][1],_matrix[3][2],_matrix[3][3]
      };

      matrix = Matrix3d(_tmparray);

      if(_buffer != NULL)
      {
        IntPtr ptr(_buffer);
        buffer = (ResultBuffer^)DisposableWrapper::Create(ResultBuffer::typeid, ptr, true);
      }
      gsmarker = _gsmarker;
      return true;
    }
    else
    {
      return false;
    }
  }

Code: [Select]
   [CommandMethod("doit")]
    public void doit()
    {
      Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;

      string prompt = "select object";
      ObjectId id;
      Point3d point;
      int pickflag = 0;
      Matrix3d matrix;
      ResultBuffer buff;
      uint transSpaceFlag = Convert.ToUInt32(AcAp.Application.GetSystemVariable("CVPORT"));
      int marker = -1;

      try
      {
        if (AcMgdWrprs.Utilities.NEntSelPEx(prompt,
                                         out id,
                                         ref point,
                                         pickflag,
                                         out matrix,
                                         out buff,
                                         transSpaceFlag,
                                         ref marker) == true)
        {
          //
          ed.WriteMessage("\nObjectId: " + id.ToString());
          ed.WriteMessage("\nPoint3d:  " + point.ToString());
          ed.WriteMessage("\nMatrix3d: " + matrix.ToString());
          ed.WriteMessage("\nmarker:   " + marker.ToString());

          if (buff != null)
          {
            ed.WriteMessage("\nBuffer:   " + marker.ToString());
            foreach (TypedValue e in buff)
            {
              ed.WriteMessage(e.ToString());
            }
          }
        }
      }
      catch(System.Exception ex)
      {
        ed.WriteMessage(ex.Message);
        ed.WriteMessage(ex.StackTrace);
      }
    }


Chumplybum

  • Newt
  • Posts: 97
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #18 on: May 08, 2008, 11:53:22 PM »
tried it, and it works a treat

thanks heaps


Cheers

Mark

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #19 on: May 09, 2008, 12:00:45 AM »
tried it, and it works a treat

thanks heaps


Cheers

Mark

Great, Glad it works  :laugh:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #20 on: May 11, 2008, 09:17:14 AM »
FYI, Tony posted how to p/invoke acedNEntSelPEx here
http://discussion.autodesk.com/thread.jspa?messageID=5928092&#5928092

ahlzl

  • Guest
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #21 on: June 02, 2009, 08:02:17 AM »
FYI, Tony posted how to p/invoke acedNEntSelPEx here
http://discussion.autodesk.com/thread.jspa?messageID=5928092&#5928092


Daniel, I run the code, but fail.
are you OK?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #22 on: June 02, 2009, 08:10:05 AM »
I'm doing just dandy, I had a nice Ribeye of Yak and a baked patato for dinner.  :-)
What code are you having problems with, Mine or Tony's? What cad version are you using? Are you getting an error message?

ahlzl

  • Guest
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #23 on: June 02, 2009, 08:45:13 AM »
thanks,Daniel.

I run this code, fail! VS2008 + AutoCAD 2009
Code: [Select]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace Namespace1
{
    public static class NestedPickSample
    {
        [CommandMethod("NESTEDPICKTEST")]
        public static void acedNEntSelPExTest()
        {
            Int64 adsname = 0;
            Point3d picked;
            Matrix3d xform;
            IntPtr resbuf = IntPtr.Zero;
            int gsmarker = 0;
            int result = acedNEntSelPEx("Pick something:", out adsname,
            out picked, 0, out xform, out resbuf, 0, out gsmarker);

            if (result == 5100)
            {
                Prompt("Success: ");

                // Dump contents of resultbuffer:

                ResultBuffer buffer = (ResultBuffer)DisposableWrapper.Create(
                typeof(ResultBuffer), resbuf, true);
                int i = 0;
                foreach (TypedValue v in buffer)
                    Prompt("element[{0}]: ({1} {2})",
                    i++, v.TypeCode, v.Value.ToString());

                buffer.Dispose();
            }
            Console.Write(0);
        }

        private static void Prompt(string msg, params object[] args)
        {
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
            .MdiActiveDocument.Editor.WriteMessage(msg, args);
        }

        // This may get mangled by this crappy news server:
        [DllImport("acad.exe",
        EntryPoint = "?acedNEntSelPEx@@YAHPB_WQAJQANHQAY03NPAPAUresbuf@@IPAH@Z",
        CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]

        extern static int acedNEntSelPEx(string prompt,  
        out Int64 adsname,
        out Point3d picked,
        int pickflag,
        out Matrix3d transform,
        out IntPtr resbuf,
        uint transSpaceFlag,
        out int gsMarker);
    }
}

« Last Edit: June 02, 2009, 10:30:37 AM by ahlzl »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #24 on: June 02, 2009, 10:06:07 AM »
Just a guess, you might need to test to see if resbuf == IntPtr.Zero before creating ResultBuffer buffer

ahlzl

  • Guest
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #25 on: June 02, 2009, 10:26:50 AM »
Just a guess, you might need to test to see if resbuf == IntPtr.Zero before creating ResultBuffer buffer
success!
thanks Daniel again!

ahlzl

  • Guest
new question for acedNEntSelPEx
« Reply #26 on: June 02, 2009, 09:35:50 PM »
I run Daniel's code for acedNEntSelPEx, OK.
I run Tony's code for acedNEntSelPEx, OK.

but how to get objectid?

Daniel's code:
ed.WriteMessage("\nObjectId: " + id.ToString());  OK!


Tony's code:
int result = acedNEntSelPEx("\nPick something:", out adsname, out picked, 0, out xform, out resbuf, 0, out gsmarker);

adsname is Int64, is not Int64[], how get objectid from the adsname?  thanks!

« Last Edit: June 02, 2009, 09:40:13 PM by ahlzl »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #27 on: June 03, 2009, 01:38:42 AM »
Try this code, I did not have a chance to test it

Code: [Select]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace Namespace1
{
    public static class NestedPickSample
    {
        [CommandMethod("doit")]
        public static void acedNEntSelPExTest()
        {
            ObjectId id = new ObjectId();
            long[] adsname = {0,0};
            Point3d picked;
            Matrix3d xform;
            IntPtr resbuf = IntPtr.Zero;
            int gsmarker = 0;
            int result = acedNEntSelPEx("Pick something:",adsname,
            out picked, 0, out xform, out resbuf, 0, out gsmarker);

            if (result == 5100)
            {
                if (resbuf != IntPtr.Zero)
                {
                    ResultBuffer buffer = (ResultBuffer)DisposableWrapper.Create(
                    typeof(ResultBuffer), resbuf, true);
                    int i = 0;
                    foreach (TypedValue v in buffer)
                        Prompt("element[{0}]: ({1} {2})",
                        i++, v.TypeCode, v.Value.ToString());

                    buffer.Dispose();
                }
                acdbGetObjectId(ref id, adsname);
                Prompt("\nId{0}",id);
            }
        }

        private static void Prompt(string msg, params object[] args)
        {
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
            .MdiActiveDocument.Editor.WriteMessage(msg, args);
        }

        [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl)]
        private static extern int acdbGetObjectId(ref ObjectId objId, long[] name);   

        [DllImport("acad.exe",
        EntryPoint = "?acedNEntSelPEx@@YAHPB_WQAJQANHQAY03NPAPAUresbuf@@IPAH@Z",
        CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]

        extern static int acedNEntSelPEx(string prompt,
        long[] adsname,
        out Point3d picked,
        int pickflag,
        out Matrix3d transform,
        out IntPtr resbuf,
        uint transSpaceFlag,
        out int gsMarker);
    }
}


ahlzl

  • Guest
Re: P/Invoke acedNEntSelPEx, ie select modelspace entity from paperspace
« Reply #28 on: June 03, 2009, 02:31:24 AM »
thank you, great Daniel!

I bethink of acdbGetObjectId, but I hidebound to long[] adsname and out Int64 adsname. :x

thanks again!