sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Reloading a Definition

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 471 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      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?

      Hi

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        @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... πŸ˜•

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          I got the impression that the name was not the issue, but the path.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Well the second section tries to remove the definition of the original so you can upload again - the 'make_unique' should remove the path...

            TIG

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              @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?

              Hi

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement