明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: lzx838

[翔麟专集] [原创]翔麟专集——读取Excel数据在CAD上展图

  [复制链接]
发表于 2013-3-7 09:21 | 显示全部楼层
厉害厉害,向你学习
发表于 2013-11-8 19:23 | 显示全部楼层
正需要类似的代码呢,谢谢啦
发表于 2014-1-9 10:03 | 显示全部楼层
好是好,就是不知到该怎么加载使用啊,vb咱又不懂。。。。。。。悲催
发表于 2014-3-25 21:54 | 显示全部楼层
牛叉,很厉害,先下了!
发表于 2014-3-26 09:49 | 显示全部楼层
好东西不会用!怎么办!
发表于 2014-3-26 21:09 | 显示全部楼层
感谢楼主分享!
发表于 2014-4-19 23:28 | 显示全部楼层
感谢分享,学习了,正想做一个类似的工具
发表于 2014-6-10 08:37 | 显示全部楼层
想问您一下,我把这个插入函数改成返回ObjectID的函数后,那么在WHILE循环里面使用
ObjectId Id1=createEntity.InsertBlockRefWithAtt(strBlockName1, pt, new Scale3d(1), 0, read.GetString(0), douSD); 得到的Id1是不是同一个值,因为我想得到每次插入在图纸上块的ObjectID
/// <summary>
        /// 插入一个带属性的块
        /// </summary>
        /// <param name="blockName">图块名称</param>
        /// <param name="point">插入点</param>
        /// <param name="scale">图块比例</param>
        /// <param name="rotateAngle">图块旋转角度</param>
        /// <param name="KHstring">属性值:孔号</param>
        /// <param name="KSdouble">属性值:孔深</param>
        /// <remarks></remarks>
        public ObjectId InsertBlockRefWithAtt(string blockName, Point3d point, Scale3d scale, double rotateAngle, string KHstring, double KSdouble)
        {
            ObjectId blockRefId;
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                if (!bt.Has(blockName))
                {
                    return ObjectId.Null;
                }
                BlockTableRecord blockwithatt = (BlockTableRecord)trans.GetObject(bt[blockName], OpenMode.ForRead);
                BlockReference blockRef = new BlockReference(point, bt[blockName]);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                blockRef.ScaleFactors = scale;
                blockRef.Rotation = rotateAngle;
                blockRefId = btr.AppendEntity(blockRef);
                trans.AddNewlyCreatedDBObject(blockRef, true);
                //获取blockName块的遍历器,以实现对块中对象的访问
                BlockTableRecordEnumerator iterator = blockwithatt.GetEnumerator();
                //如果blockName块包含属性
                if (blockwithatt.HasAttributeDefinitions)
                {
                    //利用块遍历器对块中的对象进行遍历
                    while (iterator.MoveNext())
                    {
                        //获取块遍历器当前指向的块中的对象
                        AttributeDefinition attdef = trans.GetObject(iterator.Current, OpenMode.ForRead) as AttributeDefinition;
                        //定义一个新的属性参照对象
                        AttributeReference att = new AttributeReference();
                        //判断块遍历器当前指向的块中的对象是否为属性定义
                        if (attdef != null)
                        {
                            //从属性定义对象中继承相关的属性到属性参照对象中
                            att.SetAttributeFromBlock(attdef, blockRef.BlockTransform);
                            //设置属性参照对象的位置为属性定义的位置+块参照的位置
                            att.Position = attdef.Position + blockRef.Position.GetAsVector();
                            //判断属性定义的名称
                            switch (attdef.Tag)
                            {
                                //设置块参照的属性值
                                case "孔号":
                                    att.TextString = KHstring;
                                    break;
                                case "孔深":
                                    att.TextString = KSdouble.ToString();
                                    break;
                            }

                            //判断块参照是否可写,如不可写,则切换为可写状态
                            if (!blockRef.IsWriteEnabled)
                            {
                                blockRef.UpgradeOpen();
                            }
                            //添加新创建的属性参照
                            blockRef.AttributeCollection.AppendAttribute(att);
                            //通知事务处理添加新创建的属性参照
                            trans.AddNewlyCreatedDBObject(att, true);
                        }
                    }
                }
                trans.Commit();//提交事务处理
            }
            return blockRefId;
        }
发表于 2014-6-11 08:33 | 显示全部楼层
学习交流了,谢谢楼主了。
发表于 2014-7-30 07:32 | 显示全部楼层
谢谢两位无私的提供资料!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-25 21:11 , Processed in 0.454048 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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