明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2418|回复: 3

[基础] 求帮忙,块参照以及属性的问题,对新手来说是大瓶颈了,后面无法继续。

[复制链接]
发表于 2015-4-30 13:44 | 显示全部楼层 |阅读模式
7明经币
所有家当只有7个明经币,不好意思有点少。
基本问题跟基本代码在这个帖子里,http://bbs.mjtd.com/thread-113607-1-1.html
麻烦大家了 另外附上图片,方便理解。主要就做成下面两张图的样子
第一个图片,就是添加块引用的时候输入名称输入编号 显示的,中间用条线分隔开 线中间的点 作为块的基点
第二个图片,就是另外添加的块属性,用另一个命令添加。(如果有没说清楚的地方,请问我谢谢)

谢谢帮忙,分太少了~ 希望大神可以帮忙 。

附件: 您需要 登录 才可以下载或查看,没有账号?注册
发表于 2015-4-30 17:12 | 显示全部楼层
回复

使用道具 举报

发表于 2015-5-1 11:43 | 显示全部楼层
foreach (ObjectId id in block)
                {
                    if (id.ObjectClass.Equals(RXClass.GetClass(typeof(AttributeDefinition))))
                    {
                        AttributeDefinition ad = trans.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
                        AttributeReference ar = new AttributeReference(ad.Position, ad.TextString, ad.Tag, new ObjectId());
                        ar.SetAttributeFromBlock(ad, br.BlockTransform);
                        br.AttributeCollection.AppendAttribute(ar);
                        trans.AddNewlyCreatedDBObject(ar, true);
                    }
                }
回复

