AutoCAD VBNET 曲线求交点

autocad,vbnet,曲线,交点 · 浏览次数 : 10

小编点评

**曲线求取点** **步骤:** 1. **获取用户坐标系:**确保应用程序已设置正确的世界坐标系。 2. **获取两个 PolyLine 对象:**使用 `PromptEntityOptions` 获取第一个和第二个 PolyLine 对象。 3. **检查曲线平面的交点数量:**如果两个曲线平面不共面,则无法求取交点。 4. **求取交点:**如果平面的交点数量大于 0,则使用 `CurveCurveIntersector3d` 类计算交点。 5. **绘制交点:**将交点坐标添加到 BlockTable 中。 6. **提交 transaction:**将交点记录到数据库中。 7. **显示结果:**显示交点生成成功的信息。 **代码示例:** ```vba Sub TT_PolyLineCrossCheck() 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 Dim peo As New PromptEntityOptions("选择第一条PolyLine") With peo .SetRejectMessage("only Polyline can be select") .AddAllowedClass(GetType(Polyline), False) End With Dim per1 = ed.GetEntity(peo) Dim peo2 As New PromptEntityOptions("选择第二条PolyLine") Dim per2 = ed.GetEntity(peo) If per1.Status <> PromptStatus.OK Or per2.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 c1 As Curve = per1.ObjectId.GetObject(OpenMode.ForRead) Dim c2 As Curve = per2.ObjectId.GetObject(OpenMode.ForRead) Dim cur3d1 As Curve3d = c1.GetGeCurve() Dim cur3d2 As Curve3d = c2.GetGeCurve() Dim c1Plane As Curve = c1.GetPlane() Dim c2Plane As Curve = c2.GetPlane() If Not c1Plane.IsCoplanarTo(c2Plane) Then MsgBox("两条曲线不共面无法求取交点", MsgBoxStyle.Critical) Return End If Dim c1c2 As New CurveCurveIntersector3d(cur3d1, cur3d2, c1Plane.Normal) If c1c2.NumberOfIntersectionPoints > 0 Then ' 获取交点的坐标 For index = 0 To c1c2.NumberOfIntersectionPoints - 1 Dim p As New DBPoint(c1c2.GetIntersectionPoint(index)) ms.AppendEntity(p) Next tr.Commit() MsgBox("交点生成成功!\") Else MsgBox("找不到交点", MsgBoxStyle.Critical) End If End Using End Sub ```

正文

曲线求取点,利用几何库

<CommandMethod(NameOf(TT_PolyLineCrossCheck))>
Public Sub TT_PolyLineCrossCheck()
    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 Polyline can be select")
            .AddAllowedClass(GetType(Polyline), False)
        End With
        Dim per1 = ed.GetEntity(peo)
        peo.Message = "选择第二条PolyLine"
        Dim per2 = ed.GetEntity(peo)
        If per1.Status <> PromptStatus.OK Or per2.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 c1 As Curve = per1.ObjectId.GetObject(OpenMode.ForRead)
            Dim c2 As Curve = per2.ObjectId.GetObject(OpenMode.ForRead)
            Dim cur3d1 As Curve3d = c1.GetGeCurve()
            Dim cur3d2 As Curve3d = c2.GetGeCurve()
            Dim c1Plane = c1.GetPlane()
            Dim c2Plane = c2.GetPlane()
            If Not c1Plane.IsCoplanarTo(c2Plane) Then
                MsgBox("两条曲线不共面无法求取交点", MsgBoxStyle.Critical)
                Return
            End If
            Dim c1c2 As New CurveCurveIntersector3d(cur3d1, cur3d2, c1Plane.Normal)
            If c1c2.NumberOfIntersectionPoints > 0 Then '获取交点的个数
                For index = 0 To c1c2.NumberOfIntersectionPoints - 1 '提取每个交点的坐标
                    Dim p As New DBPoint(c1c2.GetIntersectionPoint(index))
                    ms.AppendEntity(p)
                    tr.AddNewlyCreatedDBObject(p, True)
                Next
                tr.Commit()
                MsgBox("交点生成成功!")
            Else
                MsgBox("找不到交点", MsgBoxStyle.Critical)
            End If
        End Using
    Catch ex As System.Exception
        Application.ShowAlertDialog(ex.StackTrace)
    End Try
End Sub

 

与AutoCAD VBNET 曲线求交点相似的内容:

AutoCAD VBNET 曲线求交点

曲线求取点,利用几何库 Public Sub TT_PolyLineCrossCheck() Dim doc As Document = Application.DocumentManager.MdiAct

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

求取空间任意曲线在xoy/yoz/xoz平面的投影 Public Sub TT_CurveProjected() Dim doc As Document = Application.DocumentManager.

AutoCAD VBNET 当前文档保存

当前文档保存总出问题 现在借助com的方法实现了保存文件 Public Sub TT_SaveDrawing() Dim doc As Document = Application.DocumentManager.Mdi

VBNET AUTOCAD 单行文字OBB有向包围盒的计算

遇到要求单行文字包围和的需求,发现AutoCAD自带的算法仅能求出正交包围盒,如下图所示的粉色矩形 我想获取下图下图所示蓝色矩形的部分及OBB 计算方法图形示例: 下面是完整的代码,其中求D点的坐标p1涉及到向量定比分点公式

AutoCAD VBA 获取字体样式列表

cad中的可用字体样式 获取windows标准字体 Dim winFontsdir As String winFontsdir = VBA.Environ("windir") & "\Fonts\" If winFontsdir <> vbNullString Then Dim shxfl As S

AutoCAD C# 程序插入OLE图片

参考博客地址 https://www.cnblogs.com/edata/p/17474704.html var fn = @"D:\NetDriveDir\OneDrive\软件工具\MNYT.png"; var bm = Bitmap.FromFile(fn); Clipboard.SetIma

C# AutoCAD 利用Editor.CommandAsync 同步监测自带命令的执行情况

#1官方文档并无相关解释:AutoCAD 2023 Developer and ObjectARX Help | Editor.CommandAsync Method | Autodesk #2 上例子,我用自带的命令画一个圆,画完后我要修改它的颜色,此时该如何操作呢,下面是可用的代码 [Comma