CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2020 开发者帮助

创建点对象 (.NET)

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

创建点对象 (.NET)

Point例如,对象可能很有用,例如,作为节点或参考点,您可以捕捉到对象并从中偏移对象。您可以设置点的样式及其相对于屏幕的大小或以绝对单位设置。

对象的 和 属性控制 Point 对象的外观。值 0、2、3 和 4 指定要绘制穿过点的图形。值为 1 时不选择要显示的任何内容。PdmodePdsizeDatabasePdmode

将 32、64 或 96 添加到上一个值中,除了通过该点绘制的图形外,还会选择要围绕该点绘制的形状:

Pdsize控制点图形的大小,但 0 和 1 除外。0 设置在图形区域高度的 5% 处生成点。设置为正值可指定点图形的绝对大小。负值被解释为视口大小的百分比。重新生成图形时,将重新计算所有点的大小。PdmodePdsize

更改 和 后,现有点的外观将在下次再生图形时更改。PdmodePdsize

创建一个 Point 对象并更改其外观

以下示例在“模型”空间的坐标 (5, 5, 0) 处创建一个对象。然后更新 和 属性。PointPdmodePdsize

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("AddPointAndSetPointStyle")> _
Public Sub AddPointAndSetPointStyle()
    '' 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 point at (4, 3, 0) in Model space
        Using acPoint As DBPoint = New DBPoint(New Point3d(4, 3, 0))

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

        '' Set the style for all point objects in the drawing
        acCurDb.Pdmode = 34
        acCurDb.Pdsize = 1

        '' 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("AddPointAndSetPointStyle")]
public static void AddPointAndSetPointStyle()
{
    // 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 point at (4, 3, 0) in Model space
        using (DBPoint acPoint = new DBPoint(new Point3d(4, 3, 0)))
        {
            // Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acPoint);
            acTrans.AddNewlyCreatedDBObject(acPoint, true);
        }

        // Set the style for all point objects in the drawing
        acCurDb.Pdmode = 34;
        acCurDb.Pdsize = 1;

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

VBA/ActiveX 代码参考

Sub AddPointAndSetPointStyle()
    Dim pointObj As AcadPoint
    Dim location(0 To 2) As Double
 
    ' Define the location of the point
    location(0) = 4#: location(1) = 3#: location(2) = 0#
 
    ' Create the point
    Set pointObj = ThisDrawing.ModelSpace.AddPoint(location)
    ThisDrawing.SetVariable "PDMODE", 34
    ThisDrawing.SetVariable "PDSIZE", 1
 
    ZoomAll
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-6-27 16:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部