Trust me Chris you and everyone else who takes the time to help us new guys out are anything but useless. 
@chris fullmer said:
Sorry we were so useless. Glad you figured it out, though!
Trust me Chris you and everyone else who takes the time to help us new guys out are anything but useless. 
@chris fullmer said:
Sorry we were so useless. Glad you figured it out, though!
With some trial and lots of errors I figured it out. 
Sorry to dig up an old thread but It's kind of relevant to what I'm trying to do with inputbox.
What I'd like to do is associate a word with a value... ie: inputbox prompts for 3 values to create a square, height, width and vertical line... height and width are pretty self explanatory. Vertical line is expressed as inches.. so a 24" x 24" square could be divided in half by typing in 12... what I'd like to add is being able to type in 'center' or 'middle' and getting the same result.
I've tried making that field of the array a string and then converting the string to an integer or a float but I just can't get it to work... also tried associating the words to a value and samething no workie...
Hope that makes sense...
Thanks in advance.
@tig said:
Also you might not want the height as an integer by using
.to_i, because0.5.to_iwill become0not1as you might have expected, as an integer simply ignores anything to the right of the decimal-separator !
The inputbox dialog can have its 'type' set to be a 'float' etc by making the default e.g. 1.0 [rather than 1 which fixes it as an integer] - then the dialogs returned_value[0] is always as a float anyway - BUT if you really want it to be a string - so for example the user can type '1.5m' and they'll get 1.5m irrespective of the SKP's current unit settings - then use.to_lto convert that value into a 'length'...Rather than add your dialog into a lot of complex code to test it just make it in a one-liner in the Ruby Console...
results=UI.inputbox(["Height: "],[1.0],[""],"My Title")
for a float - shown with
answer=results[0], andanswer.class
results=UI.inputbox(["Height: "],[1],[""],"My Title")
for an integer - shown with
answer=results[0], andanswer.class
results=UI.inputbox(["Height: "],["1.0"],[""],"My Title")
for a 'string'- shown with
answer=results[0], andanswer.classand then
answer.to_i answer.to_f answer.to_l[Try different answers to see the results...]
@tig said:
Here's Jim's clever solution made into a method...
def roundtofraction(num, frac)
> num = num.to_f
> frac = frac.to_f
> return (num * frac).round / frac
> end
Usage:
my_num = 0.17578125
my_frac = 16
my_num=roundtofraction(my_num, my_frac)0.1875
Thanks yet again TIG! 
@dan rathbun said:
This is for measurements?
One limitation within Sketchup, is that the precision is limited to 0.001", no matter what the model units are set to.
So using a fractional float of 0.1875" may get rounded by Sketchup. Will it be 0.187" or 0.188" ??
I would suggest that you decide what it will be in your 'rounding' method...
Yes Dan, this is for measurements.
I didn't know that limitation about Sketchup, interesting. But I'm not building a plane here just cabinets, vanties and that kind of thing, but I just don't like seeing that ~ and this script programming is addictive! You just keep adding on features and stuff you can do, I think I might have a problem. 
Thanks for the info
@chris fullmer said:
That can't be right, you didn't even have to make any special methods to do that
![]()
Chris don't feel bad even after doing this thing called 'programming' for the last few weeks I'm still getting the hang of methods, classes and all that jazz!!

