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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Is there a function that loads a list of models?

CHASEONHO
18-Opal

Is there a function that loads a list of models?

You can use ProSessionMdlList () to get all the objects that exist in the session.


Can I get a list of selected items rather than a list of all the objects that exist in the session?
For example, if prt is selected, only prt is imported; if asm is selected, sub-components are imported.

 

thankㄴ

1 ACCEPTED SOLUTION

Accepted Solutions

Hi ,

I am not sure if you correctly understand the goal here but will comment so far I understood it.

- if you have a model which is not loaded in session , there is no funciton in Toolkit to found out which models are depended to it.

-the dependencies is mostly in one direction from top -> subassemblies - and components. 

- so when you load a component in session( let sey using ProMdlLoad or ProMdlRetrieve) - Creo parametric will try to load all dependend components which are required for the display in Creo Parametric.

-When you have a model in session you can use the function  ProMdlDependenciesDataList()

The function ProMdlDependenciesDataList() provides an array of ProMdl handles to the models in memory upon which a specified model depends. One model depends on another if its contents reference that model in some way. For example, an assembly depends on the models that form its components, and a drawing model depends on the solid models contained in it. Sometimes, two models can be mutually dependent, such as when a model feature
references a geometry item in a parent assembly. Clean the dependencies in the
database using the function ProMdlDependenciesCleanup() to get an accurate list of dependencies for an object in the Creo Parametric workspace.
Use the function ProMdlDependenciesCleanup() to clean the dependencies for an object in the Creo Parametric workspace.

- you can use the function ProMdlErase()
• ProMdlEraseNotDisplayed()
• ProMdlEraseAll()

To erase model from session.

So for example you can do some test by loading a model then analyses it with the function ProMdlDependenciesDataList() and write the information about the dependencies to a file and remove all files from session. For the next time you will have already outside the session an information about a model and its dependencies.

 

 

View solution in original post

8 REPLIES 8

Hi ,

I am not sure if you correctly understand the goal here but will comment so far I understood it.

- if you have a model which is not loaded in session , there is no funciton in Toolkit to found out which models are depended to it.

-the dependencies is mostly in one direction from top -> subassemblies - and components. 

- so when you load a component in session( let sey using ProMdlLoad or ProMdlRetrieve) - Creo parametric will try to load all dependend components which are required for the display in Creo Parametric.

-When you have a model in session you can use the function  ProMdlDependenciesDataList()

The function ProMdlDependenciesDataList() provides an array of ProMdl handles to the models in memory upon which a specified model depends. One model depends on another if its contents reference that model in some way. For example, an assembly depends on the models that form its components, and a drawing model depends on the solid models contained in it. Sometimes, two models can be mutually dependent, such as when a model feature
references a geometry item in a parent assembly. Clean the dependencies in the
database using the function ProMdlDependenciesCleanup() to get an accurate list of dependencies for an object in the Creo Parametric workspace.
Use the function ProMdlDependenciesCleanup() to clean the dependencies for an object in the Creo Parametric workspace.

- you can use the function ProMdlErase()
• ProMdlEraseNotDisplayed()
• ProMdlEraseAll()

To erase model from session.

So for example you can do some test by loading a model then analyses it with the function ProMdlDependenciesDataList() and write the information about the dependencies to a file and remove all files from session. For the next time you will have already outside the session an information about a model and its dependencies.

 

 

@RolandRaytchev

ProMdlDependenciesDataList return one level component

if asemmbly file include another assembly as component file didn't find two level component

iif i select top assembly i want return all components

i can't find that api

any suggestion? 

thanks

Yes , this is one level api. But remember an assembly is also one level. If you consider  the feature tree. So a component  (ProAsmcomp) is a feature from type  (PRO_FEAT_COMPONENT). So also if you for example visit and assembly in this case to be able to find all copoments and subcomponents in all level -  you need to check the type of the model and if it is itself an assembly (in this case subassembly) you have to visit it recursively . This appraoch belongs to the basis of Pro/TOOLKIT  when we handle some assemlies. Ok there is also the ProAsmcomppath where you can also specify some deph of structure (maximum 25 levels) for some selections and other objects but we can not used it for the search.

So the solution in your case is also simple. You need to do the search recursively which does not required to much addtional code - so the code should be some thing like this below:

