你好
我们的用户必须能够旋转一系列的线、圆、块等(这导致看起来像一个输送机)。我试图使用AutoCAD的内置旋转命令传递选择集。
我在AutoDesk论坛上获得了很多帮助:
http://forums.autodesk.com/t5/net/how-to-pass-objectidcollection-into-built-in-rotate-command/m-p/5429159#M42620
我现在似乎陷入了僵局。我没有AutoCAD 2015,所以我使用RunCommand包装器来使用编辑器。命令()。
- 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
然后,我使用构建的对象ID集合填充我的SelectionSet。以下是我用来尝试使用AutoCAD提供的内置旋转命令的代码:
- <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
我的问题是,每当我到达acDoc。编辑命令()部分,它不会提示用户旋转任何内容。它返回错误(-5001)。。。有什么想法吗? |