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

Selection and Macro

JB_87049
Alexandrite

Selection and Macro

I want to invoke a macro from within a Toolkit application.
The macro converts a selected annotation to an annotation feature.

When I select the annotation manually and then invoke the macro (mapkey) it works as intended.

When I try to do the same from within the Toolkit application it doesn't work.
The macro is executed but there is something wrong with the selection.

 

ProSelection AnnotationSel;

 

status = ProSelectionAlloc(NULL,
                           &((p_ListAnnFoundItem->CommonData).AnnInfo.Annotation),
                           &AnnotationSel); // must be freed

 

// Execute mapkey on selected annotation

 

ProLine wszMacro;

 

status = ProSelectionHighlight(AnnotationSel, PRO_COLOR_HIGHLITE);
ProStringToWstring(wszMacro, "%jbaf");
status = ProMacroLoad(wszMacro);
status = ProMacroExecute();

 

// Free selection

 

status = ProSelectionFree(&AnnotationSel);

 

The highlighting proves the annotation was selected by ProSelectionAlloc but apparently this is not seen by the macro. So I guess the selection has to be copied to a buffer or something similar in order for the mapkey to see it.
I couldn't find any information about this.
Anyone here who has done these kind of things before and who can point me to the right direction?
Thanks very much in advance.

7 REPLIES 7

Re: Selection and Macro

I have now changed my code to

 

// First the annotation has to be selected in the model in order for the mapkey to work

ProSelection AnnotationSel;

 

status = ProSelectionAlloc(NULL,
                           &((p_ListAnnFoundItem->CommonData).AnnInfo.Annotation),
                           &AnnotationSel); // must be freed
status = ProSelbufferSelectionAdd(AnnotationSel);

 

// Load and execute mapkey on selected annotation

 

ProLine wszMacro;

 

ProStringToWstring(wszMacro, "~ Activate `Odui_Dlg_00` `stdbtn_1`;");
status = ProMacroLoad(wszMacro);
ProStringToWstring(wszMacro, "~ Command `ProCmdAnnotFeat@PopupMenuGraphicWinStack` ;");
status = ProMacroLoad(wszMacro);
ProStringToWstring(wszMacro, "~ Close `rmb_popup` `PopupMenu`;");
status = ProMacroLoad(wszMacro);
ProStringToWstring(wszMacro, "~ Timer `UI Desktop` `UI Desktop` `popupMenuRMBTimerCB`;");
status = ProMacroLoad(wszMacro);

status = ProMacroExecute();

 

// Free selection

 

status = ProSelectionFree(&AnnotationSel);

 

The return of ProMacroExecute is PRO_TK_NOT_VALID
I don't understand why.

Re: Selection and Macro

Apparently there is nothing wrong with the macro as such.
In my application there is a dialog window displayed. This seems to prevent the macro from executing correctly.
This cumbersome route with a macro has been taken as there seems no way in Toolkit (at least I'm not aware of one) to convert a driven dimension annotation to an annotation feature.
PTC's Toolkit turns out to be one of the most frustrating software libraries I've ever worked with.

Tags (1)

Re: Selection and Macro

When it comes to running mapkey - the "state" of the PTC UI has to be well understood before you run it... If you try to run a mapkey when the UI is in a different starting point..... it would be no different than a user trying to run a mapkey from a start point that it would not run anyway.

 

If you got a mapkey to run proper the first time, but it would not the next... chances are you left the UI in a state that it could not run the mapkey again... always record mapkeys to perform the operation and then back out of any sub-dialogs back to the original UI state if possible.

 

Hope that helps.

 

Dave

Re: Selection and Macro

Thank you for your reply.
I know the state of the UI has to be consistent.
This is not the problem here.
Apparently the problem is caused by the fact I have my own dialog window still active when I try to execute the macro. I have tested my work flow by executing macros that changed the view orientation. What I now believe to be the culprit responsible for the non-functioning of my code is the fact that the conversion to an annotation feature pops up a new dialog window while my own dialog window is still active.

Re: Selection and Macro

In synchrones mode the MK is executed after the control goes back to Creo. Only in asynchrones mode the MK is executed on calling the function. 
Check the header file. 
You may able to set a global flag, and call your app at the end of the MK. But your MK must be well organized for this. 

Re: Selection and Macro

Thank you for your reply.
I read the documentation and noticed the part about synchronous and asynchronous mode.
The behaviour I see while debugging is not consistent with what is written here.

I'm running my application in synchronous mode. If the documentation is correct this would mean no macro can be executed unless my application ends. At least that is how I understand it. This is not the behaviour I'm seeing. I can execute macros that change the view orientation while my application is running and my dialog window is displayed. 
What I now believe to be the culprit responsible for the non-functioning of my code is the fact that the conversion to an annotation feature pops up a new dialog window while my own dialog window is still active.
I'm going to test now what happens when my code is still running but when I close my dialog window before trying to execute the macro.

Re: Selection and Macro

After some testing it seems it is indeed the way the event queue for the GUI is handled internally in Creo that is the root of the problem. When I close the dialog window of my application and as such give the full event queue back to PTC Creo and then execute the macro it works.

Announcements