直接获取没法得,通过间接临时事务生成模型得到
public static string GetBlockReferenceName(ImportInstance importInstance, Reference reference)
{
var doc = RvtApp.Document;
string name = null;
GeometryObject go = importInstance.GetGeometryObjectFromReference(reference);
using (TransactionGroup tg = new TransactionGroup(doc))
{
tg.Start("Temp Trans");
DirectShape ds = null;
using (Transaction trans = new Transaction(doc))
{
trans.Start("Temp DirectShape");
ds = DirectShape.CreateElement(doc,
new ElementId(BuiltInCategory.OST_GenericModel), Guid.NewGuid().ToString(),
Guid.NewGuid().ToString());
ds.AppendShape(new List<GeometryObject>() { go });
trans.Commit();
}
Options options = new Options
{
ComputeReferences = true,
View = doc.ActiveView
};
var gi = ds.get_Geometry(options).FirstOrDefault(i => i is GeometryInstance) as GeometryInstance;
name = gi?.Symbol?.Name;
tg.RollBack();
}
return name;
}