AutoCAD VBNET 获取曲线在3个基本平面的投影

求取空间任意曲线在xoy/yoz/xoz平面的投影

 

 

 <CommandMethod(NameOf(TT_CurveProjected))>
 Public Sub TT_CurveProjected()
     Dim doc As Document = Application.DocumentManager.MdiActiveDocument
     Dim db As Database = doc.Database
     Dim ed As Editor = doc.Editor
     '将用户坐标系转换成世界坐标系
     If Application.GetSystemVariable("WORLDUCS").ToString() <> "1" Then
         ed.CurrentUserCoordinateSystem = Matrix3d.Identity
         ed.Regen()
     End If

     Try
         Dim peo As New PromptEntityOptions("选择PolyLine")
         With peo
             .SetRejectMessage("only Curve can be select")
             .AddAllowedClass(GetType(Curve), False)
         End With
         Dim per = ed.GetEntity(peo)
         If per.Status <> PromptStatus.OK Then Return
         Using tr As Transaction = db.TransactionManager.StartTransaction()
             Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
             Dim ms As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
             Dim oriCurve As Curve = per.ObjectId.GetObject(OpenMode.ForRead)
             Dim xoyPlane As New Plane(Point3d.Origin, Vector3d.ZAxis)
             Dim xozPlane As New Plane(Point3d.Origin, Vector3d.YAxis)
             Dim yozPlane As New Plane(Point3d.Origin, Vector3d.XAxis)
             '创建曲线在xoy平面的投影
             Dim cur = oriCurve.GetOrthoProjectedCurve(xoyPlane)
             cur.Color = Color.FromColorIndex(ColorMethod.ByAci, 150)
             ms.AppendEntity(cur)
             tr.AddNewlyCreatedDBObject(cur, True)

             '创建曲线在xoz平面的投影
             Dim curXoz = oriCurve.GetOrthoProjectedCurve(xozPlane)
             curXoz.Color = Color.FromColorIndex(ColorMethod.ByAci, 100)
             ms.AppendEntity(curXoz)
             tr.AddNewlyCreatedDBObject(curXoz, True)

             '创建曲线在yoz平面的投影
             Dim curYoz = oriCurve.GetOrthoProjectedCurve(yozPlane)
             curYoz.Color = Color.FromColorIndex(ColorMethod.ByAci, 50)
             ms.AppendEntity(curYoz)
             tr.AddNewlyCreatedDBObject(curYoz, True)

             tr.Commit()
         End Using
     Catch ex As System.Exception
         Application.ShowAlertDialog(ex.StackTrace)
     End Try
     'Application.UpdateScreen()
 End Sub

 

posted @ 2023-10-05 09:05  南胜NanSheng  阅读(60)  评论(0编辑  收藏  举报