Erase a single unused Definition
-
I would like to delete a specific unused Definition from a model, but all I can find is
Definitionlist#purge_all
which deleted all unused Definitions. Is there a way? -
Yes
This way erases individual component [and group] definitions rather than the heavy handedmodel.definitions.purge_all
...
Use this
model.start_operation('DeleteDefn') defn.entities.erase_entities(defn.entities.to_a) model.commit_operation
If it's within a broader 'start/commit' block then it works too...
The 'operation' is needed to refresh the Component-Browser's contents...
Warning - IF the definition has instances it will erase them all too, so check with!defn.instances[0]
, unless of course you want it to do that ! -
Thanks, TIG.
This is of course in reference to Trim and Keep Plugin.
I didn't try that specifically, but I did try using Definition.entities.clear! and got some odd behavior and a BugSplat.
Now, I'm not sure deleting the component is the "right" thing to do - I like the idea of leaving the Definition in model in case it is needed. The user can erase/purge it if and when they want.
-
The
definition.entities.clear!
should work much as my suggestion, inside the operation block?
You could always suffix its new name with "[Untrimmed]" so it's easy to spot?
You could also add a closing dialog
'Remove the now Unused Untrimmed Definition from the Browser ?', Yes|No
Then the user decides...
I have just written something very similar myself, within a broader 'commercial' tool, BUT that auto-removes the old untrimmed definition. That one gets complicated as it is say a panel component that is trimmed on one edge using special shaped instances [it's remade as a component rather than a group], a 'hidden' proxy of the original untrimmed panel is retained after the trimming is done, it is also given attributes defining what was done on that trim; then you can trim the 2nd, 3rd, 4th edges etc, each time the attributes are expanded for each edge trimmed; now the rub - the edge trimming is editable per edge, so if I want to redo the trimming to the 2nd edge I have to start with an untrimmed version again [derived from the proxy] then read the attributes that it has and repeat the 1st then the new 2nd trim and then repeat the 3rd, 4th etc. This is because trimming one edge affects the abutting other two edges... I have taken a while to get my head around it! Now you can trim parts out of all sides of the panel using various shaped 'notches' and edit them too... Now to finish the next part - these trimmed edges marry into panels meeting at right-angles and their 'notched' edges have to be the reverse of the other panels... A tangle of attribute crosschecks and a trimming frenzy ensues...
Advertisement