简体   繁体   中英

Is it possible to keep a variable active with Revit Python Shell, using canned commands?

I'm currently using Revit Python Shell 2017 and I'd like let's say to make "communicate" different canned commands.
For instance, let's say I load a house model, and I create some additional walls on it, via a canned command that I would have previously created. While creating these walls, I could store all these new walls IDs in a variable, as a list.

Now, if I want to delete exactly these walls afterwards, I'd like to identify them using their IDs that I stored in the list, then delete them.
If I was in an interactive Python Shell session, well the "IDs list" variable would still be accessible (as long as I don't close the shell), and I could just retrieve the IDs from it, then delete the walls.
But what if I'm using canned commands? The first command would be "create the walls", and the 2nd would be "erase these walls". But that "IDs list" variable doesn't exists in the second canned command environment, so that I can't use it to erase the walls.

So, what would be the approach? Of course in this example I could identify the walls in the second command using a different methodology, such as asking the user to select them etc etc.. But the idea I'm going for would be the store that list from the first command "somewhere in Revit", and retrieve it when calling the second command.

I could write the list to an external text file, and read the file in the second command... but is there a cleaner way?

I'm sorry for the beginner's language used here, and hope that my question is clear enough! And that somebody can help ;)

Best,
Arnaud.

This is a great question Arnaud, in the past Ive done the following:

Create a text project parameter, and populate it with XML (yes you can have line breaks in a text parameter). This is similar to what Ideate BIM Link does (check the project parameters of any project that has used BIM Link). This is a long-winded method for keeping data persistent between commands.

The second part (saving a walls IDs) is more difficult I think, as I understand it every time you open a project the IDs are reassigned. You could test this to see if its the case?

Another method could involve using an External command that lingers after you have finished selecting walls. Could you go into a little more info about what youre wanting to achieve?

So,

Just for leaving a trace, I solved this using pyRevit and its ability to store data in temporary files ( here , look for "Using Temporary Files").

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