<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to pass ObjectIdCollection into built-in Rotate command? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428905#M42035</link>
    <description>I was seeing that as a last step if ever I had to create the rotate command from scratch ... If I had to, then I'd need to see the entities as I rotate them and the DrawJig would be useful. However, I was looking more along the lines of using the existing rotate command that is built-in AutoCAD and pass my ObjectIdCollection as a parameter in the command.</description>
    <pubDate>Mon, 01 Dec 2014 15:34:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-12-01T15:34:04Z</dc:date>
    <item>
      <title>How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428701#M42033</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First time user here. I am trying to rotate a bunch of entities like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="rotate_Conveyro.png" title="rotate_Conveyro.png" src="https://forums.autodesk.com/t5/image/serverpage/image-id/143941iA4EF854D0B70A443/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This image represents a bunch of lines, blocks, circles etc being rotated using the built-in AutoCAD rotate command.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Knowing that I can access all of those object IDs and store them into an ObjectIDCollection, how do I go about passing that collection into the rotate command? Is this possible? Or do I need to build a rotate command from scratch? Perhaps there's an easier way of doing all this ...?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 12:18:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428701#M42033</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T12:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428870#M42034</link>
      <description>search for JIG: Google "c# autoCAD jig"&lt;BR /&gt;Entity Jig for one entity&lt;BR /&gt;Draw Jig for multiple entities&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Dec 2014 15:15:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428870#M42034</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2014-12-01T15:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428905#M42035</link>
      <description>I was seeing that as a last step if ever I had to create the rotate command from scratch ... If I had to, then I'd need to see the entities as I rotate them and the DrawJig would be useful. However, I was looking more along the lines of using the existing rotate command that is built-in AutoCAD and pass my ObjectIdCollection as a parameter in the command.</description>
      <pubDate>Mon, 01 Dec 2014 15:34:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428905#M42035</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T15:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428919#M42036</link>
      <description>Each Database Object (ID) also has a Handle.&lt;BR /&gt;Using Lisp you pass those handles to the command, like&lt;BR /&gt;(entget (handent """ &amp;amp; theID.Handle &amp;amp; """))&lt;BR /&gt;&lt;BR /&gt;But you might be limited by the max length of commandline input.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Dec 2014 15:41:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428919#M42036</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2014-12-01T15:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428923#M42037</link>
      <description>&lt;P&gt;You probably have more success using the PickFirst Selection Set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2007/01/adding_to_the_a.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2007/01/adding_to_the_a.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://spiderinnet1.typepad.com/blog/2012/09/autocad-net-pickfirst-set-impliedselection-editorselectwindow-pointcollector.html" target="_blank"&gt;http://spiderinnet1.typepad.com/blog/2012/09/autocad-net-pickfirst-set-impliedselection-editorselectwindow-pointcollector.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 15:47:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428923#M42037</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2014-12-01T15:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428941#M42038</link>
      <description>Yeah I saw those options when I was searching for a solution. My only issue was, I prompt the user to select his object (or one of the lines related to it) as a single click. I don't prompt the user to choose all his lines. Can I pass an ObjectIdCollection into a SelectionSet? That was where I was stuck using that method ... I tried to pass my object IDs into a SelectionSet but really could not figure it out!&lt;BR /&gt;&lt;BR /&gt;Any tips on how to acheive that?&lt;BR /&gt;&lt;BR /&gt;Thanks for the help by the way!</description>
      <pubDate>Mon, 01 Dec 2014 15:58:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428941#M42038</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T15:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428946#M42039</link>
      <description>I doubt you can add to a SelectionSet other than the PickFirst Set.&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Dec 2014 16:00:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5428946#M42039</guid>
      <dc:creator>SENL1362</dc:creator>
      <dc:date>2014-12-01T16:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429044#M42040</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can build a selection set from an array of ObjectIds using the static SelectionSet.FromObjectIds() method.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 17:43:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429044#M42040</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-12-01T17:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429091#M42041</link>
      <description>&lt;P&gt;Cool! I had no idea I could do that ... Now I'm not too sure how to pass this into a rotate command using SendStringToExecute:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;CommandMethod("My-Rotate")&amp;gt; _
