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

My first script

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 3 Posters 330 Views
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.
  • G Offline
    Gardentwine
    last edited by 13 Jan 2013, 10:23

    hi guys i have be learning ruby, after thomthom guided me to give it a try and also spent a good few days look at chris's video tuts and finally got me first script working as a compete snippet, looking to expand it

    heres me first script
    ` module Gxm_blocktool

    =begin
    ╔══════╗
    β•‘ MAIN β•‘
    β•šβ•β•β•β•β•β•β•
    =end
    def Gxm_blocktool.main

    # Input box <hope to change to mouse input
    prompts = [("Width"),("Height"),("Depth")]
    values = [32.inch, 32.inch, 32.inch]
    results = inputbox prompts, values,("Box Dimensions")
    return if not results
    width, height, depth = results
    model= Sketchup.active_model
    model.start_operation("Create Box")
    entities = model.active_entities
    group = entities.add_group
    entities = group.entities
    pts = [[0,0,0], [width,0,0], [width,depth,0], [0,depth,0], [0,0,0]]
    # add the face to a enntities in model
    face = entities.add_face pts
    status = face.pushpull -height, true
    model.commit_operation
    end

    end
    =begin
    ╔══════╗
    β•‘ MENU β•‘
    β•šβ•β•β•β•β•β•β•
    =end
    unless file_loaded?(FILE)
    mymenu = UI.menu('Plugins').add_submenu('GXM Plugin Collection')
    mymenu.add_item('Block tool') {Gxm_blocktool.main}
    end

    file_loaded(FILE)`

    Things i would like add to this, is mouse input data, instead of input box and try and group each cube face then extrude in and scale in egdes to form a hollow cube with no overlaying groups.

    looking forward on feedback on my first script

    1 Reply Last reply Reply Quote 0
    • J Offline
      jolran
      last edited by 13 Jan 2013, 10:47

      Hi there!

      I'm sure you will get a lot of tips in here.

      For values you don't have to declare inches or mm etc. You can just use 45.to_l for ex.
      Sketchup will convert the value to current unit for you.
      Also if you use @ variables for values the will be rembered during the session.
      And you could set them before the prompts(they will get overwritten if edited).

      Like @width=45.0.to_l unless @width

      Break the code in different methods. You can call a method from inside another method for ex.

      Thomthom just updated a tutorial about the pickhelper that might help regarding mouse input data.
      http://sketchucation.com/forums/viewtopic.php?f=180&t=30232

      Try to learn Ruby itself, not just Ruby for Sketchup.
      I did that misstake, and I'm spending lot of time catching up on that matter.
      Just some ideas...

      Keep on swimming! πŸ˜„

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 13 Jan 2013, 13:00

        To get input data from the mouse you got either InputPoint class or PickHelper. It depends what you are looking for. InputPoint gives you inferences is is similar to what for instance the Line tool uses. PickHelper is more for being abel to select Entities. Either way, You want to oolk into the Tool class.

        As for units which jolran mentioned, I got an overview of how to deal with units in SU here: http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/ You basically should not do so much work with it. Keep everything in inches, the internal units, preferable in the Length class and let SU do the work of converting back and forth between internal units and model units.

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

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

        Advertisement