简体   繁体   中英

Revit API reopen form an keep data

I would like to make a Plugin where the user can select a source and then a target element and get all the parameters and their values.

My problem is: After I selected the source element and got all parameters and values into comboboxes I select the target (via another button). For that the form closes again and after selecting and reopening all the data from the source element is gone.

What would be a correct way to do this? At this time both buttons close the form run another ExternalEvent to select the element and collect the data.

Can I cache this data (Lists, dictionary with list, dictionary with dictionary with list) or do I have to write it to a file or is there another way?

How do I keep/remember the data I collected when a form closes an reopens?

Thank you for any help Philipp

There multiple ways of doing this I guess. It is more of a general programming rather than API issue. You basically need to keep the data in memory outside of just the WPF window.

Some options of the top of my head would be

  1. Save the data into file in temp folder and read it when needed (probably a messy solution)
  2. Create & instantiate a class with data to keep in memory and communicate it between different windows etc.
  3. Have a Static Class with appropriate property. Once selecting an element assign it to the property. This should persist within the Revit session. Static Class .

Option 3 should be the easiest to use.

Just use Properties -> Application settings to store the ID of the entity. Then on launch get the combo boxes to auto populate if the ID can be found.

External events are only required when editing the model.

This is assuming your using Visual studio and not sharp develop. If your still using sharp develop it is time to move on to a real IDE.

I think there are a few options. You could use the built in DataStorage that a revit model provides. Here, i made a datastorage entity to store a GUID for a project...

public Guid schemaGuid = new Guid("{5F374308-9C59-42AE-ACC3-A77EF45EC146}");    
public DataStorage dataStorage;
public string schemaName = "UniqueProjectId";
public DataStorage dataStorage;
public string SimpleField = "MyProjects_GUID";

public Schema CreateNewDataStorage()
            {
                Guid newProjectGuid = Guid.NewGuid();
    
                Transaction t = new Transaction(doc, "Make internal storage");
                t.Start();
                dataStorage = DataStorage.Create(doc);
                dataStorage.Name = schemaName;
                
    
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
                schemaBuilder.SetSchemaName(schemaName);
                schemaBuilder.AddSimpleField(SimpleField, typeof(Guid));
                schema = schemaBuilder.Finish();
    
                entity = new Entity(schema);
    
                entity.Set(SimpleField, newProjectGuid);
                dataStorage.SetEntity(entity);
                t.Commit();
    
                return schema;
            }

Another way would be to write to external database or text file. For something small, SQlite is easy. A temporary text file is also a very simple way to temporarily store data.

Lastly, you could use an Idling event and keep the dialogue box active.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM