JordanCaron
Aerospace
Hi guys,
I already have a macro to create a CATPRODUCT from an ALL.CATPART.
Unfortunately the macro replace every body in the ALLCATPART by a CATPART and add it to a PRODUCT.
Here is my issue. I have an ALLCATPART with 1000 bodies but only 3 differents geometry. So if I run my macro it will create 1000 CATPART with different axis system.
I would love to have a Macro that create only 3 CATPART and put them in position in the CATPRODUCT.
Here is the cat vba I have, but it's not usefull in my situation.
'L'objectif de la macro est de créer un assemblage multipart à partir d'une piece multi body
'********************************************************************************************
'Recuperation du document à decomposer
Dim les_docs As Documents
Set les_docs = CATIA.Documents
On Error Resume Next
Dim part_doc As PartDocument
Dim lapart As Part
Set part_doc = CATIA.ActiveDocument
If Err.Number = 0 Then
'c'est une part
Set lapart = part_doc.Part
Else
'c'est un produit
Err.Clear
Dim pdt_doc As ProductDocument
Set pdt_doc = CATIA.ActiveDocument
Dim pdt As Product
Set pdt = pdt_doc.Product
Dim lesprods As Products
Set lesprods = pdt.Products
Set lapart = lesprods.Item(1).ReferenceProduct.Parent.Part
End If
'********************************************************************************************
'********************************************************************************************
'Recuperation du nom de la part multi corps et création du produit correspondant
Dim Prod_doc As ProductDocument
Set Prod_doc = les_docs.Add("Product")
Prod_doc.Product.PartNumber = lapart.Name
If Err.Number <> 0 Then
MsgBox "Renommage du document créé impossible" & vbCrLf & "Vérifiez si un document avec un nom identique ne figure pas déjà dans la session..."
CATIA.DisplayFileAlerts = False
CATIA.Documents.Item(Prod_doc.Name).Close
Err.Clear
Exit Sub
End If
'********************************************************************************************
'********************************************************************************************
'Recuperation des Body non vide , creation d'une part dans le product , renommage de la part et Copier Coller Avec ou sans lien
Dim Msg, Style, Title, Response, nombody As String
Msg = "Souhaitez-vous des liens entre pièces?"
Style = vbYesNo + vbDefaultButton2 ' Définit les boutons.
Title = "Associativité... " ' Définit le titre.
Response = MsgBox(Msg, Style, Title) ' Affiche le message.
For i = 1 To lapart.Bodies.Count
If lapart.Bodies.Item(i).InBooleanOperation = False And lapart.Bodies.Item(i).Shapes.Count <> 0 Then
nombody = lapart.Bodies.Item(i).Name
If InStr(nombody, "\") <> 0 Then nombody = Replace(nombody, "\", "_")
Prod_doc.Product.Products.AddNewComponent "CATPart", nombody
If Response = vbYes Then
' L'utilisateur a choisi des liens.
CCLV2 Prod_doc.Product, lapart.Bodies.Item(i), Prod_doc.Product.Products.Item(Prod_doc.Product.Products.Count)
Else
' L'utilisateur a choisi pas de liens
CCLV1 Prod_doc.Product, lapart.Bodies.Item(i), Prod_doc.Product.Products.Item(Prod_doc.Product.Products.Count)
End If
End If
Next
Prod_doc.Product.Update
'********************************************************************************************
End Sub
Public Sub CCLV1(Context As Product, i_object_to_copy, CibleProd As Product)
Set oselection = Context.ReferenceProduct.Parent.Selection
Set oTargetPart = CibleProd.ReferenceProduct.Parent.Part
oselection.Clear
oselection.Add i_object_to_copy
'MsgBox oSelection.Count & ObjtoCCLname
oselection.Copy
oselection.Clear
oselection.Add oTargetPart
oselection.PasteSpecial "CATPrtResultWithOutLink"
End Sub
Public Sub CCLV2(Context As Product, i_object_to_copy, CibleProd As Product)
Set oselection = Context.ReferenceProduct.Parent.Selection
Set oTargetPart = CibleProd.ReferenceProduct.Parent.Part
oselection.Clear
oselection.Add i_object_to_copy
'MsgBox oSelection.Count & ObjtoCCLname
oselection.Copy
oselection.Clear
oselection.Add oTargetPart
oselection.PasteSpecial "CATPrtResult"
End Sub
Please can you help me ?
Do you have a macro that could do what I need ?
Best regards,
Jordan Caron
I already have a macro to create a CATPRODUCT from an ALL.CATPART.
Unfortunately the macro replace every body in the ALLCATPART by a CATPART and add it to a PRODUCT.
Here is my issue. I have an ALLCATPART with 1000 bodies but only 3 differents geometry. So if I run my macro it will create 1000 CATPART with different axis system.
I would love to have a Macro that create only 3 CATPART and put them in position in the CATPRODUCT.
Here is the cat vba I have, but it's not usefull in my situation.
'L'objectif de la macro est de créer un assemblage multipart à partir d'une piece multi body
'********************************************************************************************
'Recuperation du document à decomposer
Dim les_docs As Documents
Set les_docs = CATIA.Documents
On Error Resume Next
Dim part_doc As PartDocument
Dim lapart As Part
Set part_doc = CATIA.ActiveDocument
If Err.Number = 0 Then
'c'est une part
Set lapart = part_doc.Part
Else
'c'est un produit
Err.Clear
Dim pdt_doc As ProductDocument
Set pdt_doc = CATIA.ActiveDocument
Dim pdt As Product
Set pdt = pdt_doc.Product
Dim lesprods As Products
Set lesprods = pdt.Products
Set lapart = lesprods.Item(1).ReferenceProduct.Parent.Part
End If
'********************************************************************************************
'********************************************************************************************
'Recuperation du nom de la part multi corps et création du produit correspondant
Dim Prod_doc As ProductDocument
Set Prod_doc = les_docs.Add("Product")
Prod_doc.Product.PartNumber = lapart.Name
If Err.Number <> 0 Then
MsgBox "Renommage du document créé impossible" & vbCrLf & "Vérifiez si un document avec un nom identique ne figure pas déjà dans la session..."
CATIA.DisplayFileAlerts = False
CATIA.Documents.Item(Prod_doc.Name).Close
Err.Clear
Exit Sub
End If
'********************************************************************************************
'********************************************************************************************
'Recuperation des Body non vide , creation d'une part dans le product , renommage de la part et Copier Coller Avec ou sans lien
Dim Msg, Style, Title, Response, nombody As String
Msg = "Souhaitez-vous des liens entre pièces?"
Style = vbYesNo + vbDefaultButton2 ' Définit les boutons.
Title = "Associativité... " ' Définit le titre.
Response = MsgBox(Msg, Style, Title) ' Affiche le message.
For i = 1 To lapart.Bodies.Count
If lapart.Bodies.Item(i).InBooleanOperation = False And lapart.Bodies.Item(i).Shapes.Count <> 0 Then
nombody = lapart.Bodies.Item(i).Name
If InStr(nombody, "\") <> 0 Then nombody = Replace(nombody, "\", "_")
Prod_doc.Product.Products.AddNewComponent "CATPart", nombody
If Response = vbYes Then
' L'utilisateur a choisi des liens.
CCLV2 Prod_doc.Product, lapart.Bodies.Item(i), Prod_doc.Product.Products.Item(Prod_doc.Product.Products.Count)
Else
' L'utilisateur a choisi pas de liens
CCLV1 Prod_doc.Product, lapart.Bodies.Item(i), Prod_doc.Product.Products.Item(Prod_doc.Product.Products.Count)
End If
End If
Next
Prod_doc.Product.Update
'********************************************************************************************
End Sub
Public Sub CCLV1(Context As Product, i_object_to_copy, CibleProd As Product)
Set oselection = Context.ReferenceProduct.Parent.Selection
Set oTargetPart = CibleProd.ReferenceProduct.Parent.Part
oselection.Clear
oselection.Add i_object_to_copy
'MsgBox oSelection.Count & ObjtoCCLname
oselection.Copy
oselection.Clear
oselection.Add oTargetPart
oselection.PasteSpecial "CATPrtResultWithOutLink"
End Sub
Public Sub CCLV2(Context As Product, i_object_to_copy, CibleProd As Product)
Set oselection = Context.ReferenceProduct.Parent.Selection
Set oTargetPart = CibleProd.ReferenceProduct.Parent.Part
oselection.Clear
oselection.Add i_object_to_copy
'MsgBox oSelection.Count & ObjtoCCLname
oselection.Copy
oselection.Clear
oselection.Add oTargetPart
oselection.PasteSpecial "CATPrtResult"
End Sub
Please can you help me ?
Do you have a macro that could do what I need ?
Best regards,
Jordan Caron