乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 40|回复: 1

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

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
6
发表于 2018-1-1 17:28:00 | 显示全部楼层 |阅读模式
想绑定个外部参照为块,始终搞不定,哪位大侠帮我看看代码
using Autodesk..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
            }
    }
    }
}
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
6
发表于 2018-2-3 16:23:00 | 显示全部楼层
自己顶一个
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 02:14 , Processed in 0.400514 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表