Revit secondary development tips (four) read the information stored in the extension

The last time I shared how to add extended storage to the component, this time I will teach you how to read the data we saved.
The GUID code used here and the name of the read data need to be the same as when you saved it.
The entire code is as follows:

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;
        }

The display effect is as follows: The
Insert picture description here
above is the use of extended storage. The types of stored files are not unique. You can research other types of storage yourself, or you can directly contact me by private message if you need it. I hope this sharing is helpful to you, thank you

Guess you like

Origin blog.csdn.net/Oneal5354/article/details/107895408