绑定外部参照 (.NET)
使用 Bind 方法将外部参照绑定到图形将使外部参照成为图形的永久部分,而不再是外部参照文件。外部引用的信息将成为一个块。更新外部参照图形时,不会更新绑定的外部参照。此过程将绑定整个图形的数据库,包括其所有从属符号。 从属符号是命名对象,例如块、尺寸样式、图层、线型和文本样式。绑定外部参照允许在当前图形中使用外部参照中的命名对象。 该方法需要两个参数:(ObjectID 的集合)和 (boolean)。如果参数设置为 True,则外部参照图形的符号名称在当前图形中以 <blockname>$x$ 为前缀,其中 x 是自动递增以避免覆盖现有块定义的整数。如果参数设置为 ,则外部参照图形的符号名称将合并到不带前缀的当前图形中。如果存在重复名称,AutoCAD 将使用本地图形中已定义的符号。如果不确定图形是否包含重复的符号名称,建议设置为 。BindXrefxrefIdsinsertBindinsertBindinsertBindFalseinsertBindTrue 有关装订外部参照的详细信息,请参见产品帮助系统中的“关于使用外部参照存档图形(装订)”。 绑定外部参照定义本示例附着外部参照,然后将外部参照绑定到图形。此示例使用在 Sample 目录中找到的 Exterior Elevations.dwg 文件。如果您没有此映像,或者它位于其他目录中,请插入有效的路径和文件名。 VB.NETImports 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 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2024-12-15 22:26
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.