Bind メソッドを使用して外部参照を図面にバインドすると、外部参照は図面の永久的な部分となり、外部参照ファイルではなくなります。 外部参照情報はブロックになります。外部参照図面が更新されても、バインドした外部参照は更新されません。この処理により、従属する全シンボルを含む図面のデータベース全体がバインドされます。
従属するシンボルとは、ブロック、寸法スタイル、画層、線種、および文字スタイルなどの、名前の付いたオブジェクトです。外部参照をバインドすると、外部参照からの名前の付いたオブジェクトが現在の図面で使用できるようになります。
BindXref メソッドでは 2 つのパラメータ xrefId (ObjectID のコレクション)と insertBind (ブール値)が必要です。insertBind パラメータを True に設定すると、外部参照図面のシンボル名の先頭に <blockname>$x$ が付きます。x は、既存のブロック定義への上書きを避けるために自動的にインクリメントされる整数です。insertBind パラメータを False に設定すると、外部参照図面のシンボル名は、接頭語なしで現在の図面に結合されます。重複する名前が存在する場合は、AutoCAD ではローカル図面内で既に定義されているシンボルが使用されます。図面に重複するシンボル名が存在するかどうか不明な場合は、insertBind を True に設定することをお勧めします。
外部参照のバインドの詳細については、製品のヘルプ システムで「概要 - 外部参照を含む図面をアーカイブ(バインド)する」を参照してください。
次の例では、外部参照をアタッチしてから図面にバインドします。この例では、Sample フォルダにある Exterior Elevations.dwg ファイルを使用します。このイメージが存在しない場合や、別のフォルダにある場合は、有効なパスおよびファイル名を指定してください。
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
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
}
}
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