0

I have an CATIA assembly created automatically by VBA Excel. Now I need to add 6 same bolts to that, for example. Theoretically, I can add some pieces of VBA code to create each bolt in that assembly as the separate one, which seems to be so cumbersome. Is it possible to create a bolt (not saved yet, because I want to see how it is in 3D CAITA environment first) and make copies of it as the others in the assembly, like the way we often do interactively in CATIA. If possilbe, please tell me how to do that. Many thanks!

  • 1
    Please have a look on the _AddComponent_ method of the products collection. – Shrotter Oct 03 '22 at 15:35
  • Yes, I did, but had an error expressed as "automation error (error 440)" and I am not aware of its reason. My code is as below: Set product1_3 = products1.AddNewComponent("Part", "Bolt1") -----(create the product1_3) 'copy product1_3 Set product1_4 = products1.AddComponent(product1_3) – Hung Pham Vu Oct 03 '22 at 17:16
  • Use the reference product instead of the instance product (e.g. _product1_3.ReferenceProduct_) in the AddComponent method. – Shrotter Oct 03 '22 at 17:42

1 Answers1

0

If I understand your request correctly, you would like to have 6 copies of the not yet saved CATPart in the Assembly.

You can achieve this with a simple copy/paste.

For example:

Sub CATMain()

Dim oDoc As Document
Dim oSel As Object
Dim aFilter(0)
Dim oSelected
Dim oRef As Reference

Set oDoc = CATIA.ActiveDocument

Set oSel = oDoc.Selection
oSel.Clear

aFilter(0) = "Product"

oSelected = oSel.SelectElement2(aFilter, "Select Object in the tree which you want to insert six times or ESC..", True)
If oSelected = "Cancel" Then
    Debug.Print "KO"
    Exit Sub
End If

oSel.Copy

Dim i As Integer
For i = 0 To 6
    oSel.Clear
    oSel.Add oDoc.Product
    oSel.Paste
Next

End Sub

You can of course replace the system to pick product you want to copy to the automatic way, depend on your demanded logic.

JMan
  • 60
  • 7