Sidtha
Aerospace
- Nov 25, 2012
- 36
Hello All,
I have created below VBA macro in excel for CATIA V5 to insert the parts from CADLib and place as per the co ordinates and vectors.
INPUT for macro:
My QUESTION:
Parts are inserting to particular location but not aligning properly.
Please help me to solve this.
Sub CATMain()
lastRow = WS.Cells(Rows.Count, 1).End(xlUp).Row
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products1 As Products
Set products1 = product1.Products
Dim product2 As Product
Set product2 = products1.Item(1)
'---Loop through every tree node for the current product (fasterner)
k = 3
For i = 1 To products1.Count
Set oCurrentTreeNode = products1.Item(i)
MyCurrFastner = oCurrentTreeNode.PartNumber
X = Left(MyCurrFastner, 2)
Y = UCase(Left(Cells(k, 40).Value, 2))
If X = Y Then
Bolt = UCase(Cells(k, 40).Value)
'Dim Xdir As Integer, Ydir As Integer, Zdir As Integer
Xdir = WS.Cells(k, 8).Value
Ydir = WS.Cells(k, 9).Value
Zdir = WS.Cells(k, 10).Value
'Dim Xe As Integer, Ye As Integer, Ze As Integer
Xe = WS.Cells(k, 5).Value
Ye = WS.Cells(k, 6).Value
Ze = WS.Cells(k, 7).Value
Dim move1
Set move1 = oCurrentTreeNode.Move
Set move1 = move1.MovableObject
Dim arrayOfVariantOfDouble1(11)
arrayOfVariantOfDouble1(0) = 1
arrayOfVariantOfDouble1(1) = 0
arrayOfVariantOfDouble1(2) = Xdir '-xdir
arrayOfVariantOfDouble1(3) = 0
arrayOfVariantOfDouble1(4) = 1
arrayOfVariantOfDouble1(5) = Ydir '+ydir
arrayOfVariantOfDouble1(6) = -(Xdir) '+xdir
arrayOfVariantOfDouble1(7) = -(Ydir) '-ydir
arrayOfVariantOfDouble1(8) = -(Zdir) '+zdir
arrayOfVariantOfDouble1(9) = Xe
arrayOfVariantOfDouble1(10) = Ye
arrayOfVariantOfDouble1(11) = Ze
Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble1
k = k + 1
End If
Next i
End Sub
Thanks in advance
I have created below VBA macro in excel for CATIA V5 to insert the parts from CADLib and place as per the co ordinates and vectors.
INPUT for macro:

My QUESTION:
Parts are inserting to particular location but not aligning properly.
Please help me to solve this.
Sub CATMain()
lastRow = WS.Cells(Rows.Count, 1).End(xlUp).Row
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products1 As Products
Set products1 = product1.Products
Dim product2 As Product
Set product2 = products1.Item(1)
'---Loop through every tree node for the current product (fasterner)
k = 3
For i = 1 To products1.Count
Set oCurrentTreeNode = products1.Item(i)
MyCurrFastner = oCurrentTreeNode.PartNumber
X = Left(MyCurrFastner, 2)
Y = UCase(Left(Cells(k, 40).Value, 2))
If X = Y Then
Bolt = UCase(Cells(k, 40).Value)
'Dim Xdir As Integer, Ydir As Integer, Zdir As Integer
Xdir = WS.Cells(k, 8).Value
Ydir = WS.Cells(k, 9).Value
Zdir = WS.Cells(k, 10).Value
'Dim Xe As Integer, Ye As Integer, Ze As Integer
Xe = WS.Cells(k, 5).Value
Ye = WS.Cells(k, 6).Value
Ze = WS.Cells(k, 7).Value
Dim move1
Set move1 = oCurrentTreeNode.Move
Set move1 = move1.MovableObject
Dim arrayOfVariantOfDouble1(11)
arrayOfVariantOfDouble1(0) = 1
arrayOfVariantOfDouble1(1) = 0
arrayOfVariantOfDouble1(2) = Xdir '-xdir
arrayOfVariantOfDouble1(3) = 0
arrayOfVariantOfDouble1(4) = 1
arrayOfVariantOfDouble1(5) = Ydir '+ydir
arrayOfVariantOfDouble1(6) = -(Xdir) '+xdir
arrayOfVariantOfDouble1(7) = -(Ydir) '-ydir
arrayOfVariantOfDouble1(8) = -(Zdir) '+zdir
arrayOfVariantOfDouble1(9) = Xe
arrayOfVariantOfDouble1(10) = Ye
arrayOfVariantOfDouble1(11) = Ze
Set move1Variant = move1
move1Variant.Apply arrayOfVariantOfDouble1
k = k + 1
End If
Next i
End Sub
Thanks in advance