Load definition from file will lost information

If load a definition from the file, information like description and dynamic attributes will be lost. Anyone knows how to get those information with definition?

d = Sketchup.active_model.definitions.load('model.skp')
d.description # => nil

Component definitions do not have a description, by default. Are you sure you set it before?
Dynamic attributes should be there too…

Attach the model.skp file then someone can check what could be the problem.


BTW. there is no version 21 of SketchUp Make (desktop) as your profile stating.

:bulb: :thinking: Thinking further, it occurred to me that your model.skp file might contain a double wrapped version of dynamic component.

I meant, if you are created a dynamic component, let say “cube” inside your model file, then you were saved a model.skp. Loading this model.skp later will not be a dynamic component, but double wrapped component.

To properly save the dynamic component for future load, right click on the “cube” component and choose to “save as…” >> cube.skp, then load this cube.skp later.

2 Likes

Thanks for your reply. Yes, this is the reason why I can’t get the information of the definition, and it worked after saving the definition with your method.

But in this way, it seems a little tricky to modify the description of the definition since I need to open the skp file, choose the entity, make it as a component, add the description and save as another file.

If you are opening the cube.skp as individual file it will contains individual entities, its description will became as model description (Sketchup.active_model.description) its dynamic_attributes will became as model attributes ( Sketchup.active_model.attribute_dictionaries['dynamic_attributes'] )

if you

You will make an other component and this will ‘not get’ the dynamic_attributes.

You have to modify the model description (and optionally the model dynamic_attributes) and save the file and this file you can drag&drop or “load” to other model to use as dynamic component.

BUT
If you are loading the cube.skp to an already opened model:
you can get and change the description

d = Sketchup.active_model.definitions.load('c:\\cube.skp')
d.description # => "old description"
d.description = "new description" # => "new description"

Then you can #save_as it to other (or to the same file):

success = d.save_as( "c:\\cube_new.skp" )
#or:
#success = d.save_as( "c:\\cube.skp" )

You can get its dynamic_attributes too

da = d.attribute_dictionaries['dynamic_attributes']
4 Likes

I see…
Thanks again, it really helped me a lot!

1 Like