Coordinate transformation based on insertion point, normal, and rotation in VBA

Coordinate transformation based on insertion point, normal, and rotation in VBA

laufendenummer
Explorer Explorer
1,737 Views
2 Replies
Message 1 of 3

Coordinate transformation based on insertion point, normal, and rotation in VBA

laufendenummer
Explorer
Explorer

Hi all,

I have a drawing with blocks, that are 3D rotated around every axis. I need to get the global coordinates of vertices within these blocks.   

I know the local coordinates within a block and I understand how to get the block normal and rotation, but I have no idea how to get from insertion point, normal, rotation, and local coordinates to the transformed global coordinates.

I know, that there are some possibilities in c# but I need to do this in VBA.

Any hints?

0 Likes
Accepted solutions (1)
1,738 Views
2 Replies
Replies (2)
Message 2 of 3

Alexander.Rivilis
Mentor
Mentor
Accepted solution

Maybe this reference was useful for you: http://jprdintprev.autodesk.com/adn/servlet/devnote?siteID=4814862&id=5411274&linkID=4900509

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 3

laufendenummer
Explorer
Explorer

Amazing! I rewrote that for my purpose and it worked, thanks a lot! 

 

This is what my test code looks like:

Sub BlockTest()
'Block Rotated 25° around x
'Block Rotated -50° around y
'Block Rotated 75° around z
'InsertionPoint: x=7561, y=8476, -4675
'Local Point in OCS: x=1250,y=1000, z=-1455
'Measured Solution  X = 6121.91501579     Y = 8982.79425598     Z = -6208.53154201

Dim objEnt As AcadEntity
Dim objBlkRef As AcadBlockReference
Dim varInsPnt As Variant
Dim dblLocalPnt(0 To 2) As Double, dblTmp(0 To 2) As Double
Dim varTransPnt As Variant

dblLocalPnt(0) = 1250
dblLocalPnt(1) = 1000
dblLocalPnt(2) = -1455

For Each objEnt In ThisDrawing.ModelSpace
   If TypeOf objEnt Is AcadBlockReference Then
       If objEnt.Name = "TEST" Then
           Set objBlkRef = objEnt
           Exit For
       End If
   End If
Next

varInsPnt = objBlkRef.InsertionPoint

dblTmp(0) = dblLocalPnt(0) * Math.Cos(objBlkRef.Rotation) - dblLocalPnt(1) * Math.Sin(objBlkRef.Rotation)
dblTmp(1) = dblLocalPnt(0) * Math.Sin(objBlkRef.Rotation) + dblLocalPnt(1) * Math.Cos(objBlkRef.Rotation)
dblTmp(2) = dblLocalPnt(2)

varTransPnt = ThisDrawing.Utility.TranslateCoordinates(dblTmp, acOCS, acWorld, False, objBlkRef.Normal)
varTransPnt(0) = varTransPnt(0) + varInsPnt(0)
varTransPnt(1) = varTransPnt(1) + varInsPnt(1)
varTransPnt(2) = varTransPnt(2) + varInsPnt(2)

End Sub
0 Likes