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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

How To Replace an Assembly Component

pwilliams-3
11-Garnet

How To Replace an Assembly Component

All,

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,

pro_elem;

ProElempathItem pro_aElemPathItem[] = {

{PRO_ELEM_PATH_ITEM_TYPE_ID, PRO_E_COMPONENT_MODEL}

};

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)
-

TU/M12/8
6221 S Palo Verde Rd
Tucson, AZ 85706USA
www.raytheon.com


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
1 REPLY 1

I used

prodb_auto_interchange() to replace assembly components.

Top Tags