附着外部参照会将一个图形(参照文件或外部参照)链接到当前图形。当图形参照外部参照时,AutoCAD 仅将外部参照定义附着到图形,这与常规块不同,常规块定义和块的内容与当前图形一起存储。AutoCAD 读取参照图形以确定要在当前图形中显示的内容。如果参照文件丢失或损坏,则其数据不会显示在当前图形中。每次打开图形时,AutoCAD 都会从参照文件中加载所有图形和非图形(如图层、线型和文本样式)对象。如果 VISRETAIN 系统变量处于打开状态,AutoCAD 将存储当前图形中任何更新的外部参照相关图层信息。 您可以根据需要附加任意数量的外部参照副本,并且每个副本可以具有不同的位置、比例和旋转。您还可以控制在外部参照中定义的从属图层和线型属性。 若要附加外部参照,请使用以下方法。此方法要求输入要参照的图形的路径和文件名,以及当前图形中使用的外部参照的名称。该方法返回新创建的对象。返回的对象用于创建新对象并定义其在图形中的位置。创建对象后,您可以调整其旋转和缩放。AttachXrefAttachXrefObjectIdObjectIdBlockReferenceBlockReference 有关附着外部参照的详细信息,请参阅产品帮助系统中的“关于附着和分离参照图形(外部参照)”。 将外部参照附着到绘图本示例显示添加外部参照之前和之后当前图形中的所有块。此示例使用在 Sample 目录中找到的 Exterior Elevations.dwg 文件。如果此文件不可用,或者它位于其他目录中,请插入有效的路径和文件名。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry <CommandMethod("AttachingExternalReference")> _ Public Sub AttachingExternalReference() ' 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 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("AttachingExternalReference")] public void AttachingExternalReference() { // 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); } } // Save the new objects to the database acTrans.Commit(); // Dispose of the transaction } } VBA/ActiveX 代码参考Sub AttachingExternalReference() Dim InsertPoint(0 To 2) As Double Dim insertedBlock As AcadExternalReference Dim PathName As String ' Define external reference to be inserted InsertPoint(0) = 1 InsertPoint(1) = 1 InsertPoint(2) = 0 PathName = "C:\AutoCAD\Sample\Sheet Sets\Architectural\Res\Exterior Elevations.dwg" ' Add the external reference to the drawing Set insertedBlock = ThisDrawing.ActiveLayout.Block. _ AttachExternalReference(PathName, "Exterior Elevations", InsertPoint, 1, 1, 1, 0, False) End Sub 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:44
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.