Public Sub MyRotate()
    'Get the current document and database 
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database
    Dim acObj As Object
    Dim entRes As PromptEntityResult
    Dim entOpts As PromptEntityOptions
    Dim rb As ResultBuffer
    Dim FoundHunter As Boolean
    Dim acBlkTbl As BlockTable
    Dim acBlkTblRec As BlockTableRecord
    Dim pickedPolyline As Polyline = Nothing
    Dim SelSet As SelectionSet
    Dim Lst_ObjId As New List(Of ObjectId)

    'Prompt user to select the conveyor he wants to rotate
    Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
    entOpts = New PromptEntityOptions(vbLf &amp;amp; "Choose the object you wish to rotate")
    entRes = acDoc.Editor.GetEntity(entOpts)

    If (entRes.Status = PromptStatus.OK) Then

        'Start a transaction 
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            acObj = entRes.ObjectId.GetObject(OpenMode.ForRead)

            'Make sure the selected object was a polyline
            If Not TypeOf acObj Is Polyline Then MsgBox("You must choose a line or polyline") : Exit Sub

            rb = New ResultBuffer
            rb = entRes.ObjectId.GetObject(OpenMode.ForRead).XData()&lt;BR /&gt;&lt;BR /&gt;            'Sets the correct Project Conveyor
            ProjectConveyor.SetByDataTable(GetPKFromResultBuffer(rb), Project.PK_Project) &lt;BR /&gt;            &lt;BR /&gt;            'Open the Block table for read 
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)             &lt;BR /&gt;           &lt;BR /&gt;            'Open the Block table record Model space for write &lt;BR /&gt;            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 

            'Go through the Block Table Record and build the collection ID
            For Each acObjId As ObjectId In acBlkTblRec
                rb = New ResultBuffer
                rb = acObjId.GetObject(OpenMode.ForRead).XData()
                FoundHunter = False

                If Not rb Is Nothing Then
                    For Each tv As TypedValue In rb
                        If tv.TypeCode = DxfCode.ExtendedDataRegAppName Then
                            If tv.Value = "MY_PROGRAM_NAME" Then FoundHunter = True
                        End If
                        If FoundHunter And tv.TypeCode = DxfCode.ExtendedDataInteger32 Then
                            If tv.Value = ProjectConveyor.PK_ProjectConveyor Then
                                Lst_ObjId.Add(acObjId) 'Sets up all object IDs correctly here
                                Exit For
                            End If
                        End If
                    Next

                    rb.Dispose()
                End If
            Next

            'Create a selection set from object IDs
            SelSet = SelectionSet.FromObjectIds(Lst_ObjId.ToArray)

            'Use AUTOCAD's Rotate function knowing we have all selections in selection set
            acDoc.SendStringToExecute(" ROTATION ", False, False, False)

            'Save the new objects to the database 
            ProjectConveyor.Update()
            acTrans.Commit()
        End Using
    End If
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is the code I use but I am really not sure how to execute the ROTATION command. Afterwards, when the conveyor is selected, the user will follow AutoCAD's rotate guidelines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 18:36:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429091#M42041</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T18:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429118#M42042</link>
      <description>&lt;P&gt;Rather than using SendStringToExecute(), if you're targeting AutoCAD 2015, use the new Editor.Command() method.&lt;/P&gt;
&lt;P&gt;For prior versions, Tony "DiningPhiliosopher" Tanzillo, provided&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/problem-calling-acedcmd/m-p/4752787/highlight/true#M38687" target="_blank"&gt;a wrapper for the undocumented RunCommand()&lt;/A&gt; method.&lt;/P&gt;
&lt;P&gt;Both work the same way and accept selection sets as arguments :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;acDoc.Editor.Command("_.rotate", SelSet, "", basePt, angleInCurrentAngularUnits)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;basePt can be expressed as a string : "10,20,0" or as a Point3d, the same for angleInCurrentAngularUnits (string or double).&lt;/P&gt;
&lt;P&gt;If the last parameters are omitted Editor.Command() prompts the user to input them.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 18:57:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429118#M42042</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-12-01T18:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429121#M42043</link>
      <description>We're using AutoCAD 2014. Do you have the link towards Tony's RunCommand() ? I think we're very close!&lt;BR /&gt;&lt;BR /&gt;Merci! &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Mon, 01 Dec 2014 18:56:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429121#M42043</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T18:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429138#M42044</link>
      <description>&lt;P&gt;Thanks for the link.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I implemented a module that contains exactly what Tony suggested for the RunCommand wrapper. I have no errors, everything seems to be passing fluidly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Linq.Expressions
Imports System.Reflection
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput

Module EditorInputExtensionMethods
    &amp;lt;System.Runtime.CompilerServices.Extension()&amp;gt; _
    Public Function Command(editor As Editor, ParamArray args As Object()) As PromptStatus
        If editor Is Nothing Then
            Throw New ArgumentNullException("editor")
        End If
        Return runCommand(editor, args)
    End Function
    Dim runCommand As Func(Of Editor, Object(), PromptStatus) = GenerateRunCommand()
    Private Function GenerateRunCommand() As Func(Of Editor, Object(), PromptStatus)
        Dim method As MethodInfo = GetType(Editor).GetMethod( _
        "RunCommand", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.[Public])
        Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "editor")
        Dim args As ParameterExpression = Expression.Parameter(GetType(Object()), "args")
        Return Expression.Lambda(Of Func(Of Editor, Object(), PromptStatus)) _
        (Expression.Call(instance, method, args), instance, args).Compile()
    End Function
