".Move" gives me a headache.

Robbie vargo

".Move" gives me a headache.
Hi
I dont understand why everytime i run this script catia crashes.

i try to instantiate a CATPart and then move it (essentially a axis-axis snap) to a previously defined axis system.
If i record a macro and run it, it works fine.
Any advice would be nice.

Thanks
Varun Gopinath



Sub CATMain()
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Item("Bez_axis.CATPart")
Set part1 = partDocument1.Part
Set axisSystems1 = part1.AxisSystems
Set axisSystem1 = axisSystems1.Item("Axis_System_3")

Dim originCoord(2)
axisSystem1.GetOrigin originCoord
'msgbox(originCoord(2))

Dim AxisCoordX(2)
axisSystem1.GetXAxis AxisCoordX
Dim AxisCoordY(2) as variant
axisSystem1.GetXAxis AxisCoordY

Dim AxisCoordZ(2)
axisSystem1.GetXAxis AxisCoordZ

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim products1 As Products
Set products1 = product1.Products

Dim arrayOfVariantOfBSTR1(0) arrayOfVariantOfBSTR1(0) = "\\fillager.liu.se\vargo025\motor.CATPart"

products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"

Dim product2 As Product
Set product2 = products1.Item("Motor.1")

Dim move1 As Move
Set move1 = product2.Move
Set move1 = move1.MovableObject

Dim arrayOfVariantOfDouble1(11) as integer
arrayOfVariantOfDouble1(0) = AxisCoordX(0)
arrayOfVariantOfDouble1(1) = AxisCoordX(1)
arrayOfVariantOfDouble1(2) = AxisCoordX(2)

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

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

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

move1.Apply arrayOfVariantOfDouble1
'product2.referenceproduct.update
End Sub

 

Cliff Johnson, Cliff

RE: ".Move" gives me a headache.
(in response to Robbie vargo)
You are using GetXAxis 3 times instead of GetYAxis and GetZAxis.

Robbie vargo

RE: ".Move" gives me a headache.
(in response to Robbie vargo)
So i am going blind!!
You are right of ofcourse!!
thanks a lot!

Luiz Henrique Silva

RE: ".Move" gives me a headache.
(in response to Cliff Johnson, Cliff)

in fact, i found the answer in another thread - https://www.coe.org/p/fo/st/topic=113&post=17070#p17070

[by the way, some functions appears as "restricted in visual basic" like the mentioned above.

Does anyone know how to avoid this error?]

Attachments

  • restrictedautomation.jpg (35.4k)
Edited By:
Luiz Henrique Silva[Subscriber Members] @ Oct 25, 2022 - 03:05 PM (America/Sao_Paulo)

Josh Bender

RE: ".Move" gives me a headache.
(in response to Luiz Henrique Silva)

You must create an extra object of type variant to perform those functions.

Example:

Dim DumAxis as variant
set dumaxis = axisSystem1
dumaxis.getxaxis axiscoordz ....

Luiz Henrique Silva

RE: ".Move" gives me a headache.
(in response to Josh Bender)

thanks Josh!