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

    Ruby Tutorial: How to create and add a component from Ruby

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 7 Posters 8.4k Views 7 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.
    • T Offline
      tomot
      last edited by

      I find these little "Ruby snippets" very helpful. they are a great way to learn to code in Ruby.
      I have another idea for a snippet. Using the Cube as a basis that Todd started with above.

      How do I code a radial array of cubes about a central point?

      tia

      [my plugins](http://thingsvirtual.blogspot.ca/)
      tomot

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

        @tomot said:

        How do I code a radial array of cubes about a central point?
        tia

        Look into my "Grow.rb" script to see how to do all types of matrix arraying etc - Move, Rotate and Scale of copies...

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomot
          last edited by

          I revisited the Cube this afternoon:
          I added a dialog box, 2 sub-menus.
          One for a component cube, the other
          for a grouped cube. Then added some color
          and transparency statements.

          Thanks TIG I will have a look at grow.rb

          btw: using the component cube first , followed by grow.rb
          and then changing any component cube creates some interesting effects.


          Box0.rb

          [my plugins](http://thingsvirtual.blogspot.ca/)
          tomot

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomot
            last edited by

            I'm still doing some further investigating into components used in Ruby
            The attached Ruby could produce 2 options for component editing, by adding a sub menu.

            What works now is that each component in the group can be edited on its own
            What does not work!
            Editing one component in the group , and had have the other 8 follow the same editing changes.

            I hope someone can have a look at the code, I cant seem to find the right component code lines.

            tia


            Box4.rb

            [my plugins](http://thingsvirtual.blogspot.ca/)
            tomot

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

              If you make a component and place it several times then anything you do to one instance affects all of the others - unless you use 'make_unique' on it first. Using groups and copying them avoids this, BUT a recently noted but undocumented quirk in the SUp Ruby coding means you must use 'make_unique' on a group as you copy it... otherwise that copy is treated as an 'instance' (just as if it were a component anyway !!!) and then both might change as you alter one...

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomot
                last edited by

                I'm wondering why you would suggest Make_unique

                I was copying similar code from JoistTool.rb which allows for
                component editing of the type I'm looking for.

                Yet JoistTool.rb does not contain any Make_unique code.

                I'm wondering if the Upto statements are causing a problem?

                [my plugins](http://thingsvirtual.blogspot.ca/)
                tomot

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

                  But the Joist and Rafter tools make a component that is repeatedly copied AND if you subsequently edit one of them then they all change ! If you want parts that are unconnected then use Groups - but make each unique - as I said within a script they can be viewed as clones of the same thing and they'll edit together, but doing an edit in the "real world " has each of them treated as a single entity...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tomot
                    last edited by

                    OK, I really don't understand at this point how or where I'm going to introduce make_unique, into my existing script. I have the following inserted before the 1st upto statement

                    definitions = model.definitions
                    component = definitions.add
                    entities = component.entities

                    followed by:

                    trans = Geom::Transformation.new
                    entities = model.active_entities(component, trans)

                    after the cube has been drawn
                    What I cant wrap my head around is:

                    Both my script, Box4.rb and JoistTool.rb create copies of 3d entities.

                    JoistTool.rb uses t=Geom::Transformation.translation to make copies
                    while, Box4.rb uses Upto to make copies.

                    Obviously these copies are treated differently in Ruby?
                    causing JoistTool.rb work, and Box4.rb not work?

                    (I'm sorry for my thick head)

                    [my plugins](http://thingsvirtual.blogspot.ca/)
                    tomot

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

                      Try using groups as an alternative...
                      ...
                      entities=model.active_entities
                      group=entities.add_group
                      gents=group.entities
                      ...
                      gents.add_line(pt1,pt2)
                      gents.add_face(pt1,pt2,pt3...)

                      etc, all made inside the group NOT model

                      then transform group etc

                      group1=group.copy
                      group1.make_unique

                      transform group1 etc

                      ...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tomot
                        last edited by

                        I'm re-reading your comments, and somehow I get the feeling we are misunderstanding each other.
                        I think I'm responsible for that misunderstanding at the very beginning.

                        your response to my question about the joist and rafter tools is a case in point.

                        I quote you:

                        "But the Joist and Rafter tools make a component that is repeatedly copied AND if you subsequently edit one of them then they all change !"

                        What I quoted above, is exactly what I would like my script to do. I'm not looking for parts that are unconnected, as you talk about in the remainder of your quote.

                        I would like all of the cubes that my script repeatedly copies/generates, to be made a component, so that if I then edit one all the rest will change.

                        [my plugins](http://thingsvirtual.blogspot.ca/)
                        tomot

                        1 Reply Last reply Reply Quote 0
                        • K Offline
                          Koos Brandt
                          last edited by

                          Hi

                          I know it is nearly a year later, but your code is not doing what you think it is doing.

                          Box4 does the following logically:

                          It creates a component def
                          Then you add 1 face to it and pull the face to make a block
                          then you add this component as an instance

                          then you add another face to it and pull it making block 2
                          then you add another instance. But you also update the original instance to now have two blocks

                          and so on

                          if you set it to have 3 by 3 blocks you get 9 components all the same with each nine pulled faces inside it. The inside blocks are not component instances, the are merely blocks (pulled faces) inside the component.

                          If you select the block at the end of the process and move it you will see there are more blocks underneath it.

                          If you wanted to do what you intended, you needed to create a new component def each time you enter the upto loop.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            tomot
                            last edited by

                            Its one of the things I have not been able to resolve.
                            I will give your suggestion a try, in the near future.

                            thanks!

                            [my plugins](http://thingsvirtual.blogspot.ca/)
                            tomot

                            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