End Module&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although, it doesn't provide a rotate command to my drawing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG title="SelSet.png" border="0" src="https://forums.autodesk.com/t5/image/serverpage/image-id/143980i105614D829105BC4/image-size/original?v=mpbl-1&amp;amp;px=-1" alt="SelSet.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried "_.rotation" since my AutoCAD is in French but it didn't change anything. Is it because my SelSet has "Unavailable" entries or something? That doesn't seem right to me ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My object IDs are correctly added to the list. Perhaps I'm missing something very obvious... It doesn't seem to prompt me for anything when I execute this operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 19:26:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429138#M42044</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T19:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429159#M42045</link>
      <description>&lt;P&gt;It seems to me that with VB (I'm not very familiar with VB), you need to import the module where the extension method is defined in the file where the command which use it is defined :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Import EditorInputExtensionMethods&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your AutoCAD is French use "rotation" / ".rotation" or "_rotate" / "_.rotate". The underscore is used to call the global command name and the dot insure to call the native (undefined) command.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2014 19:44:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429159#M42045</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-12-01T19:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429179#M42046</link>
      <description>I thought I needed to import the module as well but if it is in the same namespace it will still accept it. I tried importing it anyways and get a green swiggly error, probably because it is already included and not needed.&lt;BR /&gt;&lt;BR /&gt;I tried "rotation", ".rotation", "_rotate", "_.rotate", "rotate" and no luck ... Any idea what the next step should be?&lt;BR /&gt;&lt;BR /&gt;I appreciate your help.</description>
      <pubDate>Mon, 01 Dec 2014 20:04:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429179#M42046</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T20:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429236#M42047</link>
      <description>If it helps, I tried to see what was returned as a value from the acDoc.Editor.Command() method and it returns Error(-5001).</description>
      <pubDate>Mon, 01 Dec 2014 21:16:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429236#M42047</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-01T21:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429640#M42048</link>
      <description>&lt;P&gt;This works for me (AutoCAD 2014). I hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Imports System.Linq.Expressions
Imports System.Reflection
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Namespace MeasureSample

    Module EditorInputExtensionMethods

        &amp;lt;System.Runtime.CompilerServices.Extension&amp;gt; _
        Public Function Command(editor As Editor, ParamArray args As Object()) As PromptStatus
            If editor Is Nothing Then
                Throw New ArgumentNullException("editor")
            End If
            Return runCommand(editor, args)
        End Function

        Dim runCommand As Func(Of Editor, Object(), PromptStatus) = GenerateRunCommand()

        Private Function GenerateRunCommand() As Func(Of Editor, Object(), PromptStatus)
            Dim method As MethodInfo = GetType(Editor).GetMethod( _
                "RunCommand", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.[Public])
            Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "editor")
            Dim args As ParameterExpression = Expression.Parameter(GetType(Object()), "args")
            Return Expression.Lambda(Of Func(Of Editor, Object(), PromptStatus))( _
                Expression.Call(instance, method, args), instance, args).Compile()
        End Function

    End Module

    Public Class CommandMethods

        &amp;lt;CommandMethod("TEST")&amp;gt;
        Public Sub Test()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim ids As ObjectIdCollection = New ObjectIdCollection()
            Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction()
                Dim space As BlockTableRecord = _
                    DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead), BlockTableRecord)
                For Each id As ObjectId In space
                    ids.Add(id)
                Next
            End Using
            Dim array(ids.Count - 1) As ObjectId
            ids.CopyTo(array, 0)
            Dim selSet As SelectionSet = SelectionSet.FromObjectIds(array)
            ed.Command("_.rotate", selSet, "")
        End Sub

    End Class

