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?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement