Retrievin object's absolute height ??
-
@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