My first script
-
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
endend
=begin
╔══════╗
║ MENU ║
╚══════╝
=end
unless file_loaded?(FILE)
mymenu = UI.menu('Plugins').add_submenu('GXM Plugin Collection')
mymenu.add_item('Block tool') {Gxm_blocktool.main}
endfile_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
-
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=30232Try 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!
-
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.
Advertisement