sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    [Question] how to add entities to componentdefinitions

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 492 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.
    • R Offline
      rvs1977
      last edited by

      Hi all

      as a beginner, I have a simple question I guess πŸ˜„

      Im looking how to "intialize" entities into a component at startup.
      As far as I know its possible to use something like componetdefintions??

      For instance I want to make a reusable box I can use again and again.
      I dont want it to load it from a file.

      tnx in advance

      RVS


      Get a Ruby

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

        Create a component: model.definitions.add
        http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#add

        
        model = Sketchup.active_model
        box = model.definitions.add('box')
        face = box.entities.add_face( [0,0,0], [10,0,0], [10,10,0], [0,10,0] )
        face.pushpull( 10 )
        
        

        If you want to create such a component every time you open a file you need to use the AppObserver to catch the events when a new model is made:
        http://code.google.com/apis/sketchup/docs/ourdoc/appobserver.html

        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

          You need to give a bit more detail before we can assist you fully.
          If you always want particular components to be in any new SKP then simply have them pre-loaded in the default SKP template that opens when you make anew file.
          If you want to 'load' or 'import' components from an external SKP file it's straightforward as long as you know the path/skp_name etc - see http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#load and http://code.google.com/apis/sketchup/docs/ourdoc/model.html#import.
          You can make a new definition using newcdef=model.definitions.add [ http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#add ] - then change its name etc using newcdef.name="new_name" etc... Then you can add entities to the definition using the entities.add_...() [ http://code.google.com/apis/sketchup/docs/ourdoc/entities.html ] which allow you to add various kinds of geometry and so on - even instances of sub-components inside definitions etc etc...
          Once you have the component-definition in your SKP you use entities.add_instance(cdef, trans) - where cdef is the component-definition and trans is its 'transformation' - typically its insertion-point [although you could move/scale/rotate it etc too] - see http://code.google.com/apis/sketchup/docs/ourdoc/transformation.html.
          If you have a component-definition that you want to change - e.g. by adding or deleting entities from within it - then the entities.add_...() [ http://code.google.com/apis/sketchup/docs/ourdoc/entities.html ] or entity.erase! [ http://code.google.com/apis/sketchup/docs/ourdoc/drawingelement.html#erase! ] methods etc will help...
          Remember that if you change a component-definition it will affect all instances of it in the model... unless you have first used the instance.make_unique method on the one instance you want changing... and then got it's new definition with cdef=instance.definition and you then change the entities of that definition.
          If you have several similar component-definitions with instances placed in the model remember that you can simply swap them around using instance.definition=new_definition [Tip: having common insertion points helps !]...
          πŸ€“

          TIG

          1 Reply Last reply Reply Quote 0
          • R Offline
            rvs1977
            last edited by

            Thanks to both of you.
            It pretty much answer all my questions for now! πŸ˜„

            btw, SU and ruby combined makes me breathless. I got a tons of ideas, but only
            beginning to learn.


            Get a Ruby

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

              @rvs1977 said:

              btw, SU and ruby combined makes me breathless. I got a tons of ideas, [...]

              Welcome to the club! Hope you will enjoy the ride. Keep asking any questions you might have.

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

              1 Reply Last reply Reply Quote 0
              • B Offline
                blindleader
                last edited by

                It looks like I'm treading ground that's been settled for years.
                I thought your link to the entities class was going to solve my problem, but...
                I'm trying to construct component definitions out of several previously defined components, but without placing any physical objects.
                Here's one of those definitions:

                ` # Make the bottom plate
                bottom_plate_def = Sketchup.active_model.definitions.add "Bottom Plate"
                bottom_plate = bottom_plate_def.entities.add_face pt # pt is an array of points

                Move the origin to center of final 3D cell

                tr = Geom::Transformation.translation [-oal/2, -oaw/2, -cell_thickness/2 + plate_thickness]
                bottom_plate_def.entities.transform_entities tr, bottom_plate`

                Now, how do I combine three such definitions (bottom_plate, core, top_plate) into a fourth one? The entities class doesn't seem to allow it. But it must be possible, since it's a straightforward operation in Sketchup itself.

                three_d_cell_std_def = Sketchup.active_model.definitions.add "3D Cell - Standard"

                three_d_cell_std_def = Sketchup.active_model.definitions.add "3D Cell - Standard"

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

                  You already know how to add objects to an '.entities' collection [i.e. for model/active_/definition/group].
                  Make a new definition, then use defn.entities.add_instances of the other three [already made] components as you wish...
                  OR make the containing definition, then make gp=defn.entities.add_group() and add geometry etc to gp.entities, make the group into a component and then adjust its definition name etc as needed - repeat three times for the contained instances...

                  TIG

                  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