.NET

Reply
*Expert Elite*
mathewk
Posts: 2,757
Registered: ‎07-09-2003
Message 1 of 8 (1,395 Views)
Accepted Solution

Select Object Command Prompt

1395 Views, 7 Replies
06-04-2012 09:29 PM

I'm creating a VB.Net routine which will run the REVCLOUD command.  In my application I prompt the user to select a single polyline using:

 

EntRslt = acDoc.Editor.GetEntity(EntOpts)

 

Then later I run the REVCLOUD command using:

 

acDoc.SendStringToExecute("_revcloud Object Poly No ", False, False, True)

 

Where Poly is the polyline I selected earlier.  Of course, the line above doesn't work since "Poly" is interpreted as a string.  But I would like to figure out how to pass my VB.Net selected Polyline into the REVCLOUD command.

 

Anyone have any advice on how I might do this?  The REVCLOUD command will not accept the "Previous" selection set so setting the Implied Selectoin does not work.  If my Polyline was the Last object in the database I could use the "Last" option, but it isn't.

 

Thanks in advance.

 

Matt Kolberg
Cansel - Autodesk Division
http://www.cansel.ca/

You better use acedCmd P/Invoke function

Give this a try:

 

 <DllImport("acad.exe", BestFitMapping:=True, CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Auto)> _
