[solved] Scale to length
-
hello again, sorry for asking another question while my other is still not resolved~ but I had another question that has come up from another step of my tool.
Can I use a length to create a scale transformation? Basically I am trying to scale a component to the length of the line? scale transformation requires a scale factor....
I was thinking I could take then length of the line, ie 12, and then divide it by the length of the component, ie 3, to get a scaling factor of 4? However I got stumped on this part due to units...my component measured 6' 1/4" not sure how I put this value into a variable I can use to divide my line length...
is their an easier way? and if not...could someone enlighten me on how to use the units? (I guess I could just switch the model to mm, but I would rather not as its not intuitive for community members at the urban design scale [my audience])
thanks again!
-
Sketchup uses Inches internally.
Class
Lengthis in inches. See:
http://code.google.com/apis/sketchup/docs/ourdoc/length.htmlFor conversion between defferent units use the methods of
Numeric(which is the superclass ofFloat, which is the superclass ofLength.) So both those subclasses inherit the conversion methods.
http://code.google.com/apis/sketchup/docs/ourdoc/numeric.htmlJust use a
Floatfor fractions:
6.25Use can get your number from complex fraction like so:
var = 3 + (15.0/32.0)But the fractional display is only in the dialogs and the VCB (Measurements inputbox).. when you get the length of the line in Ruby, it will be a
Float. -
As said...
Irrespective of the Model Info > Units settings the length of the line and the length of the component-instance are always in 'inches' as remembered inside Sketchup [decimal-number], so diving one by the other gives a scaling factor as a decimal number [.to_f] that you can use in the scaling-transformation... -
Off topic, but I like this one-liner:
def inch2modelUnit(v) return [v,v.to_feet,v.to_mm,v.to_cm,v.to_m][Sketchup.active_model.options["UnitsOptions"]["LengthUnit"]] end -
Ah i see the to_f worked perfectly, for some reason I was trying to convert it into feet with decimal places last night, not sure why....my brain was not quite as sharp after about 15 hours of coding/writing last night~
cheers
Korbin
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement