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

How To Replace an Assembly Component

Regular Member

How To Replace an Assembly Component


I am trying to programmatically replace an assembly component. I have a handle to the component to be replaced and a handle to the new component. I am trying to redefine the feature by setting the value of the PRO_E_COMPONENT_MODEL in the element tree but when I do this nothing happens. I get a message in the message window that the feature was redefined but it's really not.

Additionally I am copying the original component to a new component with a new name. I want to replace the original component with the one with the new name. Therefore all of the constraints "should" not change. Am I correct in this claim?

Here is my component visit action function.

ProError ComponentVisitAction(ProFeature* p_feature, ProError status, ProAppData app_data) {

ProError pro_error = PRO_TK_NO_ERROR;

ProPart pro_part = NULL,

pro_partNew = NULL;

ProName pro_wszName;

ProElement pro_elemTree,


ProElempathItem pro_aElemPathItem[] = {



ProElempath pro_elemPath;

ProFeatureCreateOptions pro_fCreateOpts[] = {PRO_FEAT_CR_DEFINE_MISS_ELEMS};

ProErrorlist *pro_errorList = NULL;

/*** Copy the piston.prt ***/

//Get the model

pro_error = ProAsmcompMdlGet(p_feature, (ProMdl*)&pro_part);

//Get the model name

pro_error = ProMdlNameGet(pro_part, pro_wszName);

//Set the new name

ProWstringConcatenate(L"New", pro_wszName, PRO_VALUE_UNUSED);

//Copy the Part

pro_error = ProMdlCopy(pro_part, pro_wszName, (ProMdl*)&pro_partNew);

/*** Update the new assembly reference to the new part ***/

//Get the element tree for this feature

pro_error = ProFeatureElemtreeCreate(p_feature, &pro_elemTree);

//Allocate the element path

pro_error = ProElempathAlloc(&pro_elemPath);

//Set the path items

pro_error = ProElempathDataSet(pro_elemPath, pro_aElemPathItem, 1);

//Get the PRO_E_COMPONENT_MODEL element

pro_error = ProElemtreeElementGet(pro_elemTree, pro_elemPath, &pro_elem);

//Modify the PRO_E_COMPONENT_MODEL element

pro_error = ProElementSpecialvalueSet(pro_elem, (ProAppData)&pro_partNew);

//Free the element path

pro_error = ProElempathFree(&pro_elemPath);

//Add the PRO_E_COMPONENT_MODEL element to the element tree

//pro_error = ProElemtreeElementAdd(pro_elemTree, NULL, pro_elem);

/*** Redefine the assembly reference (feature) ***/

//Redefine the feature

pro_error = ProFeatureRedefine(NULL, p_feature, pro_elemTree, pro_fCreateOpts, 1, pro_errorList);

//Free the feature element tree

pro_error = ProFeatureElemtreeFree(p_feature, pro_elemTree);

return PRO_TK_E_FOUND;


Patrick Williams
Sr. Systems Engineer II
Mechanical Engineering Solutions
Missile Systems
Raytheon Company

+1 520.545.6995(business)
+1 520.545.6399(fax)

6221 S Palo Verde Rd
Tucson, AZ 85706USA


RE: How To Replace an Assembly Component

I used

prodb_auto_interchange() to replace assembly components.