Skip to main content
13-Aquamarine
Dec 6, 2021 4:55 AM UTC
Solved

How to collect components at different level in assembly

Hello Friends, 

 

I have use ProSolidFeatureVisit() API  to find the component , but it collect component at first level , But I want to find the component at all level in assembly ,Please help me to resolve the issue.

 

Regards,

Kunal  

FV_01
FV_01Answer
Dec 6, 2021 5:56 PM UTC

You should take a look at UtilVisit.c in the examples. Copy/paste ProUtilAsmTravAction(...)

HIH.

FV_1-1638813310226.png

 

 

5 replies

24-Ruby IV
Dec 6, 2021 9:39 AM UTC

A similar question was previously - "Retrieve assembly components on all levels in Creo 2.0": https://community.ptc.com/t5/Customization/Retrieve-assembly-components-on-all-levels-in-Creo-2-0/td-p/14 

Translate
13-Aquamarine
Dec 6, 2021 10:16 AM UTC

I have see this post but I am struck in creation of visiting function for this API.

Can you please provide the visiting function for same.

 

Regards,

Kunal

Translate
FV_01
FV_0117-PeridotAnswer
Dec 6, 2021 5:56 PM UTC

You should take a look at UtilVisit.c in the examples. Copy/paste ProUtilAsmTravAction(...)

HIH.

FV_1-1638813310226.png

 

 

Translate
RPN
18-Opal
Dec 6, 2021 11:07 PM UTC

You call the visit functions for components, if your component is a PRO_ASSEMBLY you just call your function recursive again.  It’s a little bit like traverse a folder structure. But for sure not the same.

An assembly is like folder, but this folder can appear at the same level or in other levels with the same structure and multiple times. 

 

Sample Tcl Code

 

proc Get_Assy_Names {ASM} {
 # Vist the given assembly by components
 foreach FID [ps_visit type -model $ASM -- COMPONENT] {
 # Get the model name from this feature ID
 set MDL [ps_assy component_name -model $ASM -- $FID ]
 # If the MDL is an assembly, recursive call
 if { [ps_model is_assembly -model $MDL]} {
 Get_Assy_Names $MDL
 }
 }
 return
}

 

BTW: If you export, save the feature ids, you have the component path for each model in the assembly.

Translate
1-Visitor
Jan 3, 2022 10:27 AM UTC

Hi Kunal,

 

Use the function ProSolidFeatureVisit() recursively to collect components from all levels.

 

Example:

ProSolidFeatureVisit(Parent_asm, visit_action,filter_action,app_data){

    ProSolidFeatureVisit(child_asm, visit_action, filter_action, app_data)

         {

                       .........logic

          }

}

Translate