ah well, it is simpler than your code, but unfortunately also a bit more involved than it actually should be. You need to know a few things:
1. Historically, a subshape, like a vertex, gets its value from the calculation "shapeplacement*Vertexpoint". E.g. for a default box there is a vertex at (0,0,0). If you add the placement (10,10,10) to the box, this vertex will have the value (10,10,10) afterwards (vertex.Point = (10,10,10))
2. With the introduction of stacked CS (Parts and bodies etc.) the system of point 1 is still in place, but referes not to the global CS anymore, but always to the CS one level higher. E.g. if the box is in a Part, our Vertex of point 1 will still have the value (10,10,10), but this relates to the Parts origin. If the Part is moved too, this is not the global point of the vertex.
3. getGlobalPlacement() calculates you the correct placement of a hirarchy of containers like Parts and bodies. Normally one would get this placement, and simply transforms the Vertex point with this placement by box.getGlobalPlacement().multVec(vertex.Point). HOWEVER, as shown in point 1, the vertex point already includes the box placement. Hence doing that would include this placement twice. So to get the correct placement which you can multiply with the vertex you need to remove the box placement from the global one. this works like this:
Code: Select all
p = Box.getGlobalPlacement().multiply(Box.Placement.inverse())
value = p.multVec(Box.Shape.Vertexes[0])
4. Alternative way: To avoid this hassle, simply make a copy of the box and assign it the correct global placement.
Code: Select all
newBox = Box
newBox.Placement = Box.getGlobalPlacement()
value = newBox.Shape.Vertexes[0]
Additional comment: What you see here is the result of an unfortunate mix of concepts (stack of local CS vs. global geometry values). This results from the fact, that the placement hirarchy was introduced later, and that it works different than what was available before. However, changing the how the parts work would break just too many things. Hence we need to live with that.