Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Geometric Set and Parameters in every part in an assembly

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
235
US
I need to create two different Geometric Sets with 2 Parameters in each Geometric Set in every Part of my assembly.
These Geometric Sets will have the same names and parameters in every part.
The Parameters are used as standard notes in every part.

Is there a way to automate this process for large assemblies?
 
Replies continue below

Recommended for you

VBA could do that, but I would like to think EKL can do it.

Eric N.
indocti discant et ament meminisse periti
 
I have created the code to do exactly what I want when ran on a part.
But I have a really hard time modifying my codes to work from an assembly.

Here is the code:
Code:
Language="CATSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "GeoSet1"
Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
Dim strParam1 As StrParam
Set strParam1 = parameters1.CreateString("Name1", "XXX")
part1.Update 
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Clear 
selection1.Add strParam1
selection1.Cut 
Set partDocument1 = CATIA.ActiveDocument
Dim selection2 As Selection
Set selection2 = partDocument1.Selection
selection2.Clear 
selection2.Add hybridBody1
selection2.Paste 

part1.Update 

Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "GeoSet2"
Set parameters1 = part1.Parameters
Set strParam1 = parameters1.CreateString("Name2", "XXX")
part1.Update 
Set partDocument1 = CATIA.ActiveDocument
Dim selection4 As Selection
Set selection4 = partDocument1.Selection
selection4.Clear 
selection4.Add strParam1
selection4.Cut 
Set partDocument1 = CATIA.ActiveDocument
Dim selection5 As Selection
Set selection5 = partDocument1.Selection
selection5.Clear 
selection5.Add hybridBody1
selection5.Paste 


Set parameters1 = part1.Parameters
Set strParam1 = parameters1.CreateString("Name3", "XXX")
part1.Update 
Set partDocument1 = CATIA.ActiveDocument
Dim selection7 As Selection
Set selection7 = partDocument1.Selection
selection7.Clear 
selection7.Add strParam1
selection7.Cut 
Set partDocument1 = CATIA.ActiveDocument
Dim selection8 As Selection
Set selection8 = partDocument1.Selection
selection8.Clear 
selection8.Add hybridBody1
selection8.Paste 


Set parameters1 = part1.Parameters
Set strParam1 = parameters1.CreateString("Name4", "XXX")
part1.Update 
Set partDocument1 = CATIA.ActiveDocument
Dim selection10 As Selection
Set selection10 = partDocument1.Selection
selection10.Clear 
selection10.Add strParam1
selection10.Cut 
Set partDocument1 = CATIA.ActiveDocument
Dim selection11 As Selection
Set selection11 = partDocument1.Selection
selection11.Clear 
selection11.Add hybridBody1
selection11.Paste 
End Sub

Any advice would be greatly appreciated.
 
Hi,

You can clean a little bit what you recorded and also I believe that was not doing exactly what you want. Please check code below. Could be even more shorter but I'll let as it is. Now, think a little bit of the next part of the code for assembly. What if this will be a subroutine in another macro? Search for all parts in assy one by one and call this subroutine? Be aware there is no relation between your parameters (so if you modify something in Parameters will be not reflected in GeoSet and vice-versa) and this is done when you are in an active CATPart document.

Code:
Language="CATSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
    Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
    Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Dim parameters1 As Parameters
    Set parameters1 = part1.Parameters
Dim strParam1 As StrParam
Dim selection1 As Selection
Dim selection2 As Selection
    Set selection1 = partDocument1.Selection
    Set selection2 = partDocument1.Selection
'~ ''''''''''''''''''''''''''''''
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "GeoSet1"
    Set strParam1 = parameters1.CreateString("Name1", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Copy 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 
    Set strParam1 = parameters1.CreateString("Name2", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Copy 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 
'~ ''''''''''''''''''''''''''''''
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "GeoSet2"
    Set strParam1 = parameters1.CreateString("Name3", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Copy 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 
    Set strParam1 = parameters1.CreateString("Name4", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Copy 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 

End Sub

Regards
Fernando

- Romania
- EU
 
Ferdo,

Actually the code i had did exactly what i needed , I tweaked the cleaned up code you provided to do what i need.
I want the parameters to be created and moved out of the parameter set and into the specified Geo Set.
This will be used to put Standard Notes in the Geo Sets, like the Customer Program Codes, Address, and Proprietary Notess.

Here is my updated code with an attempt at making it work in the assembly.
It runs without errors...but doesn't do anything...
I have always struggled with Assembly Macros and this one is not any different.
Thanks in advance for any help.
Code:
Language="CATSCRIPT"
Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument

  If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
     MsgBox "Active CATIA Document is not a Product. Open a Product file and run this script again.", , msgboxtext
     Exit Sub
   End If
   Call CycleThroughParts(productDocument1.Product)
End Sub



Sub CycleThroughParts(current_prod)
If current_prod.Products.Count > 0 Then
For i = 1 To current_prod.Products.Count
Call CycleThroughParts(current_prod.Products.Item(i))

Next 
End If
End Sub 



Sub CreateNotes()

    Set (current_prod.Products.Item(i)) = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
    Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Dim parameters1 As Parameters
    Set parameters1 = part1.Parameters
Dim strParam1 As StrParam
Dim selection1 As Selection
Dim selection2 As Selection
    Set selection1 = partDocument1.Selection
    Set selection2 = partDocument1.Selection
'~ ''''''''''''''''''''''''''''''
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "GeoSet1"
    Set strParam1 = parameters1.CreateString("Name1", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Cut 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 
'~ ''''''''''''''''''''''''''''''
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "GeoSet2"

    Set strParam1 = parameters1.CreateString("Name2", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Cut 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 
    Set strParam1 = parameters1.CreateString("Name3", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.cut 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 
    Set strParam1 = parameters1.CreateString("Name4", "XXX")
        selection1.Clear 
        selection1.Add strParam1
        selection1.Cut 
        selection2.Clear 
        selection2.Add hybridBody1
        selection2.Paste 


End Sub
 
Code:
Sub CycleThroughParts(current_prod)
[b]If current_prod.Products.Count > 0 Then[/b]
For i = 1 To current_prod.Products.Count
Call CycleThroughParts(current_prod.Products.Item(i))

Next 
End If
End Sub

this is cycling through product structure but nothing else, you should do something if the product does not have any child (meaning it is a instance carrying a part - hmm you should also check this just in case you have empty product)

so if current_prod.Products.Count = 0 Then try to call CreateNotes passing the part as an argument, in fact you should check if the part is in a collection(/dictionary) and if not add it to collection and call the sub, this will avoid to call the sub on the same part (but different instance) several times. ... thinking about that you can do the same for the product you test, this would avoid working on product already done...

You should modify the CreateNotes sub to receive the argument.

please post your progress

Hope this help

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top