Hello,
Our users must be able to rotate a bunch of lines, circles, blocks etc (which result in looking like a conveyor). I am trying to pass a SelectionSet using the built-in rotate command of AutoCAD.
I got a lot of help on the AutoDesk forums:
http://forums.autodesk.com/t5/net/ho...5429159#M42620
I seem to be in a stalemate right now. I don't have AutoCAD 2015 so I use a RunCommand wrapper to enable me to use the editor.Command().
Code:
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
<System.Runtime.CompilerServices.Extension()> _
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
I then populate my SelectionSet using an object ID collection that was built. Here is my code that I use to try and use the already built-in rotate command that AutoCAD has to offer:
Code:
<CommandMethod("My-Rotate")> _
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 & "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()
'Sets the correct Project Conveyor
ProjectConveyor.SetByDataTable(GetPKFromResultBuffer(rb), Project.PK_Project)
'Open the Block table for read
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
'Open the Block table record Model space for write
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.Editor.Command("_.rotate", SelSet, "")
'Save the new objects to the database
ProjectConveyor.Update()
acTrans.Commit()
End Using
End If
End Sub
My issue is, whenever I get to the acDoc.Editor.Command() portion, it does not prompt the user to rotate anything. It returns Error(-5001) ... Any ideas?
Bookmarks