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

    Creating Components in Cab.rb

    Scheduled Pinned Locked Moved Developers' Forum
    26 Posts 5 Posters 1.3k 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      @frankn said:

      I had already tried that and it doesn't work, the only way to get them to show up is to edit the component then the preview shows up. Not a big deal but was just curious if I was doing something wrong with the script/code.

      Oh are these YOUR components ?? (ie, NOT Google supplied components,) that your having problems with?

      See API: ComponentDefinition.refresh_thumbnail

      cdefs = Sketchup.active_model.definitions
       cdefs.each {|comp| comp.refresh_thumbnail }
      

      I'm not here much anymore.

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


        Also..

        1. open the Model Info dialog.

        2. Go to the File panel.

        3. check the "Redefine thumbnail on save" option

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • F Offline
          Frankn
          last edited by

          See API: ComponentDefinition.refresh_thumbnail

          cdefs = Sketchup.active_model.definitions
           cdefs.each {|comp| comp.refresh_thumbnail }
          

          [/quote]

          Thanks that worked perfect. πŸ˜„

          Frank

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

            @frankn said:

            I've also been looking into adding components to other components and all I found so far is some refernences to subcomponents and parent components but nowhere did I find how those work?

            ALL Sketchup::ComponentDefinition objects are kept in the model's Sketchup::DefinitionList collection. ALL of them, regardless of what level any instances ( Sketchup::ComponentInstance,) of them are inserted.
            The "level" can at the top (under the model,) or nested many levels deep beneath any combination of Group / ComponentDefinition "parents".

            The Entity.parent() method is inherited (down thru Sketchup:Drawingelement,) to all the objects that can be put into a model.

            So create all the component definitions you will use, and load them into the model.
            To nest a component into another, insert an instance of the subcomponent, into the entities collection of another component's definition.

            outer_comp_def.entities.add_instance( inner_comp_def, transform )

            .. repeat to suit (ie, you can insert multiple bolt & nut component instances, in another component definition.)

            P.S. (a Group is a "special" component, and so it also has a Sketchup::ComponentDefinition)

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • F Offline
              Frankn
              last edited by

              Hi Dan,

              Thanks for the explanation, I think that's what I did without realizing with just trial and error... many, many errors! πŸ˜„

              I thought you might like to see what I've been working on and by default bothering you with πŸ˜‰ so I included the script.

              Keep in mind this is a work in progress and my first attemp at at sort of programming so go easy on me. 😳 and please feel free to comment on what I'm doing wrong or that I could improve.

              Also the Drawers and Doors functions/inputs aren't implemented yet... still haven't figured that part out.

              Thanks again,
              Frank


              Test.rb

              1 Reply Last reply Reply Quote 0
              • F Offline
                Frankn
                last edited by

                I fixed a few things and realized I could call the instances I added to the global component by different names. πŸ˜„ 😳

                It does run slow but I still haven't looked into optimising scripts so hopefully I can speed it up some though I don't mind it though, it's faster then creating a cabinet from scratch. πŸ˜„

                Next on the to do/ to learn list is...

                • Creating door and drawer fronts, creating drawers... shouldn't be a problem.
                • Add a user defined number of shelves and insert them evenly spaced in the cabinet... I can do this manually/individually but the math involved in doing them automatically should be fun to figure out!
                • Same thing for door and drawer fronts.
                • And give a choice of creating an upper or lower cabinet since the building of these is different... I could use 2 different scripts like I did when moding the cab.rb script but I think it would be slick having it all-in-one.
                • Add grain direction
                • And eventually learning how to export the to a csv file so that I can populate an existing excel spreadsheet that I use... yes I know there are already some cut sheet/list scripts but this is more of a hobby/learning experience and I'd like to see what I can do. πŸ˜„

                That should be it but I'm already happy with the progress I've made in just 3 or 4 days or learning this stuff.

                Again thanks for all the help I really appreciate your teach how to fish approach. πŸ˜„

                Frank


                Test.rb

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

                Advertisement