使用道具 举报

 楼主| 发表于 2015-5-11 14:12 | 显示全部楼层
     public ObjectId MakeDoor()
        {
            
            ObjectId blockId;
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Point3d pt1 = Point3d.Origin;
                Line bottomLine = new Line(pt1, pt1.PolarPoint(0, 0.3));
                Line bottomLine1 = new Line(pt1,pt1.PolarPoint(0,-0.3));
                blockId = db.AddBlockTableRecord("DOOR", bottomLine, bottomLine1);
                trans.Commit();
            }
            return blockId;
        }
        AttributeDefinition attHeight;
        AttributeDefinition attStyle;
        public void AddDoor()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId blockId = MakeDoor();//创建表示门的DOOR块定义
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //表示门符号的属性定义
                AttributeDefinition attSYM = new AttributeDefinition(Point3d.Origin, "1", "CBR", "输入门的符号", ObjectId.Null);
                //设置属性定义的通用样式
                SetStyleForAtt(attSYM, false);
                //设置属性的对齐点
                attSYM.AlignmentPoint = new Point3d(0.0, 0.15, 0.0);
                //表示门宽度的属性定义
                AttributeDefinition attWidth = new AttributeDefinition(Point3d.Origin, "1m", "DKSBM", "输入门的宽度", ObjectId.Null);
                SetStyleForAtt(attWidth, false);
                attWidth.AlignmentPoint = new Point3d(0.0, -0.15, 0.0);
                //表示门高度的属性定义
                attHeight = new AttributeDefinition(Point3d.Origin, "2m", "DKMC", "输入门的高度", ObjectId.Null);
                SetStyleForAtt(attHeight, false );
                attHeight.AlignmentPoint = new Point3d(0.0, 0.35, 0.0);
               // attHeight.Visible = false;
                //表示门宽式样的属性定义
                attStyle = new AttributeDefinition(Point3d.Origin, "TWO PANEL", "AREA", "输入门的式样", ObjectId.Null);
               SetStyleForAtt(attStyle, false );
               attStyle.AlignmentPoint = new Point3d(0.7, 0.0, 0.0);
                blockId.AddAttsToBlock(attSYM, attWidth, attHeight,attStyle);
                trans.Commit();
            }
        }

        private void SetStyleForAtt(AttributeDefinition att, bool invisible)
        {
            att.Height = 0.15;//属性文字的高度
            //属性文字的水平对齐方式为居中
            att.HorizontalMode = TextHorizontalMode.TextCenter;
            //属性文字的垂直对齐方式为居中
            att.VerticalMode = TextVerticalMode.TextVerticalMid;
            att.Invisible = invisible; //属性文字的可见性
        }

        [CommandMethod("InsertDkbs")]
        public void InsertDkbs()
        {
            ObjectId id = MakeDoor();
            AddDoor();
            //adKzsx(id);
            Point3d pt = Pick1("\n指定位置");
            Line li = new Line(pt, new Point3d(0, 0, 0));
            String cbf = GetString("\n名字");
            String dksbm = GetString("\n编号");

            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId spaceId = db.CurrentSpaceId;//获取当前空间(模型空间或图纸空间)
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //表示属性的字典对象
                Dictionary<string, string> atts = new Dictionary<string, string>();
                atts.Add("CBR", cbf);
                atts.Add("DKSBM", dksbm);
                atts.Add("DKMC", "");
                atts.Add("AREA", "");
                //在当前空间加入块参照
                ObjectId obj = spaceId.InsertBlockReference("0", "DOOR", pt, new Scale3d(2), 0, atts);
                adKzsx(obj);
                trans.Commit();
            }
        }
        [CommandMethod("addeDKMC")]
        public void addeDKMC()
        {
            string dkmc;
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //提示用户选择要更新的块
            PromptEntityOptions opt = new PromptEntityOptions("请选择一个块参数");
            opt.SetRejectMessage("你选择的不是块");
            opt.AddAllowedClass(typeof(BlockReference), true);
            PromptEntityResult result = ed.GetEntity(opt);
            if (result.Status != PromptStatus.OK) return;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
               ObjectId obj =  result.ObjectId;
               Entity ent = null;
               ent = (Entity)trans.GetObject(obj, OpenMode.ForRead);
               ResultBuffer resBuf5 = ent.GetXDataForApplication("DKMC");
               
               if (resBuf5 != null)
               {
                   System.Collections.IEnumerator iter = resBuf5.GetEnumerator();
                   while (iter.MoveNext())
                   {
                       TypedValue tmpVal = (TypedValue)iter.Current;
                       dkmc = tmpVal.Value.ToString();
                       Dictionary<string, string> atts = new Dictionary<string, string>();
                       atts.Add("DKMC", dkmc);
                       result.ObjectId.UpdateAttributesInBlock(atts);
                   }
               }
                trans.Commit();
            }
        }
        [CommandMethod("addeArea")]
        public void addeArea()
        {
            string area;
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //提示用户选择要更新的块
            PromptEntityOptions opt = new PromptEntityOptions("请选择一个块参数");
            opt.SetRejectMessage("你选择的不是块");
            opt.AddAllowedClass(typeof(BlockReference), true);
            PromptEntityResult result = ed.GetEntity(opt);
            if (result.Status != PromptStatus.OK) return;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                ObjectId obj = result.ObjectId;
                Entity ent = null;
                ent = (Entity)trans.GetObject(obj, OpenMode.ForRead);
                ResultBuffer resBuf7 = ent.GetXDataForApplication("Area");
                if (resBuf7 != null)
                {
                    System.Collections.IEnumerator iter = resBuf7.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        TypedValue tmpVal = (TypedValue)iter.Current;
                        area = tmpVal.Value.ToString();
                        Dictionary<string, string> atts = new Dictionary<string, string>();
                        atts.Add("AREA", area );
                        result.ObjectId.UpdateAttributesInBlock(atts);
                    }
                }
                trans.Commit();
            }
        }

群里的大哥帮忙发的菜鸟的代码,根据这代码改好了。可以实现这些功能了,要用到菜鸟书里的DotNetARX.dll,我已经买了他的书了,很好狠强大,
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-5 00:14 , Processed in 0.248827 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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