- 积分
- 117
- 明经币
- 个
- 注册时间
- 2017-12-30
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
想绑定个外部参照为块,始终搞不定,哪位大侠帮我看看代码
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace XrefBind
{
public class class1
{
[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:\\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
}
}
}
}
|
|