Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports System.math Public Class GILSclass1 _ Public Sub TestPline3d() Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database Dim trans As Transaction = db.TransactionManager.StartTransaction() Dim prEnt As New PromptEntityOptions("Select Entity to Rotate: ") Dim prEntRes As PromptEntityResult = editor.GetEntity(prEnt) If prEntRes.Status <> PromptStatus.OK Then Return Dim id As ObjectId = prEntRes.ObjectId Dim Ent As Object = trans.GetObject(id, OpenMode.ForRead) Dim prpt As New PromptPointOptions("Input Base Point: ") Dim prptres As PromptPointResult = editor.GetPoint(prpt) If prptres.Status <> PromptStatus.OK Then Return Dim Bp As Point3d = prptres.Value Dim prang As New PromptAngleOptions("Input Rotation Angle: ") Dim prangres As PromptDoubleResult = editor.GetAngle(prang) If prangres.Status <> PromptStatus.OK Then Return Dim Ang As Double = prangres.Value Ang = DTR(Ang) Rotate(Ent, Bp, Ang) End Sub Public Function Rotate(ByRef Ent As Object, _ ByRef Bp As Point3d, _ ByRef Ang As Double) As Object Dim vMatrix As Object vMatrix = CreateMatrix() vMatrix(0, 3) = -Bp.X vMatrix(1, 3) = -Bp.Y vMatrix(2, 3) = -Bp.Z Dim vRotate As Object vRotate = CreateMatrix() vRotate(0, 0) = Cos(Ang) vRotate(0, 1) = -Sin(Ang) vRotate(1, 0) = Sin(Ang) vRotate(1, 1) = Cos(Ang) Dim vTmpMatrix As Object vTmpMatrix = ConcatenateMatrices(vMatrix, vRotate) vMatrix(0, 3) = Bp.X vMatrix(1, 3) = Bp.Y vMatrix(2, 3) = Bp.Z vRotate = ConcatenateMatrices(vTmpMatrix, vMatrix) vRotate(0, 3) = -vRotate(0, 3) vRotate(1, 3) = -vRotate(1, 3) Ent.TransformBy(vRotate) End Function Public Function Pi() As Double Pi = Atan(1) * 4 End Function Public Function DTR(ByVal dAng As Double) As Double DTR = dAng / 180 * Pi() End Function Public Function CreateMatrix() As Object Dim dMatrix(0 To 3, 0 To 3) As Double dMatrix(0, 0) = 1 dMatrix(1, 1) = 1 dMatrix(2, 2) = 1 dMatrix(3, 3) = 1 CreateMatrix = dMatrix End Function Public Function ConcatenateMatrices(ByRef vMatrix1 As Object, _ ByRef vMatrix2 As Object) As Object Dim iOutSide As Integer Dim iInSide As Integer Dim iMathLoop As Integer Dim dResult(0 To 3, 0 To 3) As Double For iOutSide = 0 To 3 For iInSide = 0 To 3 dResult(iOutSide, iInSide) = 0 For iMathLoop = 0 To 3 dResult(iOutSide, iInSide) = dResult(iOutSide, iInSide) + _ vMatrix1(iOutSide, iMathLoop) * vMatrix2(iMathLoop, iInSide) Next iMathLoop Next iInSide Next iOutSide ConcatenateMatrices = dResult End Function End Class