@jim said:
my_num = 0.17578125 frac = 16.0 # 1/16th (radix, specifically) rounded_num = (my_num * frac).round / frac
Dude you're a genius! That is awesome!
Thank you!!
Wow! Thanks for taking the time to explain it in a Ruby's for Dummies term!
No way I would of come up with a solution to that problem!
That now makes total sense... now I'm off to try and implement this in my script... should fun 
Thanks again!
Thanks Chris...
I'm going to need to study that for awhile because at first glance I'm lost
but on the other hand I'm glad it's not something simple because I was racking my brain trying to figure this out! 
Thank you Tig... that is helpful but it doesn't accomplish exactly what I'd like it to do... unless I'm not using it properly.
Here's a more concrete example of what my problem is...
A result I get after doing some funky math is 0.17578125 but I'd like to round that off to 0.1875. In Excel I'd this =CEILING(0.17578125, 1/64) and that works great.
0,17578125 is actually more accurate but it's TOO accurate.
Because I get a measurement inside Sketchup that has the ~ in front of it.
Basically I'de likt to set the accuracy of my formulas to 1/64.
I appologize if it's me not 'getting' your previous answer... I guess from my question you already guessed I'm still new to this whole programming deal. 
Hi,
Like the title says... I'm looking for a way to replicate the ceiling function in excel. I played around with ceil but either I'm not getting it or it doesn't do the same as excel.
I basically want to round off numbers/measurments to the nearest 1/64.
Any help would be greatly appreciated.
Frank
Thank you guys that helped a ton in my understanding of how that works!
I do have a few of questions...
What is the the differnce in creating a list this way...
list = ["item1"|"item2"|"item3"]
and this...
list = ["Wall", "Wall - Corner", "Base", "Base - Corner"]
list_joined = list.join("|")
drops = [list_joined, ""]
any advantages disadvantages?
Also in some examples that I found the don't use the UI in the inputbox command... again any advantage in doing either or?
And lastly I'm having trouble understanding/implementing this last part...
def dialog()...
###then in tour main code have
return nil if not self.dialog()
...
return nil if not results
...
if results[1] < 0
UI.messagebox("The number must be >= 0 !")
self.dialog()
else ### number was OK
@number=results[1] ### reset @number only now...
return true
end
Frank
Hi,
I'm trying to get a drop down list to work. I'm able to creat an input box and even add a drop down list. But what I'm not able to figure out and can't seem to find the answer too is how to associate a value or have code run from the drop down list options.
As you might have guessed I'm new at this whole programming thing.
Any help would be appreciated.
Thanks,
Frank
I fixed a few things and realized I could call the instances I added to the global component by different names.

It does run slow but I still haven't looked into optimising scripts so hopefully I can speed it up some though I don't mind it though, it's faster then creating a cabinet from scratch. 
Next on the to do/ to learn list is...

That should be it but I'm already happy with the progress I've made in just 3 or 4 days or learning this stuff.
Again thanks for all the help I really appreciate your teach how to fish approach. 
Frank
Hi Dan,
Thanks for the explanation, I think that's what I did without realizing with just trial and error... many, many errors! 
I thought you might like to see what I've been working on and by default bothering you with
so I included the script.
Keep in mind this is a work in progress and my first attemp at at sort of programming so go easy on me.
and please feel free to comment on what I'm doing wrong or that I could improve.
Also the Drawers and Doors functions/inputs aren't implemented yet... still haven't figured that part out.
Thanks again,
Frank
See API: ComponentDefinition.refresh_thumbnail
cdefs = Sketchup.active_model.definitions
cdefs.each {|comp| comp.refresh_thumbnail }
[/quote]
Thanks that worked perfect. 
Frank
I had already tried that and it doesn't work, the only way to get them to show up is to edit the component then the preview shows up. Not a big deal but was just curious if I was doing something wrong with the script/code.
Thanks again sir,
Frank
Again thank you for the explaination Dan... it almost makes sense to me! 
Something strange is happening with the way the components are being displayed in the Components window in Sketchup. They're all there but there is no preview picture to the components. But if I create a component manually it shows up... an idea why?
I've also been looking into adding components to other components and all I found so far is some refernences to subcomponents and parent components but nowhere did I find how those work?
This has been a greta learning experience and I find half the battle is actually using the correct search terms but I'm getting there!!
Hi just wanted to thank you both for taking the time to help me learn something new. I was able to get it to work but I couldn't get this line to work...
model.active_entities.add_instance(new_def_component, Transformation.new) I keep getting this error not sure why.
Error: #<NameError: uninitialized constant Transformation>
But I am able to get it to work with this and it does what I need so far. 
inst = ent.add_instance def_shelf, [0, 0, 0]
I do have a question. I know how to create multiple instances of the same component and even make them unique if I need to... but how can I make the number of instances needed a variable?
Example... user is prompted for the number of boxes he wants to add, he enters 3, the scripts creates 3 boxes in different locations.
Frank
The more I read about how to create entities (I think I'm using the correct term) the more I realize that this script (cab.rb) probably isn't the best one to learn to script with.
Using entries like entities.add_line([0, 0, 0], [10, 10, 10]) seem to be much more useful, also more powerful and maybe even simpler to use when you get how they work.
Even if this script does hwta I want it to do, seems like building off of it to get the end result I want is more work then making something from scratch...
Back to the reading!
p.s. Mods if this is taking this thread off topic let me know and I'll stop posting here. 