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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

TK / OTK - Copy and rename assembly in memory (Reference issue)

Eike_Hauptmann
13-Aquamarine

TK / OTK - Copy and rename assembly in memory (Reference issue)

Hi I rename all models inside a model to new names. After that I have some problems with references. So external references get not updated.

Now I try to use ProFeatureReferenceEdit to edit these references. But I didn't get it.

I didn't get him to another return value than -2 (BAD INPUTS), anyone have an idea how to get it?

My current code sniplet looks like this:

  writeLog("5.0", 0);

  ProFeature feat;

  ProSolid solid = (ProSolid)wfcGetHandleFromObject(pfcSolid::cast(mdl));

  if (ProFeatureInit((ProSolid)wfcGetHandleFromObject(pfcSolid::cast(mdl)), 68, &feat) != PRO_TK_NO_ERROR) writeLog("here 55");

  writeLog("5.2", 0);

  ProError status;

  if (ProArrayAlloc(1, sizeof(ProReference), 1, (ProArray*)&old_refs) != PRO_TK_NO_ERROR) writeLog("here 1", 0);

  if (ProArrayAlloc(1, sizeof(ProReference), 1, (ProArray*)&new_refs) != PRO_TK_NO_ERROR) writeLog("here 2", 0);

  if ((status = ProFeatureReferenceEdit(solid, &feat, old_refs, new_refs, NULL)) != PRO_TK_NO_ERROR) writeLog("failure while change: " + convertInt(status), 0);

  writeLog("5.3", 0);

Br and Thanks,

Eike


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.
2 REPLIES 2
FV
17-Peridot
17-Peridot
(To:Eike_Hauptmann)

Eike,

Check your code. You are not populating neither old_refs nor new_refs, you are just allocating 'placeholders'.

HIH.

Feliks. 

Eike_Hauptmann
13-Aquamarine
(To:FV)

Hi Feliks,

