前回、コンポーネントに拡張ストレージを追加する方法を共有しましたが、今回は、保存したデータの読み取り方法を説明します。
ここで使用するGUIDコードと読み取ったデータの名前は、保存したときと同じである必要があります。
全体のコードは次のとおりです。
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
var temp = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
Wall el = doc.GetElement(temp) as Wall;
string result = GetSchema(el, "40A901FC-A0F4-4653-ABC3-CC1140391ADB", "我是测试名称");
MessageBox.Show(result);
return Result.Succeeded;
}
public string GetSchema(Wall wall, string guid, string name)
{
string data;
Schema schema = Schema.Lookup(new Guid(guid));
Entity entity = wall.GetEntity(schema);
data = entity.Get<string>(schema.GetField(name));
return data;
}
表示効果は次のとおりです。
上記は拡張ストレージの使用です。保存されているファイルの種類は一意ではありません。他の種類のストレージを自分で調べることも、必要に応じてプライベートメッセージで直接私に連絡することもできます。この共有がお役に立てば幸いです。ありがとうございます