明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 714|回复: 1

外部参照不绑定,请大侠看看,哪里有错,Vs2015,CAD2016

[复制链接]
发表于 2018-1-1 17:28 | 显示全部楼层 |阅读模式
想绑定个外部参照为块,始终搞不定,哪位大侠帮我看看代码

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
            }
    }
    }
}

 楼主| 发表于 2018-2-3 16:23 | 显示全部楼层
自己顶一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 08:49 , Processed in 0.218350 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表