sketchucation logo sketchucation
    • Login
    ⚠️ Attention | Having issues with Sketchucation Tools 5? Report Here

    How to add multiple groups into one group?

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 4 Posters 567 Views 4 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.
    • nithi09N Offline
      nithi09
      last edited by

      I change to require 'sketchup.rb'. still nothing happening. It's suppose to draw a cube in sketcup model I don't see anything happening

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

        @nithi09 said:

        I change to require 'sketchup.rb'. still nothing happening. It's suppose to draw a cube in sketcup model I don't see anything happening

        See my first reply - about addin an instance of the definition you created.

        (Also, when you modify the model you should wrap everything up in model.start_operation and model.commit_operation so it can be undone in one step.)

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

        1 Reply Last reply Reply Quote 0
        • nithi09N Offline
          nithi09
          last edited by

          I changed my code still not working here is the code after I changed

          <span class="syntaxdefault"><br />require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxdefault">def cube<br />list </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions<br />comp_def </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> list</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add </span><span class="syntaxstring">"CUBE BOX"<br /></span><span class="syntaxdefault">comp_def</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">description </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"This is a simple cube component"<br /></span><span class="syntaxdefault">ents </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> comp_def</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance<br />face </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],[</span><span class="syntaxdefault">24</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],[</span><span class="syntaxdefault">24</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">12</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">12</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">pushpull 16<br /><br />end<br /><br /><br />if </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">not $Cube_menu_loaded</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  <br />  UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Tools"</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Cube_BOX"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> cube </span><span class="syntaxkeyword">}</span><span class="syntaxdefault"> <br />  <br />  $Cube_menu_loaded </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> true<br />end<br /></span>
          
          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Your code only does half the job.
            It adds a 'box' [24x12x16"] to the model's definitions.
            If you want to add an instance of that definition to the model you need to do more steps...

            For example...
            defn=list[-1] to get the last added definition
            then to add an instance setup:
            tr=Geom::Tranfsormation.new(ORIGIN)
            OR other transformations like different points or rotations etc.
            and use
            instance=Sketchup.active_model.active_entities.add_instance(defn, tr)
            NOW you have one instance of the cube component place at the 'ORIGIN' [0,0,0] or anywhere else you specify in 'tr'...
            😕

            TIG

            1 Reply Last reply Reply Quote 0
            • nithi09N Offline
              nithi09
              last edited by

              this is different question.I want add color when OnClick. I try like this

              group.set_attribute('dynamic_attributes', 'onclick',"Set("Material","Red","Blue","Green")")

              but gives an error How do I do this
              thanks

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

                The best way to ensure you correctly 'phrase' it is to add the working onclick attribute manually to a DC [let's say it's reference is 'group'], then use:
                att = group.get_attribute('dynamic_attributes', 'onclick', "???")
                This will return att as ??? if it's not set, OR att as the attribute string, and this is in a form that you know works.
                Then reuse that in your 'set'
                group.set_attribute('dynamic_attributes', 'onclick', att) to see if the syntax is right...

                BUT note this: even if the format is right, the way you are using nested " quote-marks WILL cause failures... USING
                **"**Set("Material","Red","Blue","Green")**"**
                WILL CAUSE AN ERROR - unless you either 'escape' the internal " with a , OR more simply you use a pair of ' to enclose the whole string...
                i.e.
                "Set(**\**"Material**\**",**\**"Red**\**",**\**"Blue**\**",**\**"Green**\**")"
                or
                **'**Set("Material","Red","Blue","Green")**'**
                You must use a pair of ' to enclose ", or a pair of " to enclose any ' in a string... OR 'escape' the nested quote-marks as " or '
                🤓

                TIG

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

                  @nithi09 said:

                  but gives an error How do I do this

                  It really helps if you include the error message when posting questions related to errors.

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

                  1 Reply Last reply Reply Quote 0
                  • nithi09N Offline
                    nithi09
                    last edited by

                    Thanks TIG it's working when I use 'Set("Material","Red","Blue","Green")' but only problem I have to manually change to default color then onClick working fine How do I set to default color.

                    1 Reply Last reply Reply Quote 0
                    • jolranJ Offline
                      jolran
                      last edited by

                      material = nil ?

                      1 Reply Last reply Reply Quote 0
                      • nithi09N Offline
                        nithi09
                        last edited by

                        Thanks Jolran It's working now

                        1 Reply Last reply Reply Quote 0
                        • nithi09N Offline
                          nithi09
                          last edited by

                          Is it possible to change ItemCode according to the onclick color change if it is how do I can do?

                          1 Reply Last reply Reply Quote 0
                          • nithi09N Offline
                            nithi09
                            last edited by

                            Hope this explains my requirement a little better.

                            I have a sunroom comprised of many groups: corner post, floor channel, door, window etc.

                            I want the user to select their sunroom color by clicking the model. In order to do this I need to gather all the sunroom groups into a parent group where I will use the onClick function to change the Material attribute. I expect the Material change will automatically cascade to the sub-groups but if not I can easily set the Material of the sub-groups to something like=Parent!Material

                            The question is how do I wrap all of my groups into this parent group?

                            Thom Thom thank you for the advice regarding start opertaion, but I do not need undo for this model, the user is starting with a blank canvas and will simply delete top level group if they have to start over

                            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