Can I turn off a "tool" (ex. MEASURE + DIRECT + LINE TOOL) within a PREMIER APP and turn on another?
All --
I have an app that activates the MEASURE + DIRECT + LINE TOOL in the INTERACTIVE MODE so the USER can create a line.
I would then like the app to activate the SELECT + REGIONS OF INTEREST + SELECT ROI TOOL active so the USER can edit an existing ROI if they need to.
Recording this within PREMIER does not track this TOOL CHANGE and I don't see any QUESTIONS or DISCUSSIONS here that address this.
Is there a way to do this within PREMIER?
Thanks.
-- Matt
I have an app that activates the MEASURE + DIRECT + LINE TOOL in the INTERACTIVE MODE so the USER can create a line.
I would then like the app to activate the SELECT + REGIONS OF INTEREST + SELECT ROI TOOL active so the USER can edit an existing ROI if they need to.
Recording this within PREMIER does not track this TOOL CHANGE and I don't see any QUESTIONS or DISCUSSIONS here that address this.
Is there a way to do this within PREMIER?
Thanks.
-- Matt
0
Best Answers
-
Tool selection is not recordable, there are special commands in the Toolbox that you can use.
Just drop the command from the toolbox to your macro and activate Interaction.
Yuri0 -
Here is the sample macro:
Public Function NewMacro() As SimpleScript NewMacro = New SimpleScript With [Select].Roi.ToolsCommands.Select(NewMacro) .Prompt = "Select ROIs" .Overlay = Overlays.OverlayType.ROIOverlay .Interactive = True .Run(ThisApplication.ActiveImage) End With End Function
Yuri0 -
Matt,
Yes you are right, this is a bug in Premier 9.1.2 which affects interpreted projects (compiled projects are OK). It is addressed in Premier 9.1.4.
Pierre0 -
Matt,
Measurements.Add works differently, you have to specify coordinates if user doesn't do anything:
.With Measure.MeasurementsCommands.Add(M2) .MeasurementType = McMeasurements.enumMMSTypes.mmtsLine .Points = New System.Collections.Generic.List(Of System.Drawing.PointF) .Points.Add(New System.Drawing.PointF(81.46786F,88.87738F)) .Points.Add(New System.Drawing.PointF(164.825F,141.6702F)) .FeatureName = "L1" .SnapFeature = False .Interactive = True .Run(image1, meas1) End With
I can see that you are trying to create a measurement to use for calibration interactively. There is already a function for that - Quick Calibration. Below is the macro that promts the user to create a line and creates calibration based on that:Public Function CalibrateByLine() As SimpleScript CalibrateByLine = New SimpleScript Dim doc1 With Application.DocumentCommands.Active(CalibrateByLine) .Run(doc1) End With With Measure.Calibration.SpatialCommands.QuickCalibration(CalibrateByLine) .Interactive = True .Run(doc1) End With End Function
Yuri0
Answers
Thank you for the guidance.
I'll try it out shortly and reply with the results.
Thanks again.
-- Matt
Thank you for the SAMPLE CODE.
For my application, I modified it to be
This does a very nice job of DEACTIVATING the LINE TOOL and ACTIVATING the ROI SELECT TOOL but not demanding that the user use the ROI SELECT TOOL.
Your code also reminded me that I can change the PROMPT the LINE TOOL displays in the INTERACTIVE MODE.
Thank you for the valuable guidance.
One more related question . . .
If I use your NEW MACRO as you created it and I press the CANCEL button within the PROMPT BOX that says "SELECT ROIS", a message box is displayed by PREMIER saying
THE OPERATION WAS CANCELLED
and the macro stalls.
Is there a way to handle a CANCEL in this situation without stalling the macro?
Thanks.
-- Matt
You can catch the exception generated when the user cancels to implement your preferred behavior.
Public Function NewMacro() As SimpleScript NewMacro = New SimpleScript Try With [Select].Roi.ToolsCommands.Select(NewMacro) .Prompt = "Select ROIs" .Overlay = Overlays.OverlayType.ROIOverlay .Interactive = True .Run(ThisApplication.ActiveImage) End With Catch MsgBox "Command was cancelled!" ' ... do something else here End Try End Function
Pierre
Thank you for your suggestion.
I tried it and it did not work.
I changed your
to
as shown below so I could definitely see that everything was working properly but my PREMIER (9.1.2) still displays a
THIS OPERATION WAS CANCELED.
message.
Is there a dependency or a mode that needs to be checked?
Thanks.
-- Matt
If I remember correctly, it was an issue in error handling (canceling interactive command) in 9.1.2. Try 9.1.4.
Nikita.
Thank you for the additional information.
I have initiated the PREMIER 9.1.2 to PREMIER 9.1.4 upgrade process.
After that completes, I'll try PIERRE's solution and let you know how it goes.
Thanks again.
-- Matt
I have successfully completed the UPGRADE from 9.1.2 to 9.1.4.
I have also tried the NewMacro as shown above and it works properly.
I'll integrate the TRY / CATCH STATEMENTS into the APP.
-- Matt
Thank you very much. -- MMB
One last "twist" on this issue.
I have integrated Pierre's suggestion about the TRY and Yuri's reminder about the PROMPT into some code that is intended to allow a user to interactively create a line that will be used for calibration purposes.
All is working well when the user does what they should.
When the user presses the OK generated by the INTERACTIVE and the PROMPT without having created a line, PREMIER (9.1.4) generates an error which says
ERROR IN PROCEDURE ADD OF CLASS MODULE MCMEASUREMENTS
ARGUMENT ARRAY IS TOO SMALL
but I never see my
"An error was trapped!"
Is there a way to gracefully handle this?
I have generated a "lean" version of the function that I'm trying to build (below) for development and testing.
Thanks.
-- Matt
Thank you for your prompt response.
I am working on a "simplified" calibration mechanism but I'm not creating a new calibration, I'm checking and updating an existing calibration.
Your CalibrateByLine works great but it gives too many options to this set of users so I can't use it.
Based on your information about ADD, I did come up with a solution.
I have modified LineMacro to include a DUMMY LINE L0 from
0, 0
to
0, 0
Since my CALIBRATION routine uses the SUM of the LnLengths found after the ADD, the length of the DUMMY L0 LINE will not confound the CALIBRATION and everything seems to be happy and smooth.
FYI . . .
Using
and
and
I am having the macro "update" an existing calibration that I've already done all of the administration on regarding CALIBRATION NAME, CALIBRATION UNITS, and IQC FILE and such.
The version of LineMacro that includes the DUMMY LINE is below.
Thanks again (everyone) for all of the valuable information.
I hope the information above and below will help someone else.
-- Matt
I just wanted to add, that the way the
Please enter the correct LENGTH
PROMPT to the user is wired in, if user does not change the value and then they press OK, then they are basically agreeing that PREMIER is calibrated properly because they will have a CORRECTION FACTOR of 1 and the calibration should not change.-- Matt