Help with componentdefinition=definitions.load name
-
I have a file "filename.skp" that I would like to load in my model as a definition.
-
@honoluludesktop said:
How do I use the method in the situation above that failed.
I'm guessing you're not specifying an absolute path to the .skp file? Ensure you have given the full path to the file so SU doesn't have to guess where it is.
-
@honoluludesktop said:
I am having problems understanding using the method
load
incomponentdefinition=definitions.load name
wherename
is "filename.skp".@honoluludesktop said:
When I run SU by clicking on a "filename.skp", the above creates a definition from the "filename.skp",
It should not be using the method above, in this situation, SU should be using Sketchup.open_file
You have a definition in the file you clicked on, because the file ALREADY had a definition in it before it was saved.@honoluludesktop said:
but when I start SU, then select a file from another folder, the definition fails to be created.
SU is still using Sketchup.open_file
Because there is no component IN the saved file, just simple geometry entities.@honoluludesktop said:
However when I start SU, then open a "filename.skp" in the folder that includes the shortcut to SU, a definition is created.
I would think the definition, IN the file, was ALREADY created before the file was saved.
-
BTW, if you drag and drop a skp (that has NO saved definition within it,) from the File Explorer, into the Sketchup model space, it gets imported AND converted to a definition "on-the-fly".
The question would follow, what happens to a drag and drop, when the file DOES have a component? Is it nested?
Answer YES. -
@thomthom said:
@honoluludesktop said:
How do I use the method in the situation above that failed.
I'm guessing you're not specifying an absolute path to the .skp file? Ensure you have given the full path to the file so SU doesn't have to guess where it is.
I tried specifying an absolute path to the .skp file, but that failed.
Dan, I am still reading your post.
-
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