Skip to main content
10-Marble
Feb 22, 2023 10:14 PM UTC
Solved

pfcGetProESession().RunMacro('myScript') in for loop return pfcXToolkitGeneralError randomly.

 

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
}

 

 

 

 

 

 

20-Turquoise
Feb 28, 2023 4:31 PM UTC

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

 

 

4 replies

20-Turquoise
Feb 23, 2023 2:21 PM UTC

jlink and weblink RunMacro() only executes at the end of the program.

See: https://community.ptc.com/t5/Customization/JLink-Question/td-p/84229

Translate
10-Marble
Feb 28, 2023 3:57 PM UTC

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.

Translate
20-Turquoise
Feb 28, 2023 4:31 PM UTC

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

 

 

Translate