我正在嘗試使用指定的參考角度旋轉一組物件,但是我下面的代碼始終使用 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
uj5u.com熱心網友回復:
旋轉角度應為:NewAngle - RefAngle。您應該使用GetPoint和GetAngle而不是 GetString。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/496415.html
上一篇:計算薪水的最佳方法
