Get attribute roty
-
We must assume that the first object in the model.entities is indeed a DC instance ??
Your "roty
" code to get its attribute, should return its current rotation in Y...
For the definition's value it's more like "_inst_roty
"
Why not ensure you have the exact object of your desire in a more robust way?
This will then avoid any unexpected results... -
Thanks TIG for your reply.
Yes, entites[0] is a DC instance.
It was a simplified example, in my whole code I have different "test" to be sure that is a DC instance.
And in the same examaple with only one DC :
entity.get_attribute("dynamic_attributes", "lenx")
return a value > 0I have tested with _inst_roty
return nil -
I have tested it with my own simple DC instance and it returns the current
roty
value in degrees
Let's assume the dc instance is referenced as 'dc'...
Perhaps obtained fromdc=Sketchup.active_model.selection[0]
in the Ruby Console... Then if you use:
dc.attribute_dictionaries["dynamic_attributes"].each_pair{|k,v|p k;p v;puts}
It should print a list of ALL of the dc's attributes' key-names and their values...
So, do you really want 'roty
' is is it some other 'key' ? -
Ok I don't understand something...
In my model, I create a "cube" and make it DC (manually).
I rotate (Y axe) it (manually).I type your code in ruby console and run it.
Return nilI display in attributes component window : x,y,z,lenx,leny,lenz,rotx,roty,rotz.
I run again your code.
It return each pair key and valueWith my model who have my DC,
Your code return just
"_has_movetool_behaviors"
1.0
and the two personnal key/value
But in the attributes component windows all the key and value are displaying...In fact, with my code, I can get name, _lengthunits, lenx,ley,lenz. But x,y,z,rotx,roty,rotz, return 0
-
Everything you have said seems right.
What does roty say in the DC dialog window?
'0' or an angle ?
If it displays as '0' then that's what the attribute is set to.Rotating a DC instance in Sketchup will not change its roty rotation as a DC.
You need to get that from its transformation??I am now unclear about what it is you are doing and hoping to achieve in code.
-
Ok for the time being my aim is to get the angle of my DC.
In the DC dialog window roty = 17.
With my code I get 0.Ohhh, I get news
So I entered directly the angle in the DC dialog window
and now the angle appears in the ruby console !But if I move the DC with "move" or "rotate" the angle change in the window but no in the return of my code.
Why ?You speak about transformation... did i get my angle with other method than attribute_dictionaries ?
-
OK.
Now I think I see the issue.
A DC's attributes are remembered relative to that DC itself.
They do not necessarily relate to the DC instance's 'transformation' in 3d space within the model-context, or even within nested contexts.Image that you were NOT using a DC, but instead it were a simple group of objects...
Now you rotate it in the model.
How are you to find its model-rotation ?
Well... such an object has a 'transformation' which is a complex multi-item matrix of values that determine its location in 3d, and its scale and rotation [about all three axes] etc - many of these values interact - e.g. scaling an object about it's zaxis after it has been rotated has a different outcome compared to scaling it before the rotation.
https://developers.google.com/sketchup/docs/ourdoc/transformationYou can set various values by adjusting the object's transformation...
You can get various info by interrogating the object's transformation...To find an object's rotation about the Y_AXIS in the model you need to find its obj.transformation.yaxis, then after checking it's not parallel to the model's Z_AXIS, you can get the angle between that yaxis and the model Y_AXIS - it's in 'radians', but angle.radians returns it in degrees for you... Next issue is to determine if it's cw/ccw as the angle is not specific. If you take yaxis.cross(Y_AXIS) the resultant vector will be up or down depending on the cw/ccw of the relationship, comparing that vector.z with Z_AXIS.z will tell you whether or not to make the angle negative or not...
The reason we checked earlier if the yaxis.parallel?(Z_AXIS) was so that in that specific case we can't get its angle with the Y_AXIS as its always 90 degrees (+/-) with no 'orientation' information, in that case you need to devise a way of getting the angles between its other axes and the equivalent model axes to determine its true model Y_AXIS rotation. The same applies to all other axial rotations you might want to obtain...
There ARE complex ways of trying to get an object's rotation about an axis from the transformation itself... For exampledef euler_angles(tr=nil) return [] unless tr and tr.is_a?(Geom;;Transformation) m = tr.xaxis.to_a + tr.yaxis.to_a + tr.zaxis.to_a if m[6] != 1 and m[6] != 1 ry = -Math.asin(m[6]) rx = Math.atan2(m[7]/Math.cos(ry),m[8]/Math.cos(ry)) rz = Math.atan2(m[3]/Math.cos(ry),m[0]/Math.cos(ry)) else rz = 0 phi = Math.atan2(m[1], m[2]) if m[6] == -1 ry = Math;;PI/2 rx = rz + phi else ry = -Math;;PI/2 rx = -rz + phi end end return [-rx,-ry,-rz] if xyz==[] end
Usage
rotations=euler_angles(object.transformation)
It returns nil, OR a three element array of the[rotx, roty, rotz]
angles
So to find the object's 'roty' you can use:
roty=euler_angle(object.transformation)[1]
etc etc... The code's a bit untested and needs some trialing to see if the angles return correctly... -
Ok, I need some times to understand what you say.
But... Why I can't get the information that I see in the DC attribute window ?
Then in the DC attribute window the information is update automatically...How the feature File/Generate rapport do that ?
-
Sorry... you seem to be confusing the DC attributes and an object's actual 3d transformation
If you set an angle for RotY in the DC's dialog as say 15 that's what the attribute is read to be in the Reporter [OR any code you write]...
The 'properties' of an object within the model are not necessarily tied to these DC attributes... indeed an object need not be a DC at all... that's its 'transformation'.Now I am confused
-
I wonder if you had find an answer to your problem, I also need to know the value of lenY but I cannot get it through get_attribute with out entering them manually in dc panel
Advertisement