CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

创建实心填充区域 (.NET)

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

您可以创建用颜色填充的三角形和四边形区域。创建填充区域时,将 FILLMODE 系统变量设置为 off 以提高性能,并在创建填充后重新打开。

创建四边形实心填充区域时,第三点和第四个点的序列将确定其形状。比较下图:

前两个点定义面的一个边。第三个点的定义与第二个点对角线相反。如果第四个点设置为等于第三个点,则创建一个填充三角形。

创建实心填充对象

下面的示例使用坐标 (0, 0, 0)、(5, 0, 0)、(5, 8, 0) 和 (0, 8, 0) 在模型空间中创建四边形实体(领结)。它还使用坐标 (10, 0, 0)、(15, 0, 0)、(10, 8, 0) 和 (15, 8, 0) 创建矩形的四边形实体。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("Add2DSolid")> _
Public Sub Add2DSolid()
    '' 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 quadrilateral (bow-tie) solid in Model space
        Using ac2DSolidBow As Solid = New Solid(New Point3d(0, 0, 0), _
                                                New Point3d(5, 0, 0), _
                                                New Point3d(5, 8, 0), _
                                                New Point3d(0, 8, 0))

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

        '' Create a quadrilateral (square) solid in Model space
        Using ac2DSolidSqr As Solid = New Solid(New Point3d(10, 0, 0), _
                                                New Point3d(15, 0, 0), _
                                                New Point3d(10, 8, 0), _
                                                New Point3d(15, 8, 0))

            '' Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(ac2DSolidSqr)
            acTrans.AddNewlyCreatedDBObject(ac2DSolidSqr, True)
        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("Add2DSolid")]
public static void Add2DSolid()
{
    // 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 quadrilateral (bow-tie) solid in Model space
        using (Solid ac2DSolidBow = new Solid(new Point3d(0, 0, 0),
                                        new Point3d(5, 0, 0),
                                        new Point3d(5, 8, 0),
                                        new Point3d(0, 8, 0)))
        {
            // Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(ac2DSolidBow);
            acTrans.AddNewlyCreatedDBObject(ac2DSolidBow, true);
        }

        // Create a quadrilateral (square) solid in Model space
        using (Solid ac2DSolidSqr = new Solid(new Point3d(10, 0, 0),
                                        new Point3d(15, 0, 0),
                                        new Point3d(10, 8, 0),
                                        new Point3d(15, 8, 0)))
        {
            // Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(ac2DSolidSqr);
            acTrans.AddNewlyCreatedDBObject(ac2DSolidSqr, true);
        }

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

VBA/ActiveX 代码参考

Sub Add2DSolid()
    Dim solidObj As AcadSolid
    Dim point1(0 To 2) As Double
    Dim point2(0 To 2) As Double
    Dim point3(0 To 2) As Double
    Dim point4(0 To 2) As Double
 
    ' Define the solid
    point1(0) = 0#: point1(1) = 0#: point1(2) = 0#
    point2(0) = 5#: point2(1) = 0#: point2(2) = 0#
    point3(0) = 5#: point3(1) = 8#: point3(2) = 0#
    point4(0) = 0#: point4(1) = 8#: point4(2) = 0#
    ' Create the solid object in model space
    Set solidObj = ThisDrawing.ModelSpace.AddSolid _
                                    (point1, point2, point3, point4)
 
    ' Define the solid
    point1(0) = 10#: point1(1) = 0#: point1(2) = 0#
    point2(0) = 15#: point2(1) = 0#: point2(2) = 0#
    point3(0) = 10#: point3(1) = 8#: point3(2) = 0#
    point4(0) = 15#: point4(1) = 8#: point4(2) = 0#
    ' Create the solid object in model space
    Set solidObj = ThisDrawing.ModelSpace.AddSolid _
                                    (point1, point2, point3, point4)
 
    ZoomAll
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部