外部参照不绑定,请大侠看看,哪里有错,Vs2015,CAD2016
想绑定个外部参照为块,始终搞不定,哪位大侠帮我看看代码using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace XrefBind
{
public class class1
{
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:\\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, 0, 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);
Application.ShowAlertDialog(acXrefIdCol.Count.ToString());
acCurDb.BindXrefs(acXrefIdCol, false);//这行代码有没有都是一样
}
//acTrans.Commit();
Application.ShowAlertDialog("The external reference is bound.外部引用被绑定");
}
// Save the new objects to the database
acTrans.Commit();
// Dispose of the transaction
}
}
}
}
自己顶一个
页:
[1]