End Namespace&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 08:57:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429640#M42048</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-12-02T08:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429802#M42049</link>
      <description>&lt;P&gt;Gilles,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After some more testing, here's what I came up with.&amp;nbsp;I have AutoCAD 2014 as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been testing this using my Acad Standard executable:&lt;/P&gt;&lt;P&gt;&lt;IMG title="acad_std.png" border="0" src="https://forums.autodesk.com/t5/image/serverpage/image-id/144053iFFF936FF6B74498F/image-size/medium?v=mpbl-1&amp;amp;px=-1" alt="acad_std.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just tested it out in my Mechanical version and it works correctly.&lt;/P&gt;&lt;P&gt;&lt;IMG title="acad_mech.png" border="0" src="https://forums.autodesk.com/t5/image/serverpage/image-id/144052iE551A27ACB465CD4/image-size/medium?v=mpbl-1&amp;amp;px=-1" alt="acad_mech.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I utilize the Standard version (normally) and it doesn't work in that. Any idea why? That's so odd! Thanks for going through that much trouble though. I just need to figure out why it's glitchy in standard Acad.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 12:31:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429802#M42049</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-02T12:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429981#M42050</link>
      <description>&lt;P&gt;Hi Gilles,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quick question related to this editor.Command() wrapper.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to update my database once the command is completed. Although, when I step through the code, it goes through the command and finishes the sub before the user can actually do any input. This means I cannot update the database with the newly gotten points (Point3d) because it is already out of the End Sub routine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a fix for this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 14:58:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429981#M42050</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-02T14:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5430226#M42051</link>
      <description>&lt;P&gt;As far as I know, the Editor.Command() (this wrapper as the 2015 built-in one) needs to have all its arguments to run synchronously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With AutoCAD 2015, the Editor.CommandAsync() allows what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        Public Async Sub TestCommand()
            ' ...
            Await ed.CommandAsync("_.rotate", selSet, "", Editor.PauseToken, Editor.PauseToken)
            ' ...
        End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With prior versions of AutoCAD, you could easily write this in AutoLISP.&lt;/P&gt;
&lt;P&gt;If you need .NET, you'll have to take the Jig route, here's a little C# sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    public class CommandMethods
    {
        [CommandMethod("TEST")]
        public void Test()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptSelectionResult selection = ed.GetSelection();
            if (selection.Status != PromptStatus.OK)
                return;

            PromptPointResult pointResult = ed.GetPoint("\nBase point: ");
            if (pointResult.Status != PromptStatus.OK)
                return;

            SelectionSet selSet = selection.Value;
            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
            Point3d basePoint = pointResult.Value.TransformBy(ucs);
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity[] entities = new Entity[selSet.Count];
                for (int i = 0; i &amp;lt; selSet.Count; i++)
                {
                    entities[i] = (Entity)tr.GetObject(selSet[i].ObjectId, OpenMode.ForWrite);
                }

                // create a new instance of RotateJig
                RotateJig jig = new RotateJig(entities, basePoint, ucs.CoordinateSystem3d.Zaxis);
                // pass it to the Editor.Drag method
                PromptResult result = ed.Drag(jig);

                // if the user didn't cancel...
                if (result.Status == PromptStatus.OK)
                {
                    // apply the rotation to each entity
                    foreach (Entity entity in entities)
                    {
                        entity.TransformBy(jig.Rotation);
                    }
                }
                tr.Commit();
            }
        }
    }

    // the RotateJig inherits from DrawJid to deal with multiple entities
    class RotateJig : DrawJig
    {
        private Entity[] entities;
        private Point3d basePoint;
        double angle = 0.0;
        Vector3d axis;

        // public property (needed from the calling method)
        public Matrix3d Rotation { get; private set; }

        // constructor
        public RotateJig(Entity[] ents, Point3d basePoint, Vector3d axis)
        {
            this.entities = ents;
            this.basePoint = basePoint;
            this.axis = axis;
        }

        // dynamically rotate the entities
        protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
        {
            Autodesk.AutoCAD.GraphicsInterface.WorldGeometry geo = draw.Geometry;
            if (geo != null)
            {
                geo.PushModelTransform(this.Rotation);
                foreach (Entity ent in entities)
                {
                    geo.Draw(ent);
                }
                geo.PopModelTransform();
            }
            return true;
        }

        // prompt the user to specify a rotation
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptAngleOptions options = new JigPromptAngleOptions("\nSpecify rotation: ");
            options.BasePoint = basePoint;
            options.UseBasePoint = true;
            options.Cursor = CursorType.RubberBand;
            PromptDoubleResult result = prompts.AcquireAngle(options);
            if (result.Value == angle)
            {
                return SamplerStatus.NoChange;
            }
            angle = result.Value;
            this.Rotation = Matrix3d.Rotation(angle, axis, basePoint);
            return SamplerStatus.OK;
        }
    }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 17:55:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5430226#M42051</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-12-02T17:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass ObjectIdCollection into built-in Rotate command?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5430319#M42052</link>
      <description>&lt;P&gt;****! I was afraid of that. I was hoping for a way to run my command and code synchronously. So I guess either I upgrade to AutoCAD 2015 and use the Editor.CommandAsync() or I recreate the rotate function using the DrawJig?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2014 19:00:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5430319#M42052</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-02T19:00:33Z</dc:date>
    </item>
  </channel>
</rss>

