CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

创建点对象 (.NET)

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

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

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

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

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

更改 and 后,下次再生图形时,现有点的外观将更改。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-5-19 15:03

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部