.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to P/Invoke acedNEntSelPEx()

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
973 Views, 6 Replies

How to P/Invoke acedNEntSelPEx()

[code]

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);

}
}

[/code]

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm
6 REPLIES 6
Message 2 of 7
dmarcotte4
in reply to: Anonymous

Thanks Tony

I was fighting with this one here http://www.theswamp.org/index.php?topic=22963.msg275937#msg275937

Thanks for showing how it’s done 🙂
Message 3 of 7
Chumplybum
in reply to: Anonymous

hi tony, i finally got around to trying this out and i've come across a few problems...

1. if i select the object in modelspace, i get an exception when assigning the buffer, 'Operation is not valid due to the current state of the object' i'm assuming that the buffer is not necessary when picking the object directly and hence this could be handled using a try catch block???

2. based on question 1, again i'm assuming that the ads_name variable is the OldID of the selected object and that from this i need to use the HostApplicationServices.WorkingDatabase.GetObjectID function to get the objectID of the selected object. Which i've had a go at...

Dim SelectedObject As ObjectId = HostApplicationServices.WorkingDatabase.GetObjectId(False, New Handle(adsname), 0)

but this throws an exception 'eUnknownHandle'. do i need to use another pinvoke call (acdbGetObjectId) to get the ObjectID of the selected object???


any help would be great

cheers, Mark
Message 4 of 7
Anonymous
in reply to: Anonymous

If you don't select a nested object, the result buffer
is not assigned and you should not try to use it.

IOW, you must test it first:

if( resbuf != IntPtr.Zero )
{
ResultBuffer buffer = DisposableWrapper.Create(
typeof(ResultBuffer), resbuf, true) as ResultBuffer;
}

The ads_name variable is a native ads_name type
(e.g., long[2]), so to get the ObjectId you must P/Invoke
acdbGetObjectId(). Declare the parameter as Int64, and
the result as ObjectId.

[DllImport( "acdb17.dll", CallingConvention = CallingConvention.Cdecl )]
extern static public ErrorStatus acdbGetObjectId( out ObjectId id, Int64 ename );


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:5932672@discussion.autodesk.com...
hi tony, i finally got around to trying this out and i've come across a few problems...

1. if i select the object in modelspace, i get an exception when assigning the buffer, 'Operation is not valid due to the current state of the object' i'm assuming that the buffer is not necessary when picking the object directly and hence this could be handled using a try catch block???

2. based on question 1, again i'm assuming that the ads_name variable is the OldID of the selected object and that from this i need to use the HostApplicationServices.WorkingDatabase.GetObjectID function to get the objectID of the selected object. Which i've had a go at...

Dim SelectedObject As ObjectId = HostApplicationServices.WorkingDatabase.GetObjectId(False, New Handle(adsname), 0)

but this throws an exception 'eUnknownHandle'. do i need to use another pinvoke call (acdbGetObjectId) to get the ObjectID of the selected object???


any help would be great

cheers, Mark
Message 5 of 7
Chumplybum
in reply to: Anonymous

hi and thanks Tony,

after adding in the new pinvoke call i get an ErrorStatus of InvalidAdsName using the following code...

'code

Public class

[CommandMethod("Test")] _
Public Shared Sub acedNEntSelPExTest()

Dim adsname As Int64 = 0
Dim picked As Point3d
Dim xform As Matrix3d
Dim resbuf As IntPtr = IntPtr.Zero
Dim gsmarker As Integer = -1
Dim transflag As Integer = 1
Dim result As Integer = acedNEntSelPEx("Pick something:", adsname, picked, 0, xform, resbuf, _
transflag, gsmarker)

Dim SelectedObjectID As ObjectId = New ObjectId
Dim temp As Object = acdbGetObjectId(SelectedObjectID, adsname)

end sub

[DllImport("acad.exe", EntryPoint:="?acedNEntSelPEx@@YAHPB_WQAJQANHQAY03NPAPAUresbuf@@IPAH@Z", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)] _
Private Shared Function acedNEntSelPEx(ByVal prompt As String, ByRef adsname As Int64, ByRef picked As Point3d, ByVal pickflag As Integer, ByRef transform As Matrix3d, ByRef resbuf As IntPtr, ByVal transSpaceFlag As UInteger, ByRef gsMarker As Integer) As Integer
End Function

[Runtime.InteropServices.DllImport("acdb17.dll", CallingConvention:=Runtime.InteropServices.CallingConvention.Cdecl)] _
Public Shared Function acdbGetObjectId(ByRef id As Autodesk.AutoCAD.DatabaseServices.ObjectId, ByVal ename As Int64) As Autodesk.AutoCAD.Runtime.ErrorStatus
End Function

end Class

'end code

PS. i've replaced the vb attribute <> with [] so that the attributes will show...


any help would be great

Cheers, Mark
Message 6 of 7
Anonymous
in reply to: Anonymous

Try changing 'ByVal' to 'ByRef' on the second parameter
to acdbGetObjectId, and see if that helps.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:5932843@discussion.autodesk.com...
hi and thanks Tony,

after adding in the new pinvoke call i get an ErrorStatus of InvalidAdsName using the following code...

'code

Public class

[CommandMethod("Test")] _
Public Shared Sub acedNEntSelPExTest()

Dim adsname As Int64 = 0
Dim picked As Point3d
Dim xform As Matrix3d
Dim resbuf As IntPtr = IntPtr.Zero
Dim gsmarker As Integer = -1
Dim transflag As Integer = 1
Dim result As Integer = acedNEntSelPEx("Pick something:", adsname, picked, 0, xform, resbuf, _
transflag, gsmarker)

Dim SelectedObjectID As ObjectId = New ObjectId
Dim temp As Object = acdbGetObjectId(SelectedObjectID, adsname)

end sub

[DllImport("acad.exe", EntryPoint:="?acedNEntSelPEx@@YAHPB_WQAJQANHQAY03NPAPAUresbuf@@IPAH@Z", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)] _
Private Shared Function acedNEntSelPEx(ByVal prompt As String, ByRef adsname As Int64, ByRef picked As Point3d, ByVal pickflag As Integer, ByRef transform As Matrix3d, ByRef resbuf As IntPtr, ByVal transSpaceFlag As UInteger, ByRef gsMarker As Integer) As Integer
End Function

[Runtime.InteropServices.DllImport("acdb17.dll", CallingConvention:=Runtime.InteropServices.CallingConvention.Cdecl)] _
Public Shared Function acdbGetObjectId(ByRef id As Autodesk.AutoCAD.DatabaseServices.ObjectId, ByVal ename As Int64) As Autodesk.AutoCAD.Runtime.ErrorStatus
End Function

end Class

'end code

PS. i've replaced the vb attribute <> with [] so that the attributes will show...


any help would be great

Cheers, Mark
Message 7 of 7
Chumplybum
in reply to: Anonymous

thanks again Tony, that fixed it


Cheers

Mark

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost