Retrievin object's absolute height ??
-
hi tig,
i understood and made some tests.
but if i have a group named@main_element (i persume it has a transformation, even it is not moved or anything else)
and saytra = @main_element.transformation
i get errors , since my syntax is wrong.
could you give me the syntax for retrieving the transformation from a group?
i tried a lot of ways, but always get errors.
thank you!
stanedit:
when i define tra astra = @main_element.transformation.to_a
i get
tra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
how can i interpret the numbers?
edit 2:
when i move a group in Z+, tra becomestra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1968.503937007874, 1.0]
so 14th position seems to give the height.
the problem is, that if i create a plane in a certain height (Z+), the transformation counts this as 0,0,0 .
pos. 14 changes first, when i move the group from its origin place, where it was created.......this transformation is not related to absolute zero.... -
Does this work ?
If I resue my code with TIG's recommendations..
gpz = group.transformation.origin.z
zmax = pts.map{|p| p.z + gpz }.maxYou could also have a look at Bounds.corner.points and get the highest Z value from those,
unless you are interested in a particular vertice or so.. -
hi jolran,
- i'll test your new idea later tonight, but i had the formula with origin
tra = @main_element.transformation.origin
already and it gave me the origin of the group at the point, where it was made, not to absolute [0,0,0]. but we shall see !!
- bounding box : i tried this, but i don't need the lowest point of a group, but one special corner within it, so lowest z of the bbox does not help here.
and when i retrieve the bbox of the nested element, itz again is relative, not absolute.
seems to be tricky somehow....
thanx
stan -
@artmusicstudio said:
hi tig,
i understood and made some tests.
but if i have a group named@main_element (i persume it has a transformation, even it is not moved or anything else)
and sayYes at the moment the group is created it is given an Identity Transformation.
tra = @main_element.transformation
i get errors , since my syntax is wrong.The only reason this would give you syntax errors is if the variable @main_element has not been physically associated with the group.
could you give me the syntax for retrieving the transformation from a group?
i tried a lot of ways, but always get errors.mod = Sketchup.active_model # Open model > ent = mod.entities # All entities in model > sel = mod.selection # Current selection > @main_element = ent.grep(Sketchup;;Group).select{|g| g.name=="@main_element"}[0] > tra = @main_element.transformation; #save the current transformation > @main_element.transform! tra.inverse; # return the group to its created position > zmax = @main_element.bounds.max.z; puts zmax; # get the max z > @main_element.transform! tra; # return the group to its current position
thank you!
stanedit:
when i define tra astra = @main_element.transformation.to_a
i get
tra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
how can i interpret the numbers?
edit 2:
when i move a group in Z+, tra becomestra [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1968.503937007874, 1.0]
so 14th position seems to give the height.
the problem is, that if i create a plane in a certain height (Z+), the transformation counts this as 0,0,0 .
pos. 14 changes first, when i move the group from its origin place, where it was created.......this transformation is not related to absolute zero.... -
@sdmitch said:
@artmusicstudio said:
hi tig,
i understood and made some tests.
but if i have a group namedmod = Sketchup.active_model # Open model > > ent = mod.entities # All entities in model > > sel = mod.selection # Current selection > > @main_element = ent.grep(Sketchup;;Group).select{|g| g.name=="@main_element"}[0] > > tra = @main_element.transformation; #save the current transformation > > @main_element.transform! tra.inverse; # return the group to its created position > > zmax = @main_element.bounds.max.z; puts zmax; # get the max z > > @main_element.transform! tra; # return the group to its current position
thank you!
stanThe code block above seems to have been edited out of your earlier post, but sdmitch grabbed it first. It seems to reveal confusion between the name attribute of a group and the symbolic name of a variable that refers to that group. These are separate, unrelated concepts. That is, if you write
@foo = ents.add_group #@foo is a variable that refers to a group with no name attribute
@foo.name = "@main_element" #@foo now refers to a group with name attribute "@main_element"Following this code, there is no such variable as @main_element. Conversely, there is no group whose name attribute is @foo.
Your search above looks for a group whose name attribute is "@main_element". Did you assign that previously using Group#name=, or are you assuming that because you earlier created a group referenced by a variable named @main_element that the group has that as its name attribute (wrong). In any case, you need to test what value was assigned to @main_element by your search. I bet it is nil (because the search found nothing), and that is the cause of your syntax error.
Steve
-
I haven't follow along the other discussion so pardon me if butting in..
But If your only concern is the get the heighest elements point(?) won't this code work regardless of any transformation made ?
%(#FF0000)[bb = group.bounds # could be any element responding to Bounds.
cornersZmax = (0..7).collect{|i| bb.corner(i).z }.max]I tested and it seams to be working. ?
-
Since I haven't seen your code...
Here's a guess...If your 'reference' is to a 'group' OR a 'component-instance', then it WILL have a 'transformation'.
BUT if that 'reference' is to a 'definition' it will NOT !puts @main_element.class
in your code will tell you what the reference is... -
What are we trying to determine? If it is the highest point regardless of location and/or orientation or the true height of the group?
-
I interpreted this as highest point.
@unknownuser said:
i would like to calculate the height of a defined point (say toppoint of a bbox)
above absolute sketchup 0,0,0. -
In that case, ?group?.bounds.max.z should give you that in SU8.
-
It's possible to devise a group with a transformation where the group.bound.max.z will NOT be a vertex.
If the proposition is to find the highest vertex in a group that is not the same thing ?
However, if you are simply trying to find the max.z it will do...
See this simple illustration...
-
@unknownuser said:
element.bounds.max.z
Yeah, that's way simpler...
But as TIG pointed out bbox cp is not always safest way to find highest vertex, so normally one end up traversing the collection anyway.I'm starting to wonder if TO wants to measure the face height..
to reuse the transformation origin maybe try this.. I guess theres more than 1 way to do this.
targetZ = 0 org = group.transformation.origin group.entities.to_a.grep(Sketchup;;Edge).each{|edg| sz = edg.start.position.z ez = edg.end.position.z tmax = (sz > ez ? sz ; ez) + org.z next unless tmax > targetZ targetZ = tmax } puts targetZ.to_l
-
@jolran said:
@unknownuser said:
element.bounds.max.z
Yeah, that's way simpler...
But as TIG pointed out bbox cp is not always safest way to find highest vertex, so normally one end up traversing the collection anyway.I'm starting to wonder if TO wants to measure the face height..
to reuse the transformation origin maybe try this.. I guess theres more than 1 way to do this.
targetZ = 0 > org = group.transformation.origin > > group.entities.to_a.grep(Sketchup;;Edge).each{|edg| > sz = edg.start.position.z > ez = edg.end.position.z > tmax = (sz > ez ? sz ; ez) + org.z > next unless tmax > targetZ > targetZ = tmax > } > puts targetZ.to_l
Sorry but that only works if there is no rotation. Here is another way
targetZ = 0 tra = group.transformation group.entities.to_a.grep(Sketchup;;Edge).each{|edg| sz = edg.start.position.transform(tra).z ez = edg.end.position.transform(tra).z targetZ = [targetZ,sz,ez].max } puts targetZ.to_l
-
Dats true. But I don't understand why you opt to create a new Array for each edge instead of a ternary
Advertisement