Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hello,
we use weblink's RunMacro function to run a script, it search the feature name first to find out the coresponding prt, then switch with the specific Simplified Representations, sometimes it success switch but sometimes return an exception pfcXToolkitGeneralError, just wanna know if my code structure has any problem, or RunMacro shouldn't be executed within a for loop ?
we use Creo Parametric 8.0.5.0
var macroFixHeader = '';
macroFixHeader += '~ Command `ProCmdMdlTreeSearch`;';
macroFixHeader += '~ Open `selspecdlg0` `SelOptionRadio`;';
macroFixHeader += '~ Close `selspecdlg0` `SelOptionRadio`;';
macroFixHeader += '~ Select `selspecdlg0` `SelOptionRadio` 1 `Component`;';
var macroFixBody = '';
macroFixBody += '~ Activate `selspecdlg0` `EvaluateBtn`;';
macroFixBody += '~ Select `selspecdlg0` `ResultList` -1;';
macroFixBody += '~ Activate `selspecdlg0` `ApplyBtn`;';
macroFixBody += '~ Activate `selspecdlg0` `CancelButton`;';
macroFixBody += '~ Activate `main_dlg_cur` `page_View_control_btn` 0;';
macroFixBody += '~ Command `ProCmdViewRepUserDefine`;';
var macroFixFooter = '';
macroFixFooter += '~ Activate `usrdefitems` `AcceptBtn`;';
macroFixFooter += '~ Command `ProCmdWinActivate`;';
var referenceNameArr = [];//some feature name get from session
for(var t=0; t<referenceNameArr.length; t++) {
var reference = referenceNameArr[t];
var macroParamPartName = '~ Update `selspecdlg0` `ExtRulesLayout.ExtBasicNameLayout.BasicNameList` `' + reference + '`;';
var macroParamSimpRepName = '~ Select `usrdefitems` `ItemsList` 1 `' + simpRepName + '`;';
var finalMacro = macroFixHeader + macroParamPartName + macroFixBody + macroParamSimpRepName + macroFixFooter;
pfcGetProESession().RunMacro(finalMacro);//return pfcXToolkitGeneralError randomly
}
Solved! Go to Solution.
Running a macro works just fine. I do it all the time. Instead of running the macro each time in the loop you can add to the macro and run it after the loop.
var finalMacro = "";
for(var t=0; t<referenceNameArr.length; t++) {
var reference = referenceNameArr[t];
var macroParamPartName = '~ Update `selspecdlg0` `ExtRulesLayout.ExtBasicNameLayout.BasicNameList` `' + reference + '`;';
var macroParamSimpRepName = '~ Select `usrdefitems` `ItemsList` 1 `' + simpRepName + '`;';
finalMacro += macroFixHeader + macroParamPartName + macroFixBody + macroParamSimpRepName + macroFixFooter;
}
pfcGetProESession().RunMacro(finalMacro);//return pfcXToolkitGeneralError randomly
jlink and weblink RunMacro() only executes at the end of the program.
See: https://community.ptc.com/t5/Customization/JLink-Question/td-p/84229
Thanks for your reply, I've opened a case to call PTC TS for help, he told me that running macro by web.link is not stable, especially running in the loop, it's not recommended since it may work or crash or return error.
Running a macro works just fine. I do it all the time. Instead of running the macro each time in the loop you can add to the macro and run it after the loop.
var finalMacro = "";
for(var t=0; t<referenceNameArr.length; t++) {
var reference = referenceNameArr[t];
var macroParamPartName = '~ Update `selspecdlg0` `ExtRulesLayout.ExtBasicNameLayout.BasicNameList` `' + reference + '`;';
var macroParamSimpRepName = '~ Select `usrdefitems` `ItemsList` 1 `' + simpRepName + '`;';
finalMacro += macroFixHeader + macroParamPartName + macroFixBody + macroParamSimpRepName + macroFixFooter;
}
pfcGetProESession().RunMacro(finalMacro);//return pfcXToolkitGeneralError randomly
Thanks, this way really improve the stability of RunMacro(),