This does not work. I get the following error: Error: #<NoMethodError: undefined method transformation’ for nil:NilClass>`
I’m obviously doing something wrong, but having a hard time figuring out what. I want, really, to rotate the group
I’ve been adding to, but I’m not sure how to retrieve that with active_model.
You mentioned this before, but I never tested it. I tried to research this, but the only documentation I could find was this:
The degrees method is used to convert from degrees to radians.
For example 90.degrees would return 1.5707963267949
Examples:
degrees = 90
radians = degrees.degrees
Returns:
radians - a value in radians if successful
Version:
SketchUp 6.0
The note that it was for SketchUp 6 always made me leery of using it, but it works under 2017.
Yeah, IMHO those methods were defined backward. They tell you what units the value started in, not what units you want it converted to! It causes me repeated confusion.
You’re not the only one … I found this by Leonard Richardson:
I named the conversion method degrees by analogy to the methods like hours defined by Rails. This makes the code easy to read, but if you look at the actual numbers, it’s not obvious why 45.degrees should equal the floating-point number 0.785398163397448.
If this troubles you, you could name the method something like degrees_to_radians. Or you could use Lucas Carlson’s units gem, which lets you define customized unit conversions, and tracks which unit is being used for a particular number.
If the methods were named instead as .to_radians and .to_degrees it would have the dual advantage of being easier to remember which way the conversion is going, and also be more consistent with other unit-changing methods, like .to_int, .to_l , and .to_s
Back to your original question, @mvfpadilla, you need something like this. By using a named group (g, in this case), you can refer to it unambiguously.
ordered_line_coordinates = [[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,0]]
model = Sketchup.active_model
entities = model.active_entities
g = entities.add_group
g.entities.add_line(ordered_line_coordinates)
model_origin = model.axes.origin
tr = Geom::Transformation.rotation(model_origin,X_AXIS,45.degrees)
g.transform!(tr)
BTW, the model.axes.origin is only defined for SketchUp 2016 forward … you could replace this with [0,0,0].
Thank you. With some minor changes (factoring out the entities.add_group, and adding lines and faces to it in an inner loop), this code seems to work. Thank you very much.
For consistency with the methods used for lengths I think one should be called to_degrees and the other degrees. However it took my some time to get into that logic too. Apparently writing 10.m in Ruby is meant to correspond to writing 10 m in human text. I can agree this is quite backward though compared to the usual naming conventions.