gsteven 发表于 2009-9-28 15:59:00

[求助]如何插入带属性的块参照?已解决!

/                     operBlkRec = (BlockTableRecord)operTrans.GetObject(operBlk, OpenMode.ForWrite);
                        InsertBlkRef = new BlockReference(Point3d.Origin, InsertBlkID);
                        InsertBlkRef.SetDatabaseDefaults();
                     
                        operBlkRec.AppendEntity(InsertBlkRef);
                        operTrans.AddNewlyCreatedDBObject(InsertBlkRef, true);
我的块定义是一个圆加一个属性,结果发现圆插入了,但属性没有插入,在cad中打开插入的块参照的特性,发现根本就没有属性那一栏。
还有,调试过程中发现插入后InsertBlkRef的是null。
不知道应该怎么样插入带属性定义的块参照,并且赋给块参照的属性具体的tag?
//插入快参照后还需要插入属性
                        int i = 0;
                        BlockTableRecord blkdef = (BlockTableRecord)operTrans.GetObject(InsertBlkRef.BlockTableRecord, OpenMode.ForRead);
                        foreach (ObjectId id in blkdef)
                        {
                            DBObject ent = operTrans.GetObject(id, OpenMode.ForRead);
                            if (ent is AttributeDefinition)
                            {
                              AttributeDefinition attdef = (AttributeDefinition)ent;
                              AttributeReference attref = new AttributeReference();
                              attref.SetAttributeFromBlock(attdef, InsertBlkRef.BlockTransform);
                              attref.TextString = loopInfor;
                              i++;
                              InsertBlkRef.AttributeCollection.AppendAttribute(attref);
                              operTrans.AddNewlyCreatedDBObject(attref, true);
                            }
                        }

雪山飞狐_lzh 发表于 2009-9-28 16:25:00

我的DBTransaction类有类似的函数,转帖过来吧复制代码
页: [1]
查看完整版本: [求助]如何插入带属性的块参照?已解决!