cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get all the child elements of a model

SOLVED

How to get all the child elements of a model

Attach the used model and code.
If the subelement of the model is an assembly, you want to recursively call the function to perform a specific task.
Levels 1 and 2 work safely.

InLevel2.gif
At level 3 or higher, the function is infinite.

OutLeve3.gif
UgAsmCompVisit_c does not help me.

It is not appropriate for us to fetch information from the session model.(ProSessionMdlList)

 

Therefore, ProSelect attempts to visit the sub-elements of the selected model.
Help.. plz...

 

ProError checkDependenciesToList(ProMdl mdl , char name[80], char value[80]) //저장된 mdllistarray_to_add의 &주소값을 읽는다
{
	ProError status;
	int deps_counteps_count,iDeps=0,deps_count;
	ProModel*  deps;    
	ProModelitem mdlitem;
	int result;
	ProMdl sub_mdl;
	char var[80],var2[10],tr[80],tr2[80],c_name_[80];
	ProParamvalue pval;
	ProParameter param;
	wchar_t p_value[80];
	ProName p_name,mdl_name;
	strcpy(tr, name);
	strcpy(tr2, value);
	//ProWstringToString(var,name);
	ProStringToWstring(p_value,value);
	ProStringToWstring(p_name,name);
	status = ProParamvalueSet(&pval,p_value,PRO_PARAM_STRING);
	ProMdlNameGet(mdl,mdl_name);
	ProWstringToString(c_name_,mdl_name);
	TestDialog(c_name_);
	status = ProMdlDependenciesList (mdl, &deps, &deps_count);	
	if (status == PRO_TK_NO_ERROR && deps_count > 0)
	{		
		for (iDeps = 0; iDeps < deps_count; iDeps++)
		{ 			
			
			ProWstringToString(var2 , deps[iDeps].type);
			if(!strcmp(var2,"PRT"))
			{
				status = ProMdlInit(deps [iDeps].name, PRO_MDL_PART, &sub_mdl);	
				status = ProMdlToModelitem(sub_mdl,&mdlitem);
				status = ProParameterCreate(&mdlitem,p_name,&pval,&param);
			}
			else if(!strcmp(var2,"ASM"))
			{				
				status = ProMdlInit(deps [iDeps].name, PRO_MDL_ASSEMBLY, &sub_mdl);	
				status = ProMdlToModelitem(sub_mdl,&mdlitem);
				status = ProParameterCreate(&mdlitem,p_name,&pval,&param);
				status = ProModelitemMdlGet(&mdlitem, &sub_mdl);
				checkDependenciesToList(sub_mdl ,tr,tr2);
			}		
		}
	}
	return 0; 
}



ProError Test()
{
	ProMdl *mdl_arr,mdl;
	ProModelitem mdlitem;
	ProSelection *proselect;
	ProError status;
	ProName name;
	ProParamvalue pval;
	ProParameter param;
	int selectcount, mdl_arr_size;
	char c_name[80],c_value[80];
	wchar_t value[80];
	status = ProSelect("prt_or_asm",1,NULL,NULL,NULL,NULL,&proselect,&selectcount);
	if(status == PRO_TK_NO_ERROR)
	{
	status = ProSelectionModelitemGet(proselect[0],&mdlitem);
	status = ProModelitemMdlGet(&mdlitem, &mdl);
	
	ProMessageDisplay(MSGFIL, (char *)"USER %0s", (char *)"Enter the parameter name: " );
	ProMessageStringRead(32,name);
	
	ProMessageDisplay(MSGFIL, (char *)"USER %0s", (char *)"Enter the parameter value: " );
	ProMessageStringRead(32,value);
	ProWstringToString(c_name, name);
	ProWstringToString(c_value, value);
	status = ProParamvalueSet(&pval,value,PRO_PARAM_STRING);
	status = ProParameterCreate(&mdlitem,name,&pval,&param);

	checkDependenciesToList(mdl,c_name, c_value);
  
	/*
	ProArraySizeGet((ProArray*)mdl_arr,&mdl_arr_size);
	itoa(mdl_arr_size,c,10);
	TestDialog(c);
	*/

	TestDialog("Done");
	}

}
Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to get all the child elements of a model

