Deleting Component Definition

Deleting Component Definition

Postby ktkoh » Wed Dec 06, 2017 5:48 pm

I have not been able to delete a component definition

Code: Select all
flatPanel = ent.add_group
fp_face = flatPanel.entities.add_face (@pt)
fp_face.pushpull(-fp_T)
component_instance = flatPanel.to_component
component_instance.definition.name = ("FlatPanel")
component_instance.layer = "NewPanel"
def_Panel = component_instance.definition
UI.messagebox("Panel Definition Name " + def_Panel.to_s + "component_instance " + component_instance.to_s  )
component_instance.erase!
def_Panel.clear!


I create this panel and can delete the instance but the cannot delete the definition. The message box shows values for both the instance and definition. Run fails with error " Cannot determine parent of entity" When I comment out the last line the code runs and deletes the component instance.

Keith
0

ktkoh 
PluginStore Author
PluginStore Author
 

Re: Deleting Component Definition

Postby Dan Rathbun » Fri Dec 08, 2017 5:02 am

def_Panel = component_instance.definition
def_Panel.clear!


There is no method named "clear!" for the Sketchup::ComponentDefinition class, nor inherited from any of it's ancestor classes. (You are confusing the Entities#clear! method, which only acts upon instance objects within a definition's [or the model's] entities collection.)

There was never a specific method to delete a certain definition, before the version 2018 API.
See Sketchup::DefinitionList#remove(), which will also remove all instances of the definition argument as well as the definition object.

In older versions the only workaround is to do a purge_unused upon the Sketchup::DefinitionList collection as a whole. This sometimes can result in the deletion of wanted components (perhaps used by other plugins, but not yet having instances in the model.)
If you must do the purge, try to save up the names and paths of all the other unused components, and reload them after you do the purge that results in removing your definition.
The danger with this workaround is that you will also be purging "internal components" which are sets of geometry the user has created but not yet saved out to a component SKP file.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Deleting Component Definition

    Postby ktkoh » Fri Dec 08, 2017 3:49 pm

    Thanks Dan for the explaination. I had tried other terms than clear that was just the last version. I will let the user take care of deleting the old panel def if they need to remake the same panel. The neW panel will automatcaly get the new #diget Sketchup adds to components with the same name. Now I know why I couldnt delete def. Never saw the purge unused.

    THANKS AGAIN ans. with exp are very helpful.
    Keith
    1

    ktkoh 
    PluginStore Author
    PluginStore Author
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: No registered users and 6 guests

    Visit our sponsors: