如何将已有块加入到当前图纸中?
大侠们好,请问如何将已有的块加入到当前的图纸中呢,我写了一些代码,是加上来了,但是我的块本来是增强属性块,可以用增强属性编辑器打开,但是插入进来之后就只能用编辑块定义打开了,请大侠们指点,多谢!ObjectId id = ObjectId.Null;
using (Database sourceDatabase = GetDatabaseFromFile("d:\\arx\\bplead_title.dwg"))
{
id = HostApplicationServices.WorkingDatabase.Insert("BPLEAD_TITLE", sourceDatabase, true);
}
Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument;
Point3d point = new Point3d(bx, by, bz);
BlockReference br = null;
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
using (br = new BlockReference(point, id))
{
btr.AppendEntity(br);
trans.AddNewlyCreatedDBObject(br, true);
}
trans.Commit();
}
public Dictionary<AttributeDefinition, AttributeReference>
AppendAttribToBlock(BlockReference blkref, List<string> atts)
{
var blkdef = GetObject<BlockTableRecord>(blkref.BlockTableRecord);
int i = 0;
if (blkdef.HasAttributeDefinitions)
{
var attribs =
new Dictionary<AttributeDefinition, AttributeReference>();
foreach (var attdef in blkdef.GetEntities<AttributeDefinition>())
{
if (attdef.Constant || attdef.Invisible)
break;
AttributeReference attref = new AttributeReference();
attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
if (i < atts.Count)
attref.TextString = atts;
else
attref.TextString = attdef.TextString;
i++;
blkref.AttributeCollection.AppendAttribute(attref);
Transaction.AddNewlyCreatedDBObject(attref, true);
attribs.Add(attdef, attref);
}
return attribs;
}
return null;
}
<p>先收藏,后续学习。。。</p>
<p> </p>
页:
[1]