Create Geometric Set and Parameters in every part in an assembly
Create Geometric Set and Parameters in every part in an assembly
(OP)
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?
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?





RE: Create Geometric Set and Parameters in every part in an assembly
indocti discant et ament meminisse periti
RE: Create Geometric Set and Parameters in every part in an assembly
https://www.youtube.com/watch?v=x9_pbfAIJac
Anybody have this code?
RE: Create Geometric Set and Parameters in every part in an assembly
But I have a really hard time modifying my codes to work from an assembly.
Here is the code:
CODE --> CATScript
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 SubAny advice would be greatly appreciated.
RE: Create Geometric Set and Parameters in every part in an assembly
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 --> CATScript
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Create Geometric Set and Parameters in every part in an assembly
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 --> CATScript
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 SubRE: Create Geometric Set and Parameters in every part in an assembly
CODE -->
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
indocti discant et ament meminisse periti