Get active model data in Creo Toolkit

Getting data of the active creo model is most basic thing in Creo Customization. Here I considering to get the data of the Creo model which opened in active window.

 

  • Create a function named getActiveModel(). The return type ProError can be modified by user as per their requirement.
  • Declare the Variables required
    Declare Variable
    ProError mStatus;
    	ProMdl *activeModel;
    	ProName wName;
    	char cName[PRO_NAME_SIZE];
    	char *Name;
    • ProError 
      • The creo API Enumerated type to return function calls whether it is failed or succeed.
      • ProError declared to return the function status
    • ProMdl
      • The top level object in the Creo parametric.
      • In Part Mode the ProMdl is Part
      • In Assembly Mode the ProMdl is Assembly
      • We will use the ProMdl to handle the Currently active model
    • ProName
      • Used to refer the address of the model name
      • For Any Creo parametic name property, we can use ProName
      • The Size of the ProName is 32
    • char* & char are C/C++ datatypes to hold characters

 

  • Call the API function ProMdlActiveGet to get the Creo model
Get Active Model
mStatus = ProMdlActiveGet(activeModel);
  • return the ProError value , if it is PRO_TK_NO_ERROR then the function successfully got the model else it failed.
Validate the Get Active Model
switch (mStatus)
	{
	case PRO_TK_NO_ERROR:
// Get Active model success
break;
	default:
		MessageBox(NULL, "Couldn't get the Active model", "Failure", MB_OK);
		return PRO_TK_GENERAL_ERROR;
		break;
	}
  • If model got successfully then call the API function to get the model name (model data) to verify the model is active model
Get the Active Model Data (Name)
mStatus = ProMdlNameGet(activeModel, wName);
  • Here the consolidated code
Get Active Model Name
ProError getActiveModel() {

	ProError mStatus;
	ProMdl *activeModel;
	ProName wName;
	char cName[PRO_NAME_SIZE];
	char *Name;

	mStatus = ProMdlActiveGet(activeModel);
	switch (mStatus)
	{
	case PRO_TK_NO_ERROR:

		mStatus = ProMdlNameGet(activeModel, wName);
		ProWstringToString(cName, wName);
		Name = cName;
		MessageBox(NULL, Name, "Active Model Name", MB_OK);
		return PRO_TK_NO_ERROR;
		break;
	default:
		MessageBox(NULL, "Couldn't get the Active model", "Failure", MB_OK);
		return PRO_TK_GENERAL_ERROR;
		break;
	}

}

Hope it would be useful for beginners in Creo toolkit to access the model data.

 

 

Thanks & Regards

Parthiban Kannan

Share Now
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply