0

I'm trying to rotate a part that is already positioned within a product structure, but I would like the rotation to occur around the part’s own local axis system, not the global axis.

The issue is that this rotation is applied relative to the global axis system, not the part’s local axis system.

Question:
How can I apply a rotation so that the part rotates around its own local axis rather than the global coordinate system?

Here is the code I'm currently using:

Set move1 = productToMove.Move
Set move1 = move1.MovableObject
Dim arrayOfVariantOfDouble1(11)

arrayOfVariantOfDouble1(0) = XCoord(0)
arrayOfVariantOfDouble1(1) = XCoord(1)
arrayOfVariantOfDouble1(2) = XCoord(2)

arrayOfVariantOfDouble1(3) = YCoord(0)
arrayOfVariantOfDouble1(4) = YCoord(1)
arrayOfVariantOfDouble1(5) = YCoord(2)

arrayOfVariantOfDouble1(6) = ZCoord(0)
arrayOfVariantOfDouble1(7) = ZCoord(1)
arrayOfVariantOfDouble1(8) = ZCoord(2)

arrayOfVariantOfDouble1(9) = Position(0)
arrayOfVariantOfDouble1(10) = Position(1)
arrayOfVariantOfDouble1(11) = Position(2)

Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble1
2
  • Where is no build-in method/function for such a transformation in the API. So consider to calculate the position/transformation matrix, or use several move-operations. Commented May 15 at 6:46
  • The focus is not on computing the transformation matrix itself, but on ensuring that the rotation is applied with respect to the local coordinate system of the part, not the global one. Commented May 15 at 7:13

2 Answers 2

0

To rotate a product along one local axis you could use a workaround:

  • get current position of product
  • move product to origin of assembly
  • rotate around needed axes
  • move product back using its previous position as transformation matrix
Sub CATMain()

Dim oRootDoc as ProductDocument
Dim oRootProduct as Product
Dim oChildProduct as Product
Dim ChildPosition (11)
Dim OriginPosition (11)
Dim RotationMatrix (11)

Set oRootDoc = CATIA.ActiveDocument
Set oRootProduct = oRootDoc.Product

'get first product to move
Set oChildProduct = oRootProduct.Products.Item(1)

'Save position of instance
oChildProduct.Position.GetComponents ChildPosition

'Set instance to origin
 OriginPosition( 0 )  = 1
 OriginPosition( 1 )  = 0
 OriginPosition( 2 )  = 0
 OriginPosition( 3 )  = 0
 OriginPosition( 4 )  = 1
 OriginPosition( 5 )  = 0
 OriginPosition( 6 )  = 0
 OriginPosition( 7 )  = 0
 OriginPosition( 8 )  = 1
 OriginPosition( 9 )  = 0
 OriginPosition( 10 ) = 0
 OriginPosition( 11 ) = 0

 oChildProduct.Position.SetComponents OriginPosition

'Move instance: e.g. Rotation 45 degrees around the x axis
 RotationMatrix( 0 )  = 1.000
 RotationMatrix( 1 )  = 0
 RotationMatrix( 2 )  = 0
 RotationMatrix( 3 )  = 0
 RotationMatrix( 4 )  = 0.707
 RotationMatrix( 5 )  = 0.707
 RotationMatrix( 6 )  = 0
 RotationMatrix( 7 )  = -0.707
 RotationMatrix( 8 )  = 0.707
 RotationMatrix( 9 )  = 0
 RotationMatrix( 10 ) = 0
 RotationMatrix( 11 ) = 0
 
 oChildProduct.Move.Apply RotationMatrix

 'Move instance using the position before rotation
 oChildProduct.Move.Apply ChildPosition

End Sub
Sign up to request clarification or add additional context in comments.

8 Comments

Hi, Thanks for the suggestion! Yes, that could work, but I’d prefer to solve it with a single positioning step if possible. I have one question about your code: Why do you use .GetComponent and .SetComponent for the first translation, but .Move for the second one? In my case, the GetComponent and SetComponent functions are marked as restricted.
If you want a single transformation step, you have to calculate the transformation matrix to this oriented axis (eg current orientation of the local x-axis in the global system)
I use a VBA function to rotate the Y-axis of the part around its X-axis. However, when I apply the resulting transformation matrix to the product, the part is not only rotated but also displaced from its original position. This occurs because the transformation matrix is defined in the part's local axis system, while in CATIA, the transformation is applied relative to the global axis system. I would appreciate it if someone could help me find a code snippet to compute the transformation matrix from the local to the global axis system, as Shrotter suggested.
Actually, would it not be sufficient to just determine the X, Y, and Z coordinates of the movement?
|
0

This issue can be resolved by using the .SetComponents method instead of .Move, as it provides the correct behavior in this context. The .Move method applies a relative transformation based on the part’s current position, while .SetComponents sets the absolute position of the part with respect to the global axis system.



Dim arrayOfVariantOfDouble1(11)
arrayOfVariantOfDouble1(0) = XCoord(0)
arrayOfVariantOfDouble1(1) = XCoord(1)
arrayOfVariantOfDouble1(2) = XCoord(2)

arrayOfVariantOfDouble1(3) = YCoord(0)
arrayOfVariantOfDouble1(4) = YCoord(1)
arrayOfVariantOfDouble1(5) = YCoord(2)

arrayOfVariantOfDouble1(6) = ZCoord(0)
arrayOfVariantOfDouble1(7) = ZCoord(1)
arrayOfVariantOfDouble1(8) = ZCoord(2)

arrayOfVariantOfDouble1(9) = Position(0)
arrayOfVariantOfDouble1(10) = Position(1)
arrayOfVariantOfDouble1(11) = Position(2)

Dim productToMoveObject As Object
Set productToMoveObject = productToMove.Position
productToMoveObject.SetComponents arrayOfVariantOfDouble1

1 Comment

This only works if you have calculated the new position before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.