...
int checkDependenciesToList(ProMdl mdl , ProMdl **mdllistarray_to_add)
{int deps_counteps_count,iDeps;
 ProMdlfileType *filetypes;
 ProMdlnameShortdata*  deps;
 int result;
 ProMdl sub_mdl;

 status = ProMdlDependenciesDataList (mdl, &deps, &filetypes, &deps_count);
 
if (status == PRO_TK_NO_ERROR && deps_count > 0)
 {
    
 for (iDeps = 0; iDeps < deps_count; iDeps ++)
    { //printing some infos
     PTTestSPrintf (path_line, "       - %s.%s",
          ProWstringToString (var, deps [iDeps].name),
      		   ProWstringToString (var2, deps [iDeps].type));
     	  PTTestResfileWrite (path_line);
    status= ProMdlnameInit(deps [iDeps].name, filetypes[iDeps], &sub_mdl);	
	//add the model to array
	ProArrayObjectAdd((ProArray*)mdllistarray_to_add, PRO_VALUE_UNUSED, 1, &sub_mdl);	
 if( filetypes[iDeps]== PRO_ASSEMBLY)  checkDependenciesToList(sub_mdl , mdllistarray_to_add);
//this is an assembly and need to call recursively checkDependenciesToList } //end of the loop of the models one level ProArrayFree ((ProArray*)&deps); } return PRO_TK_NO_ERROR; } ...

:

 

int checkDependenciesToList(ProMdl mdl , ProMdl **mdllistarray_to_add) //저장된 mdllistarray_to_add의 &주소값을 읽는다
{
	ProError status;
	int deps_counteps_count,iDeps,deps_count;
	ProModel*  deps;          
	int result;
	ProMdl sub_mdl;
	char var[80],var2[10];
	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);	
				//if(status==PRO_TK_NO_ERROR)	TestDialog("prt init");
			}
			else if(!strcmp(var2,"ASM"))
			{
				status= ProMdlInit(deps [iDeps].name, PRO_MDL_ASSEMBLY, &sub_mdl);	
				//if(status==PRO_TK_NO_ERROR)	TestDialog("asm init");
			}
			
			//add the model to array
			status = ProArrayObjectAdd((ProArray*)mdllistarray_to_add, PRO_VALUE_UNUSED, 1, &sub_mdl);	
			if(status==PRO_TK_NO_ERROR)	TestDialog("add");
			else
			{
				switch(status)
				{
					case PRO_TK_BAD_INPUTS : TestDialog("bad input"); break;
					default : TestDialog("big memory"); break;
				}

			}

			if(!strcmp(var2,"ASM"))  checkDependenciesToList(sub_mdl , mdllistarray_to_add);
			//this is an assembly and need to call recursively checkDependenciesToList

									  
		} //end of the loop of the models one level
		
		

		ProArraySizeGet((ProArray*)mdllistarray_to_add,&mdl_arr_size);
	itoa(mdl_arr_size,c,10);
	//TestDialog(c);

		ProArrayFree ((ProArray*)&deps);
	}
	return PRO_TK_NO_ERROR; 
	  
  
}



ProError Test()
{
	ProMdl *mdl_arr,mdl;
	ProModelitem mdlitem;
	ProSelection *proselect;
	ProError status;
	int selectcount, mdl_arr_size;
	char c[10];
	
	status = ProSelect("prt_or_asm",1,NULL,NULL,NULL,NULL,&proselect,&selectcount);
	status = ProSelectionModelitemGet(proselect[0],&mdlitem);
	status = ProModelitemMdlGet(&mdlitem, &mdl);

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

}

I used it like this: array size is -1.
Also, if you run ProArrayObjectAdd, PRO_TK_BAD_INPUTS is returned.
Is there an invalid format?

When recursively called, arrays in the model are not created correctly.

So we have created a feature to be create parameter inside a recursive function.

Small assembly files work, but large assembly files do not work.

Creo will exit with a fatal error (thread).

The following code was used to recursively enforce parameter operations on all models.
The assembly up to the level 2 of the model will work properly.
However, if the model has an assembly level of 3 or higher, it will end up in an infinite loop.
When I tested it with the following data, the assembly called CAR was displayed continuously.

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");
	}

}

The actual question : why do you have an exit with large assemblies and what do then?

So I think this is because in such assemblies we have very often some kind of  a circular reference - then is clear that the recursive function will lead to  infinite loop.

What to do then.

So you have an array where you add the model.s.

So you can simple make a check  with a funciton like : " ist _model_in_array(ProMdl mdl, ProMdl **mdl_array) " if the model is already in the array you will  not call the function recorsively  - I think this will avoid the infinite loop.

So I do not see in you code some a handle of the array but I will recommend to use it - so you will start the frist time with initilized list and then add  in each call the model your found to the list.

For example some think like:

example TestDbms.c from UserGuide

int checkDependenciesToList(ProMdl mdl , ProMdl **mdllistarray_to_add) 
{
	ProError status;
	int deps_counteps_count,iDeps,deps_count;
	ProModel*  deps;          
	int result;
	ProMdl sub_mdl;
	char var[80],var2[10];
	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);	
				//if(status==PRO_TK_NO_ERROR)	TestDialog("prt init");
			}
			else if(!strcmp(var2,"ASM"))
			{
				status= ProMdlInit(deps [iDeps].name, PRO_MDL_ASSEMBLY, &sub_mdl);	
				//if(status==PRO_TK_NO_ERROR)	TestDialog("asm init");
			}
			
			//add the model to array
			status = ProArrayObjectAdd((ProArray*)mdllistarray_to_add, PRO_VALUE_UNUSED, 1, &sub_mdl);	

			if(!strcmp(var2,"ASM"))  checkDependenciesToList(sub_mdl , mdllistarray_to_add);
			//this is an assembly and need to call recursively checkDependenciesToList

									  
		} //end of the loop of the models one level
		
		

		ProArraySizeGet((ProArray*)mdllistarray_to_add,&mdl_arr_size);
	itoa(mdl_arr_size,c,10);
	//TestDialog(c);

		ProArrayFree ((ProArray*)&deps);
	}
	return PRO_TK_NO_ERROR; 
	  
  
}



ProError Test()
{
	ProMdl *mdl_arr,mdl;
	ProModelitem mdlitem;
	ProSelection *proselect;
	ProError status;
	int selectcount, mdl_arr_size;
	char c[10];
	
	status = ProSelect("prt_or_asm",1,NULL,NULL,NULL,NULL,&proselect,&selectcount);
	status = ProSelectionModelitemGet(proselect[0],&mdlitem);
	status = ProModelitemMdlGet(&mdlitem, &mdl);

	checkDependenciesToList(mdl,&mdl_arr);
  
	ProArraySizeGet((ProArray*)mdl_arr,&mdl_arr_size); //return -1 Size
	itoa(mdl_arr_size,c,10);
	TestDialog(c);

}

I am currently developing a toolkit based on Wildfire 5.0.
I have written additional code for the array, but no array is added.
When ProArraySizeGet is done, -1 is returned.

Top Tags