you're right. But thats only to simplify the sniplet. The complete one look like this at the moment:

  void CopyDialog::CopyAndRenameDependentModels(pfcModel_ptr mdl, vector<xstring> & mdl_old_names, vector<xstring> & mdl_new_names) {

  if (mdl == NULL) {

  writeLog("mdl = NULL", 0); return;

  }

  pfcModelItems_ptr mis = mdl->ListItems(pfcModelItemType::pfcITEM_FEATURE);

  if (mis != NULL)

  for (int i = 0; i < mis->getarraysize(); i++) {

  if (pfcFeature::cast(mis->get(i))->GetFeatType() == pfcFeatureType::pfcFEATTYPE_COMPONENT) {

  pfcModel_ptr on = retrieveModel(pfcComponentFeat::cast(mis->get(i))->GetModelDescr());

  if ((on->GetType() == pfcModelType::pfcMDL_PART

  || on->GetType() == pfcModelType::pfcMDL_ASSEMBLY

  || on->GetType() == pfcModelType::pfcMDL_DRAWING

  || on->GetType() == pfcModelType::pfcMDL_MFG)) {

  for (int k = 0; k < mdl_old_names.size(); k++) {

  xstring old_file_name = pfcComponentFeat::cast(mis->get(i))->GetModelDescr()->GetFileName();

  if (StringToLower(string(mdl_old_names.at(k))) == StringToLower(string(old_file_name))) {

  writeLog("1", 0);

  try {

  writeLog("CREATE: " + mdl_new_names.at(k), 0);

  pfcFamilyTableRow_ptr row = pfcFamilyMember::cast(on)->AddRow(mdl_new_names.at(k));

  pfcModel_ptr instance = row->CreateInstance();

  writeLog("2", 0);

  pfcFeatureOperations_ptr pfcops = pfcFeatureOperations::create();

  pfcCompModelReplace_ptr repop = pfcComponentFeat::cast(mis->get(i))->CreateReplaceOp(instance);

  writeLog("3", 0);

  if (repop != NULL) {

  pfcops->append(pfcFeatureOperation::cast(repop));

  }

  writeLog("4", 0);

  ProConfigoptSet(L"regen_failure_handling", L"resolve_mode");

  pfcSolid::cast(mdl)->ExecuteFeatureOps(pfcops, NULL);

  pfcFamilyMember::cast(on)->RemoveRow(row);

  ProConfigoptSet(L"regen_failure_handling", L"no_resolve_mode");

  //TODO: only after creation

  pfcModelItems_ptr imis = instance->ListItems(pfcModelItemType::pfcITEM_FEATURE);

  for (int inti = 0; inti < imis->getarraysize(); inti++) {

  /*wfcElementTree_ptr elemtree = wfcWFeature::cast(imis->get(inti))->GetElementTree(NULL, wfcFEAT_EXTRACT_NO_OPTS);

  wfcFeatCreateOptions_ptr wfco = wfcFeatCreateOptions::create();

  wfco->append(wfcFeatCreateOption::wfcFEAT_CR_DO_NOT_DISPLAY);

  wfcWFeature::cast(imis->get(inti))->RedefineFeature(NULL, elemtree, wfco, NULL);*/

  wfcExternalReferenceInfos_ptr extinfos = wfcWFeature::cast(imis->get(inti))->GetExternalParents(wfcExternalReferenceType::wfcALL_REF_TYPES);

  int oldid = -1;

  if (extinfos != NULL) {

  for (int l = 0; l < extinfos->getarraysize(); l++) {

  wfcWExternalFeatureReferences_ptr extrefs = extinfos->get(l)->GetExtRefs();

  if (extrefs != NULL) {

  ProReference * old_refs = NULL, * new_refs;

  for (int m = 0; m < extrefs->getarraysize(); m++) {

  for (int extk = 0; extk < mdl_old_names.size(); extk++) {

  xstring old_file_name = pfcComponentFeat::cast(mis->get(i))->GetModelDescr()->GetFileName();

  if (StringToLower(string(mdl_old_names.at(extk))) == StringToLower(string(extrefs->get(m)->GetAsmcomponents()->GetPathToRef()->GetLeaf()->GetFileName()))) {

  ProSelection mdl_o_sel, mdl_n_sel;

  ProReference mdl_o_ref, mdl_n_ref;

  ProAsmcomppath p_o_asmcoppath, p_n_asmcoppath;

  if (extrefs->get(m)->GetFeature()->GetId() == oldid) continue;

  oldid = extrefs->get(m)->GetFeature()->GetId();

  writeLog(extrefs->get(m)->GetAsmcomponents()->GetPathToRef()->GetRoot()->GetFileName() + " - " + extrefs->get(m)->GetAsmcomponents()->GetPathToRef()->GetLeaf()->GetFileName() + " - " + convertInt(extrefs->get(m)->GetFeature()->GetId()), 0);

  writeLog(extrefs->get(m)->GetAsmcomponents()->GetPathToOwner()->GetRoot()->GetFileName() + " - " + extrefs->get(m)->GetAsmcomponents()->GetPathToOwner()->GetLeaf()->GetFileName() + " - " + convertInt(extrefs->get(m)->GetFeature()->GetId()), 0);

  xintsequence_ptr xii = extrefs->get(m)->GetAsmcomponents()->GetPathToRef()->GetComponentIds();

  ProIdTable pidt;

  for (int xiii = 0; xiii < xii->getarraysize(); xiii++) {

  pidt[xiii] = xii->get(xiii);

  writeLog("ASMPATH: " + convertInt(xii->get(xiii)), 0);

  }

  if (ProAsmcomppathInit((ProSolid)wfcGetHandleFromObject(pfcSolid::cast(extrefs->get(m)->GetAsmcomponents()->GetPathToRef()->GetRoot())), pidt, xii->getarraysize(), &p_o_asmcoppath) != PRO_TK_NO_ERROR) writeLog("Can't create Comp path 1", 0);

  if (ProAsmcomppathInit((ProSolid)wfcGetHandleFromObject(pfcSolid::cast(mdl)), pidt, xii->getarraysize(), &p_n_asmcoppath) != PRO_TK_NO_ERROR) writeLog("Can't create Comp path 2", 0);

  if (old_refs == NULL) {

  //Allocate Arrays

  if (ProArrayAlloc(0, sizeof(ProReference), 1, (ProArray*)&old_refs) != PRO_TK_NO_ERROR) writeLog("here 1", 0);

  if (ProArrayAlloc(0, sizeof(ProReference), 1, (ProArray*)&new_refs) != PRO_TK_NO_ERROR) writeLog("here 2", 0);

  }

  if (ProSelectionAlloc(&p_o_asmcoppath, (ProFeature *)wfcGetHandleFromObject(pfcFeature::cast(extrefs->get(m)->GetFeature())), &mdl_o_sel) == PRO_TK_NO_ERROR) {

  if (ProSelectionToReference(mdl_o_sel, &mdl_o_ref) != PRO_TK_NO_ERROR) writeLog("here 3");

  if (ProArrayObjectAdd((ProArray *)&old_refs, PRO_VALUE_UNUSED, 1, mdl_o_ref) != PRO_TK_NO_ERROR) writeLog("here 4", 0);

  writeLog(mdl_new_names.at(extk), 0);

  pfcModelDescriptor_ptr desc = pfcModelDescriptor::Create(instance->GetType(), mdl_new_names.at(extk), ""); //TODO ... Type nicht von der Instanz nutzen

  pfcModel_ptr ofmdl = pfcGetProESession()->GetModelFromDescr(desc);

  writeLog(ofmdl->GetFileName(), 0);

  if (ofmdl != NULL) {

  ProFeature nfeat;

  if (ProFeatureInit((ProSolid)wfcGetHandleFromObject(pfcSolid::cast(ofmdl)), extrefs->get(m)->GetFeature()->GetId(), &nfeat) != PRO_TK_NO_ERROR) writeLog("here 55");

  if (ProSelectionAlloc(&p_n_asmcoppath, &nfeat, &mdl_n_sel) == PRO_TK_NO_ERROR) {

  if (ProSelbufferSelectionAdd(mdl_n_sel) != PRO_TK_NO_ERROR) writeLog("meow1");

  if (ProSelectionToReference(mdl_n_sel, &mdl_n_ref) != PRO_TK_NO_ERROR) writeLog("here 3");

  if (ProArrayObjectAdd((ProArray *)&new_refs, PRO_VALUE_UNUSED, 1, mdl_n_ref) != PRO_TK_NO_ERROR) writeLog("here 4", 0);

  }

  else {

  writeLog("Can't create selection element 2", 0);

  }

  }

  else {

  writeLog("Can't find of model", 0);

  }

  }

  else {

  writeLog("Can't create selection element 1", 0);

  }

  break;

  }

  }

  }

  writeLog("------", 0);

  if (old_refs != NULL) {

  writeLog("5.0", 0);

  ProFeature feat;

  ProSolid solid = (ProSolid)wfcGetHandleFromObject(pfcSolid::cast(instance));

  if (ProFeatureInit((ProSolid)wfcGetHandleFromObject(pfcSolid::cast(instance)), imis->get(inti)->GetId(), &feat) != PRO_TK_NO_ERROR) writeLog("here 55");

  writeLog("5.2", 0);

  ProError status;

  if (ProArrayAlloc(1, sizeof(ProReference), 1, (ProArray*)&old_refs) != PRO_TK_NO_ERROR) writeLog("here 1", 0);

  if (ProArrayAlloc(1, sizeof(ProReference), 1, (ProArray*)&new_refs) != PRO_TK_NO_ERROR) writeLog("here 1", 0);

  if ((status = ProFeatureReferenceEdit(solid, &feat, old_refs, new_refs, NULL)) != PRO_TK_NO_ERROR) writeLog("failure while change: " + convertInt(status), 0);

  writeLog("5.3", 0);

  }

  }

  }

  }

  }

  writeLog("5", 0);

  } xcatchbegin

  writeLog("Oh ... oho ... oh oh .... I die", 0);

  xcatchend

  writeLog("6", 0);

  break;

  }

  }

  }

  }

  }

  }

So that's my current state ... The array have the same length and filled up with selections that changed to references. Not sure if that could be the problem. Empty arrays are also problems ... everything I try results in a -2 error : )

Br,

Eike

Top Tags