Skip to main content
15-Moonstone
July 15, 2020
Question

Selection and Macro

  • July 15, 2020
  • 1 reply
  • 2892 views

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.

1 reply

JB_8704915-MoonstoneAuthor
15-Moonstone
July 15, 2020

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.

JB_8704915-MoonstoneAuthor
15-Moonstone
July 15, 2020

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.

17-Peridot
July 15, 2020

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