CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

绑定外部参照 (.NET)

2023-1-1 10:07| 发布者: admin| 查看: 327| 评论: 0|来自: AutoCAD

摘要:

使用 Bind 方法将外部参照绑定到图形会使外部参照成为图形的永久部分,而不再是外部参照文件。外部引用的信息将变为块。更新外部参照图形时,绑定外部参照不会更新。此过程将绑定整个图形的数据库,包括其所有从属符号。

依赖符号是命名对象,例如块、标注样式、图层、线型和文本样式。绑定外部参照允许在当前图形中使用外部参照中的命名对象。

该方法需要两个参数:(对象ID的集合)和(布尔值)。如果参数设置为 True,则外部参照图形的符号名称在当前图形中以 <blockname>$x$ 为前缀,其中x是自动递增以避免覆盖现有块定义的整数。如果参数设置为 ,则外部参照图形的符号名称将合并到当前图形中,不带前缀。如果存在重复的名称,AutoCAD 将使用本地图形中已定义的符号。如果不确定图形是否包含重复的符号名称,建议您设置为。BindXrefxrefIdsinsertBindinsertBindinsertBindFalseinsertBindTrue

有关绑定外部参照的详细信息,请参阅产品帮助系统中的“关于使用外部参照归档图形(装订)”。

绑定外部参照定义

本示例附着一个外部参照,然后将该外部参照绑定到绘图。此示例使用在示例目录中找到的外部立面.dwg文件。如果没有此映像,或者它位于其他目录中,请插入有效的路径和文件名。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

<CommandMethod("BindingExternalReference")> _
Public Sub BindingExternalReference()
    ' Get the current database and start a transaction
    Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database
    acCurDb = Application.DocumentManager.MdiActiveDocument.Database

    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
        ' Create a reference to a DWG file
        Dim PathName As String = "C:\AutoCAD\Sample\Sheet Sets\Architectural\Res\Exterior Elevations.dwg"
        Dim acXrefId As ObjectId = acCurDb.AttachXref(PathName, "Exterior Elevations")

        ' If a valid reference is created then continue
        If Not acXrefId.IsNull Then
            ' Attach the DWG reference to the current space
            Dim insPt As New Point3d(1, 1, 0)
            Using acBlkRef As New BlockReference(insPt, acXrefId)

                Dim acBlkTblRec As BlockTableRecord
                acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite)

                acBlkTblRec.AppendEntity(acBlkRef)
                acTrans.AddNewlyCreatedDBObject(acBlkRef, True)
            End Using

            MsgBox("The external reference is attached.")

            Using acXrefIdCol As New ObjectIdCollection
                acXrefIdCol.Add(acXrefId)
 
                acCurDb.BindXrefs(acXrefIdCol, False)
            End Using

            MsgBox("The external reference is bound.")
        End If

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

        ' Dispose of the transaction
    End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

[CommandMethod("BindingExternalReference")]
public void BindingExternalReference()
{
    // Get the current database and start a transaction
    Database acCurDb;
    acCurDb = Application.DocumentManager.MdiActiveDocument.Database;

    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Create a reference to a DWG file
        string PathName = "C:\\AutoCAD\\Sample\\Sheet Sets\\Architectural\\Res\\Exterior Elevations.dwg";
        ObjectId acXrefId = acCurDb.AttachXref(PathName, "Exterior Elevations");

        // If a valid reference is created then continue
        if (!acXrefId.IsNull)
        {
            // Attach the DWG reference to the current space
            Point3d insPt = new Point3d(1, 1, 0);
            using (BlockReference acBlkRef = new BlockReference(insPt, acXrefId))
            {
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                acBlkTblRec.AppendEntity(acBlkRef);
                acTrans.AddNewlyCreatedDBObject(acBlkRef, true);
            }

            Application.ShowAlertDialog("The external reference is attached.");

            using (ObjectIdCollection acXrefIdCol = new ObjectIdCollection())
            {
                acXrefIdCol.Add(acXrefId);

                acCurDb.BindXrefs(acXrefIdCol, false);
            }

            Application.ShowAlertDialog("The external reference is bound.");
        }

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

        // Dispose of the transaction
    }
}

VBA/ActiveX 代码参考

Sub BindingExternalReference()
    ' Define external reference to be inserted
    Dim xrefInserted As AcadExternalReference
    Dim insertionPnt(0 To 2) As Double
    Dim PathName As String
    insertionPnt(0) = 1
    insertionPnt(1) = 1
    insertionPnt(2) = 0
    PathName = "C:\AutoCAD\Sample\Sheet Sets\Architectural\Res\Exterior Elevations.dwg"
 
    ' Add the external reference
    Set xrefInserted = ThisDrawing.ActiveLayout.Block. _
        AttachExternalReference(PathName, "Exterior Elevations", insertionPnt, 1, 1, 1, 0, False)
    MsgBox "The external reference is attached."
 
    ' Bind the external reference definition
    ThisDrawing.Blocks.Item(xrefInserted.name).Bind False
    MsgBox "The external reference is bound."
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部