I’m trying to rotate a group of objects using a specified reference angle, however my code below always uses 0 as the reference angle. Hoping someone can help me out with this issue.
Thanks in advance.
<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
CodePudding user response:
The rotation angle should be: NewAngle - RefAngle. You should use GetPoint and GetAngle instead of GetString.