Reloading a Definition
-
I found out I can not load a Definition if a Definition already exists in the model that has the same path as the one I want to load. (Which is a reload, I guess.)
Has anyone done a work-around for this?
-
@jim said:
I found out I can not load a Definition if a Definition there already exists in the model that has the same path as the one I want to load. (Which is a reload, I guess.)
Has anyone done a work-around for this?To reuse an example, I assume you are using something like...
model=Sketchup.active_model # First, load our pants. We'll search for the file inside the Components folder. pants_path = Sketchup.find_support_file "pants.skp" ,"Components" ### *** pants_def = model.definitions.load(pants_path) # Then define a location, and place our pants there. pants_location = Geom;;Point3d.new(100,200,0) tr = Geom;;Transformation.new(pants_location) instance = model.active_entities.add_instance(pants_def, tr)
If it's not updating the pre-loaded file with the same name then at *** you can test all files for that path
defs=[] model.definitions.each{|d|defs<< d if d.path=pants_path} defs.each{|defn| defn.name=defn.name+"#1" model.definitions.unique_name(defn.name) }
Now when you load the file it's name is 'free' ?
If that doesn't work try this - use the defs list, try inserting an instance of defn (inst), then use inst.make_unique, then get the df=instance.definition, delete the instance inst.erase!; set the old definition to the new unique definition defn.instances{|ins|inst.definition=df}; remove the offending defn by erasing all of its entities inside a start/commit loop so it goes from the browser too... -
I got the impression that the name was not the issue, but the path.
-
Well the second section tries to remove the definition of the original so you can upload again - the 'make_unique' should remove the path...
-
@thomthom said:
I got the impression that the name was not the issue, but the path.
Right. loading a definition with the same path returns the in-model definition with the same path, and does not re-load it from disk. The name is not important, but it is the path that matters. If I save_as the definition to a new path, then load will work on the original path, and the new definition's name will be incremented.
I wanted to avoid saving the old definition to a disk file and all the mess that goes along with that - such as finding/creating a folder to save it to and cleaning it up afterward.
What I found is I can
cdef.save_as("/dev/null")
which will reset the path, but not actually create a file on disk. Then I am free to load the definition again - a re-load, although the definition name is incremented.This apparently works on Windows as well as Mac even though Windows does not have a /dev/null file. Perhaps Ruby just knows how to deal with it.
Can anyone confirm this does not create a file on disk on either Windows or Mac?
Advertisement