AutoCAD旋转组使用参考角度VB.NET



我试图使用指定的参考角度旋转一组对象,但是我下面的代码总是使用0作为参考角度。希望有人能帮我解决这个问题。

提前感谢。

<CommandMethod("ROTATEGROUP")>
Public Shared Sub ROTATEGROUP()
Dim doc As Document = AutoCADApp.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim GroupName As String = ed.GetString("Group Name").StringResult
Dim X As Single = ed.GetString("X").StringResult
Dim Y As Single = ed.GetString("Y").StringResult
Dim Z As Single = ed.GetString("Z").StringResult
Dim RefAngle As Single = ed.GetString("Refence Angle").StringResult * (Math.PI / 180)
Dim NewAngle As Single = ed.GetString("New Angle").StringResult * (Math.PI / 180)
Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
Dim gd As DBDictionary = CType(tr.GetObject(db.GroupDictionaryId, OpenMode.ForRead), DBDictionary)
Dim grpId As ObjectId = gd.GetAt(GroupName)
Dim grp As Group = CType(tr.GetObject(grpId, OpenMode.ForWrite), Group)
Dim ids As ObjectId() = grp.GetAllEntityIds()
Dim curUCSMatrix As Matrix3d = doc.Editor.CurrentUserCoordinateSystem
Dim curUCS As CoordinateSystem3d = curUCSMatrix.CoordinateSystem3d
For i As Integer = 0 To ids.Length - 1
Dim ent As Entity = CType(tr.GetObject(ids(i), OpenMode.ForWrite), Entity)
ent.TransformBy(Matrix3d.Rotation(NewAngle, curUCS.Zaxis, New Point3d(X, Y, Z)))
Next
'Save to the database
tr.Commit()
End Using
End Sub

旋转角度应为:NewAngle - reangle。你应该使用GetPoint和GetAngle而不是GetString。

最新更新