I need to get all the Points2D and Lines2D endpoints coordinates inside a Sheet, including all those Points2d and Lines2d included inside BlockOccurrences placed on that Sheet.
As far as I see, there's no direct simple way of getting, for example, the "global" coordinates of each Point2d o Line2d sendpoints inside the different occurrences of all the blocks. A block can contain another blocks and each one can be rotated and scaled in different ways, which increases difficulty
One approach, not quite easy, is getting position (GetOrigin), ScaleFactor and RotationAngle of each occurrence and then apply those transformations to each of the points/lines inside it. This must be done recursively if we are dealing with blocks inside blocks and so on. Not an easy task.
The other approach is getting references of the different elements using MemberReference property of the BlockOccurrence, and using the transformation matrix provided in order to adjust coordinates to the upper level. Quite spare documentation about this matrix stuff, unfortunately. Also, I'm not sure about what happens with the scale in this case, since that matrix I guess only deals with position and rotation. Recursive thinking is also expected here... Not sure if this is even worse than the first choice!
Before getting absolutely mad with maths and testings, I would love to know if there's not really a simpler approach for getting the FINAL coordinates (refered to the main Sheet origin) of different geometric elements inside BlockOccurrences
i fear doing the math yourself is the only possibility.
It's not that difficult... Using the values of the BlockOccurrence you can transform the points of the 2d space of the occurrence plane to the space of the sheet:
Private Sub OccurrenceToSheet(BOcc As SEDraft.BlockOccurrence, xBlock As Double, yBlock As Double,
ByRef xSheet As Double, ByRef ySheet As Double)
Dim xOrig, yOrig As Double
Dim xOccOrig, yOccOrig As Double
Dim xTemp, yTemp As Double
Dim Angle As Double
Dim dSin As Double
Dim dCos As Double
' get the origin points
' transform point from block system relative to origin
xTemp = xBlock - xOrig
yTemp = yBlock - yOrig
xTemp = xTemp * BOcc.ScaleFactor
yTemp = yTemp * BOcc.ScaleFactor
Angle = BOcc.RotationAngle
If Angle <> 0.0 Then
dSin = Sin(Angle)
dCos = Cos(Angle)
xSheet = dCos * xTemp - dSin * yTemp
ySheet = dSin * xTemp + dCos * yTemp
xSheet = xTemp
ySheet = yTemp
xSheet = xSheet + xOccOrig
ySheet = ySheet + yOccOrig
If you are in some sub BlockOccurrence you have to test for the parent an do this "bottom up" until the parent is the sheet.
If you want to do this for a lot of points, then you can consider to generate a transformation matrix for each BlockOccurrence or sub BlockOccurrence to do this in one step. There are lots of examples on some math / geometry pages in the web.
Then you could do just a matrix multiply of the transformation matrix with each point to transform it.