Converting Local Coordinates to Global Coordinates in CATIA VBA

Below is the revised code. Apologies for the delay. I have simplified it to only focus on the coordinate transformation. There are two functions and a sub. The two functions involve mathematical calculations, specifically the 3x3 matrix inverse and determinant. You can replace them with your preferred ones if needed. The sub Coord_Transform is responsible for the actual coordinate transformation.


The arguments for the sub are as follows:

1. aRel() As Double: Matrix containing coordinates relative to the CATPart's axis system. These are typically obtained using the GetCoordinates method on a Point. The coordinates are as follows: aRel(0) for X, aRel(1) for Y, and aRel(2) for Z. You may need to convert variant types to double to avoid type mismatch.

2. aAbs() As Double: Matrix containing coordinates relative to the Axis System of the top-level CATProduct. This matrix will be empty initially and will be properly filled by the sub. Once again, the coordinates are aAbs(0) for X, aAbs(1) for Y, and aAbs(2) for Z.

3. oProduct As Product: This refers to the CATPart's Product. For example, if you are measuring the coordinates of "Point.1" in a CATPart named "Part.1", which is the first instance in a CATproduct named "RootProduct", then oProduct=RootProduct.Products.Item(1).

4. bRecursively As Boolean: This is True if you want to calculate the coordinates with respect to the top-level Product, regardless of the depth of your CATPart. It should be False if you want to calculate the coordinates only with respect to the CATPart's father Product.


You can simply paste the code in yours and call the Coord_Transform sub with the appropriate arguments. If needed, there is a similar routine that calculates coordinates considering different Axis Systems in a CATPart using the same matrix transformations. Hope this helps! Regards.


'---CODE START------------------------------------------------------

Function Det3x3(dX11 As Double, dX12 As Double, dX13 As Double, _ dX21 As Double, dX22 As Double, dX23 As Double, _ dX31 As Double, dX32 As Double, dX33 As Double) As Double

'3x3 matrix determinant calculation (direct)

Det3x3 = dX11 * dX22 * dX33 + dX12 * dX23 * dX31 + dX21 * dX32 * dX13 - _ dX13 * dX22 * dX31 - dX12 * dX21 * dX33 - dX23 * dX32 * dX11

End Function


Function Inv3x3(dX11 As Double, dX12 As Double, dX13 As Double, _ dX21 As Double, dX22 As Double, dX23 As Double, _ dX31 As Double, dX32 As Double, dX33 As Double, aInv() As Double) As Boolean

'3x3 matrix inverse calculation (direct)

Dim dDet As Double ReDim aInv(8) Inv3x3 = False dDet = Det3x3(dX11, dX12, dX13, dX21, dX22, dX23, dX31, dX32, dX33) if dDet = 0 Then Exit Function

aInv(0) = (dX22 * dX33 - dX23 * dX32) / Abs(dDet) aInv(1) = (dX13 * dX32 - dX12 * dX33)

' ... (continuing the code with the remaining lines)

End Function

Sub Coord_Transform(aRel() As Double, aAbs() As Double, oProduct As Product, bRecursively As Boolean)

' (continuing the code with the remaining lines)

End Sub"

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空