Private Shared Function acedCmd(ByVal vlist_in As System.IntPtr) As Integer
End Function
<CommandMethod("Cloud")> _
Public Shared Sub TestCloud()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim doc As Document = acApp.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Using tr
Try
' Prompt for the polyline to revcloud
Dim peo As New PromptEntityOptions(vbLf & "Select first polyline:")
peo.SetRejectMessage(vbLf & "Select polyline only")
peo.AddAllowedClass(GetType(Polyline), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Dim fid As ObjectId = per.ObjectId
Dim obj1 As DBObject = tr.GetObject(fid, OpenMode.ForWrite)
acApp.SetSystemVariable("CMDECHO", 0)
Dim buf As New ResultBuffer()
buf.Add(New TypedValue(5005, "_REVCLOUD"))
buf.Add(New TypedValue(5005, "_O"))
buf.Add(New TypedValue(5006, fid))
buf.Add(New TypedValue(5005, "_N"))
acedCmd(buf.UnmanagedObject)
buf.Dispose()
acApp.SetSystemVariable("CMDECHO", 1)
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(ex.Message + vbLf + ex.StackTrace)
End Try
End Using
End Sub

 

~'J'~

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 8 (1,387 Views)

Re: Select Object Command Prompt

06-05-2012 01:58 AM in reply to: mathewk

You better use acedCmd P/Invoke function

Give this a try:

 

       <DllImport("acad.exe", BestFitMapping:=True, CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Auto)> _
        Private Shared Function acedCmd(ByVal vlist_in As System.IntPtr) As Integer
        End Function
        <CommandMethod("Cloud")> _
        Public Shared Sub TestCloud()
            Dim db As Database = HostApplicationServices.WorkingDatabase

            Dim doc As Document = acApp.DocumentManager.MdiActiveDocument

            Dim ed As Editor = doc.Editor

            Dim tr As Transaction = db.TransactionManager.StartTransaction()

            Using tr
                Try

                    ' Prompt for the polyline to revcloud

                    Dim peo As New PromptEntityOptions(vbLf & "Select first polyline:")

                    peo.SetRejectMessage(vbLf & "Select polyline only")

                    peo.AddAllowedClass(GetType(Polyline), True)

                    Dim per As PromptEntityResult = ed.GetEntity(peo)

                    If per.Status <> PromptStatus.OK Then

                        Return
                    End If

                    Dim fid As ObjectId = per.ObjectId

                    Dim obj1 As DBObject = tr.GetObject(fid, OpenMode.ForWrite)

                    acApp.SetSystemVariable("CMDECHO", 0)

                    Dim buf As New ResultBuffer()

                    buf.Add(New TypedValue(5005, "_REVCLOUD"))

                    buf.Add(New TypedValue(5005, "_O"))

                    buf.Add(New TypedValue(5006, fid))

                    buf.Add(New TypedValue(5005, "_N"))

                    acedCmd(buf.UnmanagedObject)

                    buf.Dispose()

                    acApp.SetSystemVariable("CMDECHO", 1)

                    tr.Commit()

                Catch ex As Autodesk.AutoCAD.Runtime.Exception

                    ed.WriteMessage(ex.Message + vbLf + ex.StackTrace)

                End Try

            End Using

        End Sub

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 8 (1,354 Views)

Re: Select Object Command Prompt

06-05-2012 11:06 AM in reply to: mathewk

I discovered one more method you may want to use,

check this as well, just change the arc sizes in the command string:

        <CommandMethod("Revc", CommandFlags.Modal Or CommandFlags.Session)> _
        Public Shared Sub RevCloudTest()
            Dim doc As Document = acApp.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            acApp.SetSystemVariable("osmode", 512)
            Dim pt As Point3d = ed.GetPoint(vbLf + "Pick a point on polyline: ").Value
            doc.SendStringToExecute("_REVCLOUD _A 0.1 0.3 _O " + pt.X.ToString + "," + pt.Y.ToString + ",0 _N ", True, False, False)
        End Sub

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
mathewk
Posts: 2,757
Registered: ‎07-09-2003
Message 4 of 8 (1,352 Views)

Re: Select Object Command Prompt

06-05-2012 11:20 AM in reply to: Hallex

Thank you very much for your reply.  I was able to get your first suggection to line:

 

I assume it has something to do with the TypedValue TypeCode 5006.  I assume 5005 is a string and 5006 is an ObjectID?  What would the code be for a double?  Is there a list of these codes somewhere?  I have looked and I've not found anythng useful.

buf.Add(New TypedValue(5005, "_OFFSET"))
buf.Add(New TypedValue(5006, OffsetLength))
buf.Add(New TypedValue(5006, Pline.ObjectId))

 Thanks again.

Matt Kolberg
Cansel - Autodesk Division
http://www.cansel.ca/
*Expert Elite*
mathewk
Posts: 2,757
Registered: ‎07-09-2003
Message 5 of 8 (1,350 Views)

Re: Select Object Command Prompt

06-05-2012 11:33 AM in reply to: mathewk

Ok, the offset length is easy, I just use the ToString option.

 

But of course, in the Offset command I will need to specify a point as well.  5006 does not work; I'm not sure which integer value to use here.

 

Matt Kolberg
Cansel - Autodesk Division
http://www.cansel.ca/
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 8 (1,345 Views)

Re: Select Object Command Prompt

06-05-2012 12:17 PM in reply to: mathewk

Here is some constants for ResultBuffer values:

		' Type of resbuf element
		' credit to Alexander Rivilis 
		Const RTNONE As Short = 5000
		' No result 
		Const RTREAL As Short = 5001
		' Real number 
		Const RTPOshort As Short = 5002
		' 2D poshort X and Y only 
		Const RTSHORT As Short = 5003
		' Short integer 
		Const RTANG As Short = 5004
		' Angle 
		Const RTSTR As Short = 5005
		' String 
		Const RTENAME As Short = 5006
		' Entity name 
		Const RTPICKS As Short = 5007
		' Pick set 
		Const RTORshort As Short = 5008
		' Orientation 
		Const RT3DPOshort As Short = 5009
		' 3D poshort - X, Y, and Z 
		Const RTLONG As Short = 5010
		' Long integer 
		Const RTVOID As Short = 5014
		' Blank symbol 
		Const RTLB As Short = 5016
		' list begin 
		Const RTLE As Short = 5017
		' list end 
		Const RTDOTE As Short = 5018
		' dotted pair 
		Const RTNIL As Short = 5019
		' nil 
		Const RTDXF0 As Short = 5020
		' DXF code 0 for ads_buildlist only 
		Const RTT As Short = 5021
		' T atom 
		Const RTRESBUF As Short = 5023
		' resbuf 
		Const RTMODELESS As Short = 5027
		' interrupted by modeless dialog 
		'
		' Error return code
		Const RTNORM As Short = 5100
		' Request succeeded 
		Const RTERROR As Short = -5001
		' Some other error 
		Const RTCAN As Short = -5002
		' User cancelled request -- Ctl-C 
		Const RTREJ As Short = -5003
		' AutoCAD rejected request -- invalid 
		Const RTFAIL As Short = -5004
		' Link failure -- Lisp probably died 
		Const RTKWORD As Short = -5005
		' Keyword returned from getxxx() routine 
		Const RTINPUTTRUNCATED As Short = -5008

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
mathewk
Posts: 2,757
Registered: ‎07-09-2003
Message 7 of 8 (1,338 Views)

Re: Select Object Command Prompt

06-05-2012 01:29 PM in reply to: Hallex

Thank you very much HALLEX, I was able to use your code to fix mine.  It all seems to work now.

Matt Kolberg
Cansel - Autodesk Division
http://www.cansel.ca/
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 8 of 8 (1,326 Views)

Re: Select Object Command Prompt

06-05-2012 10:50 PM in reply to: mathewk

Glad I could help, Matt

Happy computing :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.