Help with componentdefinition=definitions.load name
-
OK, let me try to explain better.
1a. I open SU, either by selecting a .skp, or 1b. the SU shortcut (then open a .skp from a folder that the SU plugin is not in).
2. I add a new .skp into the model as a component.Where
name
is not the absolute path name,componentdefinition=definitions.load name
creates a definition of the new .skp in the model in the case of 1a, but not 1b. Whenname
is the absolute path name, both 1a, and 1b. fail.I realize that not using the absolute path name seems wrong, but it worked, where using the absolute path name failed.
-
What this seems to be telling me, is that
componentdefinition=definitions.load name
works when the active SU::Model folder is the same as the new .skp file. Or, I am somehow not getting the correct absolute file name. My code is:dir_name=File.dirname(model.path) name=dir_name+"\\"+filename+".skp"
I have checked the result by
puts name
, and it looks OK. -
I don't think a Definition will load if a definition already exists with the same path. Is this what's happening?
-
-
Maybe, how do I check? How do I delete an existing definition?
-
@jim said:
Related?
You posted while I was posting.:-) Went to viewtopic, but some of the discussion is "over my head". How do I
cdef.save_as("/dev/null")
? is "/dev/null", my "dive:/pathname/null"? Iscdef
the existing cdef, or the new cdef? -
More precicely:
- I saved the transformations of a set of components.
- Then deleted the components from the model.
- Created a new definition from a new .skp.
- Created components with the new definition and the saved transformations.
This
cnt_instance.definition.save_as(File.dirname(model.path)+"\\null")
returned, Error: #<TypeError: reference to deleted ComponentInstance>, where cht_instance is the deleted component.I also tried
definitions.purge_unused
without success. -
@honoluludesktop said:
More precicely:
- I saved the transformations of a set of components.
- Then deleted the components from the model.
- Created a new definition from a new .skp.
- Created components with the new definition and the saved transformations.
This
cnt_instance.definition.save_as(File.dirname(model.path)+"\\null")
returned, Error: #<TypeError: reference to deleted ComponentInstance>, where cht_instance is the deleted component.I also tried
definitions.purge_unused
without success.Try switching steps 2 and 3. Once you delete the component referring to it will throw the error you're getting. If you require a reference to the instance in order to property do step 4, then add the new components to the model first and delete the old components afterwards.
-
Cleverbeans, Thanks, but didn't work.
-
Well, I completed my program, and did it by not using a path. It's my guess that SU keeps track of where SU is, so if you:
- Save a component to file as name.skp.
- Edit the saved file. (this is the function of the plugin)
- Erase the component instances (that was saved) from the original model entities.
definitions.purge_unused
componentdefinition = definitions.load name.skp
entities.add_instance componentdefinition, each_transformation
The key to make this work is step 4. The only problem that can come about is if you require the erased components to remain in the select "Components" window.
Advertisement