By declaring and comparing one more array, we avoided an infinite loop.

6 REPLIES 6

Re: How to get all the child elements of a model

By declaring and comparing one more array, we avoided an infinite loop.

Re: How to get all the child elements of a model

What do you want to archive at the end?

Re: How to get all the child elements of a model

What do you mean?
I do not understand well ..

Re: How to get all the child elements of a model

Could you describe in a couple of sentences what the app should do at the end?

Re: How to get all the child elements of a model

The core of the functionality is to get the components that correspond to all levels of the assembly.
When using recursive with ProMdlDependenciesList, the assembly structure of level 3 or higher is infinite.

 

We used ProMdlDependenciesList () in do-while without using recursion.

 

Assembly Arrangement for Comparison There is an assembly array asmarr for which you need to perform cmparr and ProMdlDependenciesList ().
In do-while statements, the entries in asmarr perform ProMdlDependenciesList ().
If there are subassemblies, compare them with the list in cmparr and add the models to cmparr and asmarr if they are not duplicates.

 

The end of do-while removes the asmarr one by one.

 

So at the end you will have subassemblies of all assemblies at cmparr.
Likewise, parts were also available.

 

Was the answer to your question?

Re: How to get all the child elements of a model

Hello Chaseon, use FeatVisit and check for a component, the Dependencies List does not return a valid structure to parse the assembly.

 

A script, build for restart over and over (I used your Windchill Data):

 

proc Creo_Visit_Component_Tree {Model Parent {Path {}} } {
	set CompIDs [ps_visit type -model $Model -- component]
	foreach CompID $CompIDs {
		set name [ps_assy component_name -model $Model -- $CompID]
		set TID $Parent.$CompID
		.tree insert $Parent end -id $TID -text $name
		set EXT [string range $name end-2 end]
		Debug "Cur Path '$Path' CompID $CompID name $name EXT $EXT"
		if {[string equal $EXT ASM] } {
			set LocPath $Path
			lappend LocPath $CompID
			Creo_Visit_Component_Tree $name $TID $LocPath 
		}
	}
}

destroy .tree
ttk::treeview .tree 
pack .tree -side top -expand yes -fill both
set cur [ps_model cur]
.tree insert {} end -id ID0 -text $cur

Creo_Visit_Component_Tree $cur ID0

 

Have fun to do this in Toolkit Smiley Very Happy

Imáge for the ID's to validate

 

Elevator.png

First lines of the log: (Here you can see how the component path will be build, based on the toplevel assy)

Cur Path '' CompID 39 name STRUCTURE.PRT EXT PRT
Cur Path '' CompID 40 name CAR.ASM EXT ASM
Cur Path '40' CompID 471 name CAR_FRAMEWORK.ASM EXT ASM
Cur Path '40 471' CompID 26 name WALL_CORNER.PRT EXT PRT
Cur Path '40 471' CompID 28 name WALL_CORNER.PRT EXT PRT
Cur Path '40 471' CompID 30 name WALL_CORNER.PRT EXT PRT
Cur Path '40 471' CompID 32 name WALL_CORNER.PRT EXT PRT
Cur Path '40 471' CompID 34 name SUPPORT_BEAM_LARGE.PRT EXT PRT
Cur Path '40 471' CompID 36 name SUPPORT_BEAM_LARGE.PRT EXT PRT
Cur Path '40 471' CompID 38 name SUPPORT_BEAM_SMALL.PRT EXT PRT
Cur Path '40 471' CompID 40 name SUPPORT_BEAM_SMALL.PRT EXT PRT
Cur Path '40' CompID 474 name PANEL_STRUCTURE_SIDE.ASM EXT ASM
Cur Path '40 474' CompID 22 name CAR_WALL_PANEL.PRT EXT PRT
Cur Path '40 474' CompID 56 name SIDE_PANNEL_WALL.PRT EXT PRT
Cur Path '40 474' CompID 38 name INT_SIDE_PANEL.PRT EXT PRT
Cur Path '40 474' CompID 120 name INT_SIDE_PANEL_2.PRT EXT PRT
Cur Path '40 474' CompID 124 name INT_SIDE_PANEL_3.PRT EXT PRT

 

(view in My Videos)