CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

编辑样条曲线 (.NET)

2024-5-18 19:13| 发布者: admin| 查看: 111| 评论: 0|原作者: admin|来自: AutoCAD

编辑样条曲线 (.NET)

您可以编辑开放样条或闭样条的属性,甚至可以将其转换为折线。使用以下属性可以打开或关闭样条曲线、更改其控制点或反转样条曲线的方向:

返回样条曲线的多项式表示形式。

EndFitTangent(端拟切线)

将样条曲线的端切作为方向向量返回。

FitTolerance(健身耐受性)

使用新的公差值将样条调整到现有点。

NumControlPoints

返回样条的控制点数。

NumFitPoints

返回样条曲线的拟合点数。

启动FitTangent

返回样条曲线的起始切线。

此外,还可以使用以下方法编辑样条曲线:

插入FitPointAt

将单个拟合点添加到给定索引处的样条曲线。

提升学位

将样条的度数增加到给定度数。

GetControlPointAt

获取给定索引处样条曲线的控制点。(仅获取一个控制点。该属性包含样条的控制点数。NumControlPoints

GetFitPoint在

获取样条曲线在给定索引处的拟合点。(仅获得一个拟合点。若要查询样条的所有拟合点,请使用该属性,然后查询使用其成员函数返回的对象。该属性包含样条曲线的拟合点数。FitDataFitDataGetFitPointsNumFitPoints

删除FitPoint在

删除样条曲线在给定索引处的拟合点。

反向曲线

反转样条的方向。

SetControlPointAt

在给定索引处设置样条的控制点。

设置FitPointAt

设置样条曲线在给定索引处的拟合点。(仅设置一个拟合点。若要更改样条曲线的所有拟合点,请使用该属性。FitPoints

SetWeightAt

在给定索引处设置控制点的权重。

使用以下只读属性查询样条曲线:

面积

获取样条曲线的封闭区域。

指示样条曲线是打开的还是闭合的。

获取样条的多项式表示的度数。

IsPeriodic

指定给定样条是否为周期性样条曲线。

是平面的

指定给定样条是否为平面样条。

IsRational的

指定给定样条是否为有理数。

NumControlPoints

获取样条的控制点数。

NumfFit点数

获取样条曲线的拟合点数。

更改样条上的控制点

本示例创建一个样条曲线,然后更改样条曲线的第一个控制点。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("EditSpline")> _
Public Sub EditSpline()
    '' Get the current document and database
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database

    '' Start a transaction
    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

        '' Open the Block table for read
        Dim acBlkTbl As BlockTable
        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
                                     OpenMode.ForRead)

        '' Open the Block table record Model space for write
        Dim acBlkTblRec As BlockTableRecord
        acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                        OpenMode.ForWrite)

        '' Create a Point3d Collection
        Dim acPt3dColl As Point3dCollection = New Point3dCollection()
        acPt3dColl.Add(New Point3d(1, 1, 0))
        acPt3dColl.Add(New Point3d(5, 5, 0))
        acPt3dColl.Add(New Point3d(10, 0, 0))

        '' Set the start and end tangency
        Dim acStartTan As Vector3d = New Vector3d(0.5, 0.5, 0)
        Dim acEndTan As Vector3d = New Vector3d(0.5, 0.5, 0)

        '' Create a spline
        Using acSpline As Spline = New Spline(acPt3dColl, _
                                              acStartTan, _
                                              acEndTan, 4, 0)

            '' Set a control point
            acSpline.SetControlPointAt(0, New Point3d(0, 3, 0))

            '' Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acSpline)
            acTrans.AddNewlyCreatedDBObject(acSpline, True)
        End Using

        '' Save the new objects to the database
        acTrans.Commit()
    End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("EditSpline")]
public static void EditSpline()
{
    // Get the current document and database
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;

    // Start a transaction
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Open the Block table for read
        BlockTable acBlkTbl;
        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                        OpenMode.ForRead) as BlockTable;

        // Open the Block table record Model space for write
        BlockTableRecord acBlkTblRec;
        acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                        OpenMode.ForWrite) as BlockTableRecord;
                
        // Create a Point3d Collection
        Point3dCollection acPt3dColl = new Point3dCollection();
        acPt3dColl.Add(new Point3d(1, 1, 0));
        acPt3dColl.Add(new Point3d(5, 5, 0));
        acPt3dColl.Add(new Point3d(10, 0, 0));

        // Set the start and end tangency
        Vector3d acStartTan = new Vector3d(0.5, 0.5, 0);
        Vector3d acEndTan = new Vector3d(0.5, 0.5, 0);

        // Create a spline
        using (Spline acSpline = new Spline(acPt3dColl,
                                        acStartTan,
                                        acEndTan, 4, 0))
        {

            // Set a control point
            acSpline.SetControlPointAt(0, new Point3d(0, 3, 0));

            // Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acSpline);
            acTrans.AddNewlyCreatedDBObject(acSpline, true);
        }

        // Save the new objects to the database
        acTrans.Commit();
    }
}

VBA/ActiveX 代码参考

Sub EditSpline()
    ' Create the spline
    Dim splineObj As AcadSpline
    Dim startTan(0 To 2) As Double
    Dim endTan(0 To 2) As Double
    Dim fitPoints(0 To 8) As Double
 
    startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0
    endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0
    fitPoints(0) = 1: fitPoints(1) = 1: fitPoints(2) = 0
    fitPoints(3) = 5: fitPoints(4) = 5: fitPoints(5) = 0
    fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0
    Set splineObj = ThisDrawing.ModelSpace. _
                                  AddSpline(fitPoints, startTan, endTan)
    splineObj.Update
 
    ' Change the coordinate of the first fit point
    Dim controlPoint(0 To 2) As Double
    controlPoint(0) = 0
    controlPoint(1) = 3
    controlPoint(2) = 0
    splineObj.SetControlPoint 0, controlPoint
    splineObj.Update
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 11:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部