sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Help with componentdefinition=definitions.load name

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 5 Posters 825 Views 5 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.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      I have a file "filename.skp" that I would like to load in my model as a definition.

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

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

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

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @honoluludesktop said:

          I am having problems understanding using the method load in componentdefinition=definitions.load name where name 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.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            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.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • honoluludesktopH Offline
              honoluludesktop
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

                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. When name 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.

                1 Reply Last reply Reply Quote 0
                • honoluludesktopH Offline
                  honoluludesktop
                  last edited by

                  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.

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

                    I don't think a Definition will load if a definition already exists with the same path. Is this what's happening?

                    Hi

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

                      Related?

                      http://forums.sketchucation.com/viewtopic.php?f=180&t=28122

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • honoluludesktopH Offline
                        honoluludesktop
                        last edited by

                        Maybe, how do I check? How do I delete an existing definition?

                        1 Reply Last reply Reply Quote 0
                        • honoluludesktopH Offline
                          honoluludesktop
                          last edited by

                          @jim said:

                          Related?

                          http://forums.sketchucation.com/viewtopic.php?f=180&t=28122

                          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"? Is cdef the existing cdef, or the new cdef?

                          1 Reply Last reply Reply Quote 0
                          • honoluludesktopH Offline
                            honoluludesktop
                            last edited by

                            More precicely:

                            1. I saved the transformations of a set of components.
                            2. Then deleted the components from the model.
                            3. Created a new definition from a new .skp.
                            4. 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.

                            1 Reply Last reply Reply Quote 0
                            • C Offline
                              Cleverbeans
                              last edited by

                              @honoluludesktop said:

                              More precicely:

                              1. I saved the transformations of a set of components.
                              2. Then deleted the components from the model.
                              3. Created a new definition from a new .skp.
                              4. 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.

                              1 Reply Last reply Reply Quote 0
                              • honoluludesktopH Offline
                                honoluludesktop
                                last edited by

                                Cleverbeans, Thanks, but didn't work.

                                1 Reply Last reply Reply Quote 0
                                • honoluludesktopH Offline
                                  honoluludesktop
                                  last edited by

                                  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:

                                  1. Save a component to file as name.skp.
                                  2. Edit the saved file. (this is the function of the plugin)
                                  3. Erase the component instances (that was saved) from the original model entities.
                                  4. definitions.purge_unused
                                  5. componentdefinition = definitions.load name.skp
                                  6. 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.

                                  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