Skip to main content
16-Pearl
February 7, 2020
Solved

"Macro" to hide part in a .asm based on its name

  • February 7, 2020
  • 1 reply
  • 1646 views

To all

I am trying to understand the effort required to write a “macro” to automate a task in CREO 5.0. I have code countless simple macros in vba for excel and for the  CAD system I am using – So I ma not a total beginner
What I have in mind

Given the active assembly (.asm)
Loop through each part in the tree
Get the name of the part
 If the name of the part exists in a given list then hide the part
Else do nothing



 

 

Can this be done? Is anyone willing to provide the few lines of code for such task (I am guessing that there are specific Classes, properties , etc ). The list I have in mind will be a

Dim ListofName As New List(of String)

 

 which will contains specific/fixed name

 

Thanks

Regards

Best answer by syalagudri

Check the sample code from Creo installation directory:

Common Files\vbapi\vbapi_examples\pfcAssembliesExamples.vb

 

            '======================================================================
            'Loop through all the components and create replace operations for any
            'instance of the model found
            '======================================================================
            components = assembly.ListFeaturesByType(False, EpfcFeatureType.EpfcFEATTYPE_COMPONENT)
            For i = 0 To components.Count - 1
                component = components.Item(i)
                modelDesc = component.ModelDescr
                If modelDesc.InstanceName = oldInstance Then
                    replace = component.CreateReplaceOp(newModel)                   
                    replaceOperations.Insert(0, replace)
                End If
            Next

1 reply

14-Alexandrite
February 7, 2020

Check the sample code from Creo installation directory:

Common Files\vbapi\vbapi_examples\pfcAssembliesExamples.vb

 

            '======================================================================
            'Loop through all the components and create replace operations for any
            'instance of the model found
            '======================================================================
            components = assembly.ListFeaturesByType(False, EpfcFeatureType.EpfcFEATTYPE_COMPONENT)
            For i = 0 To components.Count - 1
                component = components.Item(i)
                modelDesc = component.ModelDescr
                If modelDesc.InstanceName = oldInstance Then
                    replace = component.CreateReplaceOp(newModel)                   
                    replaceOperations.Insert(0, replace)
                End If
            Next

16-Pearl
February 7, 2020

Thanks a lot for that. Will have a good look