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
Hi,
have anyone an idea how to get the sketch relations / if it's possible to get the sketch relations out of sketches inside of for example Extrude Features? I've using Toolkit Creo 2.0 M110 atm.
I know how to get feature relations with ProModelitemToRelset, but I don't know how to get out the Sketch as a ?ModelItem?.
Best regards,
and thanks in advance,
Eike
Hi all,
Eike,
I had commented out this portion of the code sometime in WF 3.0 years, had never tried it again. If you could tryit and see if it works it would bereally nice.
//TODO: in the future when PTC would allow to get relset from sketcher , get relations and get data from them
/*
err = ProMdlToModelitem( (ProMdl) section_mdl, &mdl_mi);
if( err == PRO_TK_NO_ERROR){
err = ProModelitemToRelset( &mdl_mi, &relset);
if( err == PRO_TK_NO_ERROR) {
err = ProArrayAlloc( 0, sizeof(ProWstring), 1, (ProArray*) &wstr_arr);
if( err != PRO_TK_NO_ERROR)
return( PRO_TK_GENERAL_ERROR);
err = ProRelsetRelationsGet( &relset, &wstr_arr);
if( err != PRO_TK_NO_ERROR)
return( PRO_TK_GENERAL_ERROR);
err = ProArraySizeGet( (ProArray) wstr_arr, &numb);
if( err != PRO_TK_NO_ERROR)
return( PRO_TK_GENERAL_ERROR);
}
}
*/
HIH.
Feliks.
In Reply to Eike Petersen:
Hi,
have anyone an idea how to get the sketch relations / if it's possible to get the sketch relations out of sketches inside of for example Extrude Features? I've using Toolkit Creo 2.0 M110 atm.
I know how to get feature relations with ProModelitemToRelset, but I don't know how to get out the Sketch as a ?ModelItem?.
Best regards,
and thanks in advance,
Eike
Thx Feliks.
I tested it with internal sketches // sections.
if(PRO_TK_NO_ERROR == ProFeatureNumSectionsGet(p_feature, &p_n_sections)){
for (i = 0; i < p_n_sections; i++) {
ProSection section;
ProName r_name;
if(PRO_TK_NO_ERROR == ProFeatureSectionCopy(p_feature, i, §ion)) {
ProModelitem sec_item;
ProSectionNameGet(section, r_name);
writeRunnerLog_d(r_name, 0, 1);
//PROBLEMCODE
if (PRO_TK_NO_ERROR == ProMdlToModelitem((ProMdl) section, &sec_item)) {
} else {
writeRunnerLog(L"Can't convert ProSection to ModelItem", 2);
}
//PROBLEMCODE_END
ProSectionFree(§ion);
} else {
writeRunnerLog(L"Can't copy section",2);
}
}
} else {
writeRunnerLog(L"Can't get the sections number",2);
}
But it didn't work. I can't convert them to something, not model or modelitem. So I can't get the relations from the modelitem
Best regards,
Eike
Here comes a not nice solution for this problem (with mapkey -.-)
if(PRO_TK_NO_ERROR == ProFeatureNumSectionsGet(p_feature, &p_n_sections)){
for (i = 0; i < p_n_sections; i++) {
ProSection section;
ProName r_name;
/*ProElement p_elem;
ProFeatureElemtreeExtract(p_feature, NULL, PRO_FEAT_EXTRACT_NO_OPTS, &p_elem);
swprintf_s(name, PRO_NAME_SIZE, L"c:\\elemtree%d.xml", p_feature->id);
ProElemtreeWrite(p_elem, PRO_ELEMTREE_XML, name);
ProFeatureElemtreeFree(p_feature, p_elem);*/
if(PRO_TK_NO_ERROR == ProFeatureSectionCopy(p_feature, i, §ion)) {
ProModelitem sec_item;
wchar_t macro[800];
ProPath temppath, ntemppath;
FILE *f;
ProStringToWstring(temppath, getTemppath());
_wreplace_text_s(ntemppath, PRO_PATH_SIZE,temppath, L"\", L"\\\");
ProSectionNameGet(section, r_name);
writeRunnerLog_d(r_name, 0, 1);
writeRunnerLog_d(ntemppath, 0, 1);
swprintf_s(macro, 800, L"~ Command `ProCmdMmRels` ;~ Select `relation_dlg` `OMContext` 1 `section`;~ Command `ProCmdMdlTreeSearch` ;~ Select `selspecdlg0` `SelOptionRadio` 1 `Feature`;~ Select `selspecdlg0` `RuleTab` 1 `Misc`;~ Update `selspecdlg0` `ExtRulesLayout.ExtBasicIDLayout.InputIDPanel` `%d`;~ Activate `selspecdlg0` `EvaluateBtn`;~ Activate `selspecdlg0` `ApplyBtn`;~ Activate `selspecdlg0` `CancelButton`;~ Activate `relation_dlg` `PBExport`;~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` `file_open`;~ Update `file_open` `Inputname` `%s%s`;~ Command `ProFileSelPushOpen@context_dlg_open_cmd` ;~ Activate `relation_dlg` `PB_OK`;", p_feature->id, temppath, L"mp_creo_temp_outp.txt");
ProMacroLoad(macro);
ProMacroExecute();
wcscat_s(temppath, PRO_PATH_SIZE, L"mp_creo_temp_outp.txt");
if (_wfopen_s(&f, temppath, L"r") == 0) {
ProPath line, message;
int k = 0;
while (fgetws(line, PRO_PATH_SIZE, f) != NULL) {
ProPath line_repl;
if (k == 0) {
swprintf(message,PRO_PATH_SIZE,L"%s - at Id: %d",r_name,p_feature->id);
_writeInformationPDFwriteString(message,15,hold_pdf_font,50,heightrunner-=20);
k = 1;
}
_wreplace_text_s(line_repl, PRO_PATH_SIZE, line, L"", L");
_wreplace_text_s(line, PRO_PATH_SIZE, line_repl, L"\n", L");
_writeInformationPDFwriteString(line,10,hold_pdf_font,100,heightrunner -= 15);
}
fclose(f);
} else {
//writeRunnerLog(L"Can't open File, no rights to write to the temp directory ?", 2);
}
_wremove(temppath);
ProSectionFree(§ion);
} else {
//writeRunnerLog(L"Can't copy section",2);
}
}
} else {
writeRunnerLog(L"Can't get the sections number",2);
}
Best regards,
Eike
Hi all,
Eike,
If you are going for mapkey I think you could use mapkey where you select feature by ID, then use the UI command 'Feature Info' it will pop browser window which you would have to deal later,drastically shortens you mapkey, what 'Feature Info' (UI version) will do for you is to create html file in %TEMP% directory - search for ProwtTmpDir subdirectory and it will be burried somewhere there and named featinfo_proephist_<numeric>.html . In html file you should see the listing of sketch relations. Parse it as needed.
HIH.
Feliks.
In Reply to Eike Petersen:
Here comes a not nice solution for this problem (with mapkey -.-)
if(PRO_TK_NO_ERROR == ProFeatureNumSectionsGet(p_feature, &p_n_sections)){
for (i = 0; i < p_n_sections; i++) {
ProSection section;
ProName r_name;
/*ProElement p_elem;
ProFeatureElemtreeExtract(p_feature, NULL, PRO_FEAT_EXTRACT_NO_OPTS, &p_elem);
swprintf_s(name, PRO_NAME_SIZE, L"c:\\elemtree%d.xml", p_feature->id);
ProElemtreeWrite(p_elem, PRO_ELEMTREE_XML, name);
ProFeatureElemtreeFree(p_feature, p_elem);*/
if(PRO_TK_NO_ERROR == ProFeatureSectionCopy(p_feature, i, §ion)) {
ProModelitem sec_item;
wchar_t macro[800];
ProPath temppath, ntemppath;
FILE *f;
ProStringToWstring(temppath, getTemppath());
_wreplace_text_s(ntemppath, PRO_PATH_SIZE,temppath, L", L"\\");
ProSectionNameGet(section, r_name);
writeRunnerLog_d(r_name, 0, 1);
writeRunnerLog_d(ntemppath, 0, 1);
swprintf_s(macro, 800, L"~ Command `ProCmdMmRels` ;~ Select `relation_dlg` `OMContext` 1 `section`;~ Command `ProCmdMdlTreeSearch` ;~ Select `selspecdlg0` `SelOptionRadio` 1 `Feature`;~ Select `selspecdlg0` `RuleTab` 1 `Misc`;~ Update `selspecdlg0` `ExtRulesLayout.ExtBasicIDLayout.InputIDPanel` `%d`;~ Activate `selspecdlg0` `EvaluateBtn`;~ Activate `selspecdlg0` `ApplyBtn`;~ Activate `selspecdlg0` `CancelButton`;~ Activate `relation_dlg` `PBExport`;~ Trail `UI Desktop` `UI Desktop` `DLG_PREVIEW_POST` `file_open`;~ Update `file_open` `Inputname` `%s%s`;~ Command `ProFileSelPushOpen@context_dlg_open_cmd` ;~ Activate `relation_dlg` `PB_OK`;", p_feature->id, temppath, L"mp_creo_temp_outp.txt");
ProMacroLoad(macro);
ProMacroExecute();
wcscat_s(temppath, PRO_PATH_SIZE, L"mp_creo_temp_outp.txt");
if (_wfopen_s(&f, temppath, L"r") == 0) {
ProPath line, message;
int k = 0;
while (fgetws(line, PRO_PATH_SIZE, f) != NULL) {
ProPath line_repl;
if (k == 0) {
swprintf(message,PRO_PATH_SIZE,L"%s - at Id: %d",r_name,p_feature->id);
_writeInformationPDFwriteString(message,15,hold_pdf_font,50,heightrunner-=20);
k = 1;
}
_wreplace_text_s(line_repl, PRO_PATH_SIZE, line, L"", L");
_wreplace_text_s(line, PRO_PATH_SIZE, line_repl, L"\n", L");
_writeInformationPDFwriteString(line,10,hold_pdf_font,100,heightrunner -= 15);
}
fclose(f);
} else {
//writeRunnerLog(L"Can't open File, no rights to write to the temp directory ?", 2);
}
_wremove(temppath);
ProSectionFree(§ion);
} else {
//writeRunnerLog(L"Can't copy section",2);
}
}
} else {
writeRunnerLog(L"Can't get the sections number",2);
}Best regards,
Eike
Hi Feliks,
thx for this idea, the problem with browserwindow stuff is that it could be created asynchronous. So I now it from the history functionality. If I call model history by a sychronous mapkey and look for the html file directly after the mapkey call it could be that it's not already written. So I think this is the easier way. But you're right to use the %TEMP% variable to write it down. So I didn't have a fix path inside my mapkey anymore.
Wish u a wonderfull day,
Br and thx,
Eike