CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

扩展和修剪对象 (.NET)

2023-1-1 13:47| 发布者: admin| 查看: 319| 评论: 0|来自: AutoCAD

您可以更改圆弧的角度,也可以更改直线、开放多段线、椭圆弧和开放样条曲线的长度。结果类似于扩展和修剪对象。

您可以通过编辑对象的属性来扩展或修剪对象。例如,要延长一条线,只需更改理论属性的坐标即可。要更改弧的角度,请更改弧的理论属性。更改一个或多个对象的特性后,可能需要重新生成显示才能在绘图窗口中查看更改。StartPointEndPointStartAngleEndAngle

加长一行

本示例创建一行,然后更改该行的终结点,从而生成更长的行。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("ExtendObject")> _
Public Sub ExtendObject()
    '' 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 line that starts at (4,4,0) and ends at (7,7,0)
        Using acLine As Line = New Line(New Point3d(4, 4, 0), _
                                        New Point3d(7, 7, 0))

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

            '' Update the display and diaplay a message box
            acDoc.Editor.Regen()
            Application.ShowAlertDialog("Before extend")

            '' Double the length of the line
            acLine.EndPoint = acLine.EndPoint + acLine.Delta
        End Using

        '' Save the new object 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("ExtendObject")]
public static void ExtendObject()
{
    // 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 line that starts at (4,4,0) and ends at (7,7,0)
        using (Line acLine = new Line(new Point3d(4, 4, 0),
                                new Point3d(7, 7, 0)))
        {

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

            // Update the display and diaplay a message box
            acDoc.Editor.Regen();
            Application.ShowAlertDialog("Before extend");

            // Double the length of the line
            acLine.EndPoint = acLine.EndPoint + acLine.Delta;
        }

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

VBA/ActiveX 代码参考

Sub ExtendObject()
    ' Define and create the line
    Dim lineObj As AcadLine
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2)  As Double
    startPoint(0) = 4
    startPoint(1) = 4
    startPoint(2) = 0
    endPoint(0) = 7
    endPoint(1) = 7
    endPoint(2) = 0
    Set lineObj = ThisDrawing.ModelSpace. _
                                AddLine(startPoint, endPoint)
    lineObj.Update
 
    ' Double the length of the line
    endPoint(0) = lineObj.endPoint(0) + lineObj.Delta(0)
    endPoint(1) = lineObj.endPoint(1) + lineObj.Delta(1)
    endPoint(2) = lineObj.endPoint(2) + lineObj.Delta(2)
    lineObj.endPoint = endPoint
    lineObj.Update
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 13:53

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部