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

    Ruby api - Get the thickness of component

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 223 Views 3 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.
    • N Offline
      nXqd
      last edited by

      Hi everyone,
      This is my very first post in this great forum. I encounter some problem when finding and using ruby api.
      What I want to do know is duplicate a component - (by selecting it using model.selection[0] ), and put the duplicated one on top of the original one. I have problem with find the x,y,z of a component in space and its thickness.
      I think this should be an easy issue for experienced sketchup users here 😎

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

        <drunkcode>

        <span class="syntaxdefault"><br />model&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />instance&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">point&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">corner</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">4</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">tr&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new(&nbsp;</span><span class="syntaxdefault">point&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definition</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">tr&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;</span><span class="syntaxdefault"></span>
        

        </drunkcode>

        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 have instance1.
          That has bounds.
          So to find its vertical extent use
          zz=instance1.bounds.depth
          Note that the three values for a bounding-box are counter-intuitive - following the old CAD conventions when z/depth was out of the screen - it's NOT the 'height' !
          So bounds
          .width >>> x Red
          .height >>> y Green
          .depth >>> z Blue
          You can also get its transformation
          tr=instance1.transformation
          Use that to insert your duplicate.
          instance2=instance1.parent.entities.add_instance(instance1,definition, tr)
          This now overlays the two exactly.
          To move the new instance up in the 'z' by ' zz' make a vector and apply a second transformation to it - you could apply it as you insert it BUT this is perhaps an easier way to get your head around...
          ve=Z_AXIS.clone ve.length=z tv=Geom::Transformation.translation(ve) instance2.transform!(tv)
          The second instance should now rise up so its bottom-most part aligns with the original's top-most part.

          TIG

          1 Reply Last reply Reply Quote 0
          • N Offline
            nXqd
            last edited by

            @TIG
            Thanks for the great long and damn useful answer. I will try it today πŸ˜„

            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