Home Image-Pro Automation (Macros, Apps, Reports)

CODE to ACTIVATE and DEACTIVATE the POLY NUDGE TOOL . . .

2017-06-28-152453

All --

I can get the NUDGE TOOL to ACTIVATE and DEACTIVATE using the N KEY and the POLY NUDGE TOOL BUTTON

   

on the IMAGE + RIGHT CLICK MENU.

I would like to put a NUDGE BOUNDARY BUTTON into an PREMIER PROJECT but the ROUTINE that is recorded by the PROJECT WORKBENCH does not seem to record the ACTIVATION and DEACTIVATION of the POLY NUDGE TOOL.

I see

    mcSelectToolCommandFlags + mcstcfSetPolyToolState

and

   
mcEditToolState + mcPolyEditNudge

in the

    IMAGE-PRO PREMIER AUTOMATION HELP

but I don't know how to take advantage of the information shown there.

Will you please provide some guidance on how to write CODE that can be used to control the ACTIVATION and DEACTIVATION of the POLY NUDGE TOOL?

Thanks.

-- Matt

Best Answers

  • Answer ✓
    Hi Matt,

    I could reproduce your problem when Nudge tool was not used in Premier session.
    Please try the following code, that should also work if Nudge tool haven't been invoked previously.

        Public Sub NudgeToolOn
            With ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
                .CheckState=McCommand.mcCheckState.Checked
                .Run
            End With
        End Sub
    
        Public Sub NudgeToolOff
            With ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
                .CheckState=McCommand.mcCheckState.Unchecked
                .Run
            End With
        End Sub
    

    Yuri
  • Answer ✓
    Hi Matt,

    I've created a new macro that activates the nudge tool with interactive prompt (unlocking and selecting the object should be done by other macro, before calling this).

        Public Sub UseNudgeToolInteactively
            Dim cm As McCommand=ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
    '       toggle on nudge tool 
            cm.Execute
            With Automate.ScriptingCommands.Interaction(Nothing)
                .Interactive = True
                .Prompt= "Please use the NUDGE TOOL then press OK!"
                .Run(ThisApplication.ActiveDocument, Nothing)
            End With
    '       toggle off nudge tool 
            cm.Execute
        End Sub
    

    Let me know if it works for you.

    Yuri

Answers

  • edited June 2017
    Hi Matt,

    These macros will control the nudge tool:

        Public Sub NudgeToolOn
            With ThisApplication.Commands("Select.Image.ToggleEditToolNudge")
                .CheckState=McCommand.mcCheckState.Checked
                .Run
            End With
        End Sub
    
        Public Sub NudgeToolOff
            With ThisApplication.Commands("Select.Image.ToggleEditToolNudge")
                .CheckState=McCommand.mcCheckState.Unchecked
                .Run
            End With
        End Sub

    Note, that a polygonal ROI has to be selected to see effect of these commands.

    Yuri
  • 2017-06-29-103114

    Yuri --

    Thank you for your reply and the CODE it contains.

    I copied your code from the FORUM into my PROJECT and then I tried to activate the NUDGE TOOL on an IMAGE that contains a selected MEASUREMENT OBJECT (with EDIT POINTS showing).

    The result was the ERROR shown below as a SCREEN CAPTURE and as a COPY TO CLIPBOARD.

    I am working with PREMIER 3D V9.3.

    This seems like something more complicated than a missing reference.

    Will you help me resolve this issue please?

    Thanks.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-



    Error in Image-Pro Premier 3D 64-bit

    Unable to cast object of type 'MediaCy.IQL.Application.McCommand' to type 'MediaCy.IQL.Application.McCommandExtended'.


    Message: Unable to cast object of type 'MediaCy.IQL.Application.McCommand' to type 'MediaCy.IQL.Application.McCommandExtended'.
    Data: System.Collections.ListDictionaryInternal
    InnerException: Nothing
    TargetSite: MediaCy.IQL.Application.McCommandExtended Instantiate()
    StackTrace:    at MediaCy.IQL.Application.McCommand.Instantiate()
       at MediaCy.IQL.Application.McCommand.Record(RecordOptions options)
       at MediaCy.IQL.Application.McCommand.OnStatusChanged(McCommand sender, EventArgs e)
       at MediaCy.IQL.Application.McCommand.set_Status(TaskStatus value)
       at MediaCy.IQL.Application.McTasks.Deactivate(McCommand task)
       at MediaCy.IQL.Application.McCommand.Schedule(ThreadAffinity taskBehavior, TaskPriority taskPriority)
    HelpLink: Nothing
    Source: MediaCy.IQL.Application
    HResult: -2147467262
    Call Stack:
        MediaCy.IQL.Application.McCommandExtended Instantiate():
        Void Record(RecordOptions):
        Void OnStatusChanged(MediaCy.IQL.Application.McCommand, System.EventArgs):
        Void set_Status(TaskStatus):
        Void Deactivate(MediaCy.IQL.Application.McCommand):
        Void Schedule(MediaCy.IQL.Application.ThreadAffinity, MediaCy.IQL.Application.TaskPriority):

  • 2017-06-29-184843

    Yuri --

    I copied your CODE into my project and tested them with a RIGHT CLICK + RUN on the reference in the PROJECT EXPLORER.

    Your ON and OFF CODE worked . . . sometimes.

    I reviewed this with RICK L during a WEBEX and have some recordings of the performance.

    I'll send you links to the recordings.

    Hopefully you'll be able to see the ryhme and reason behind what seems to be a bit erratic access to the NUDGE TOOL.

    Thanks.

    -- Matt
  • The polygon Nudge editing mode can become active only if the selection tool is running and a polygon graphic object is selected (showing the selection handles on the vertices).
  • You can experiment with the conditions under which the Nudge tool can be toggled on or off by right-clicking on the image while doing overlay editing.  The context menu that comes up will show the "Poly Nudge Tool" and "Expand Vertices" buttons grayed unless these tools can be invoked (i.e., while editing a selected polygon or polyline).
  • 2017-07-03-114530

    Craig --

    Thanks for the information.

    Rick L and I had a meeting via WEBEX and we recorded that the POLYGON NUDGE TOOL seemed to be responding inconsistently even when we set up the editing scenario that you described.

    Links to the recording were sent to YURI and PIERRE in the hope that they could chart a path through what seemed to be inconsistencies.

    Your review and comment on these videos would be appreciated.

    Thanks.

    -- Matt
  • Matt,

    BTW, I have not received the recordings, but do you now understand how the tool supposed to work after Craig's explanation?

    Also, I checked my macros again and found that they just toggle the current state of the nudge tool. The state of the tool can be retrieved using the "Checked" property of that command.

    Yuri

  • 2017-07-03-130112

    Yuri --

    I have just FORWARDED a copy of the message with the LINKS to the RECORDINGS.

    If this copy doesn't reach your INBOX, please let me know and we can formulate a PLAN B.

    Thanks.

    -- Matt


  • Hi Matt,

    Thanks for letting me know, I've found your email in the spam folder. I will check the recording later and let you know my comments.

    Yuri
  • 2017-07-03-143257

    Yuri --

    Super.

    I'll not be at my desk / computer much the rest of the day.

    I'll be working tomorrow (TUE) AM though.

    Thanks.

    -- Matt
  • Matt,

    I checked your recording and can give my comments:

    1. You tried to use Nudge tool on count/size objects. The objects created by Count/Size are not editable by default, nudge tool cannot not be used neither. You have to Unlock these objects first (Measure tab, Select group, Show overlay button dropdown).
    2. Nudge tool works only on Polygonal features. Rectangle objects cannot be edited by nudge tool.

    Let me know if you have other questions.

    Yuri
  • 2017-07-05-095023

    Yuri --

    Thank you for reviewing the recordings and responding here.

    The information you have provided about "nudging" measurement objects generated by the COUNT / SIZE TOOL seems to conflict with information in the PREMIER USER GUIDE.

    PAGE 25 of says:
    "Adjust the size and shape of irregular ROIs and Measurements with the Polygon
    Nudge Tool."

    and PAGE 189 says:
    "The Polygon Nudge tool allows you to adjust the size and shape of irregular ROIs and
    measurements."

    But . . .

    After using the the UNLOCK TOOL that you directed me to, I can NUDGE any MEASUREMENT OBJECT generated by the COUNT / SIZE TOOL if I select it individually. 

    Looking back through this "discussion" I see that I did not mention it but I was having luck with the NUDGE TOOL after using the SHRINK TOOL and GROW TOOL.  Working with the UNLOCK / LOCK TOOL, it seems that that doing a SHRINK and a GROW indirectly performs an UNLOCK on the MEASUREMENT OBJECTS which allows them to be NUDGED.

    With this new information, I have attempted to create a ROUTINE that handles everything needed to NUDGE a MEASUREMENT OBJECT.

    This code works GREAT the first time through after a restart and the DEBUG WINDOW shows a 111 while the NUDGE TOOL is active for the USER and while waiting for the OK BUTTON to be pressed.

    Unfortunately the second time this routine is run, the ROUTINE does not pause for the user to work with the NUDGE TOOL and then press the OK BUTTON.

    This is shown by the contents of the DEBUG WINDOW.

     111
    2017-07-05 12:02:22
     222
    2017-07-05 12:02:31
     444
    2017-07-05 12:02:31
     111
    2017-07-05 12:02:41
     222
    2017-07-05 12:02:41
     444
    2017-07-05 12:02:41

    Can you please help me resolve this issue?

    The TIF IMAGE with MEASUREMENT OBEJCTS that I have been using for testing is attached.

    Thank you very much for your assistance on this.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

        Public Sub NudgeSelectedMeasurementObject()
    
            'Declare LOCAL VARIABLES
            Dim MyCancelFlag As Boolean = False
    
            'Connect with the ACTIVE DOCUMENT
            Dim doc1
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            'Unlock MEASUREMENT OBJECTS
            With Measure.MeasurementsCommands.Unlock(Nothing)
                .Lock = False
                .Run(doc1)
            End With
    
            'Give the user the MEASUREMENT SELECTION TOOL
            Try
    
                    With Measure.Measurements.ToolsCommands.Select(Nothing)
                        .Tool = eMMTool.SelectionTool
                        .Prompt = _
                            "Please select the MEASUREMENT FEATURE(s) you want to NUDGE!" & vbLf & vbLf & _
                            "Please press OK to CONTINUE or CANCEL to TERMINATE!"
                        .Interactive = True
                        .Run(doc1)
                    End With
    
                Catch
    
                    'Raise the CANCEL FLAG
                    MyCancelFlag = True
    
                End Try
    
            'If the user pressed OK
            If MyCancelFlag = False _
                Then
    
                    'Use TRY and CATCH to handle errors
                    Try
    
                            Debug.Print 111
    
                            'Activate the POLY NUDGE TOOL
                            With ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
                                .CheckState=McCommand.mcCheckState.Checked
                                .Prompt = "Please use the NUDGE TOOL then press OK!"
                                .Interactive = True
                                .Run
                            End With
    
                            Debug.Print 222
    
                        Catch
    
                            Debug.Print 333
    
                        Finally
    
                            Debug.Print 444
    
                        End Try
    
                End If
    
            'Deactivate the POLY NUDGE TOOL
            With ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
                .CheckState=McCommand.mcCheckState.Unchecked
                .Prompt = Nothing
                .Interactive = False
                .Run
            End With
    
            'Deactivate all tools by selecting the NO TOOL
            With Measure.Measurements.ToolsCommands.Select(Nothing)
                .Tool = eMMTool.NoTool
                .Run(doc1)
            End With
    
            'Lock the MEASUREMENT OBJECTS
            With Measure.MeasurementsCommands.Unlock(Nothing)
                .Lock = True
                .Run(doc1)
            End With
    
        End Sub
    



  • 2017-07-06-093922

    Yuri --

    Any thoughts on why the NudgeSelectedMeasurementObject routine would run properly the first time it is run within PREMIER but then misbehaves until PREMIER is restarted?

    Thanks.

    -- Matt
  • Matt,

    I need more details to understand what you mean.
    The function should toggle the tool, so it will activate nudge tool 1st, 3rd, 5th time. Is that what you see?

    Yuri
  • 2017-07-06-155409

    Yuri --

    After restarting PREMIER, opening the EXAMPLE IMAGE, and running the ROUTINE, the USER will be prompted to SELECT a MEASUREMENT OBJECT.

    After the OK BUTTON is pressed the NUDGE TOOL will be activated and the USER will be prompted to NUDGE the SELECTED MEASUREMENT OBJECT.

    After the OK BUTTON is pressed the NUDGE TOOL is deactivated.

    I would think that running the ROUTINE again would produce the same results but it does not.

    This is shown in output of the DEBUG.PRINT where the first time through the pause between 222 and 444 is seen.  Until PREMIER is restarted, something causes the routine to proceed through the NUDGE without the PROMPT / INTERACTIVE giving the USER the opportunity to use the NUDGE TOOL.

    Your assistance with this mystery issue would be much appreciated.

    -- Matt
  • edited July 2017
    Matt, 

    You should not make that command interactive. Just use it as in my sample. It triggers the state of the nudge tool. 

    Yuri

  • 2017-07-06-164626

    Yuri --

    I tried using the equivalent of your NUDGEON (with an UNLOCK) and your NUDGEOFF (with a LOCK) with an INTERACTION BALLOON in between to give instructions and pause during the NUDGE but it wouldn't flow right.

    The NudgeSelectedMeasurementObject routine works GREAT the 1st time through.  Is there a way to resolve the issue that keeps it from working a second time?

    Thanks.

    -- Matt


  • 2017-07-07-103548

    Yuri --

    Thank you for your message and the code it contains.

    I modified my routine and yours and then linked them together as shown below.

    This works great as shown by the TRACE put into the DEBUG WINDOW

     111
    2017-07-07 10:54:25
     222
    2017-07-07 10:54:30
     444
    2017-07-07 10:54:30
     111
    2017-07-07 10:54:39
     222
    2017-07-07 10:54:48
     444
    2017-07-07 10:54:48

    and by the SCREEN CAPTURES below.

    Your code gives the APP the ability to give the USER instructions about the NUDGE TOOL and allows the APP to pauses until the USER is finished with the NUDGE TOOL.

    Again, this works great and I think it will be helpful to other folks creating APPS for IMAGE-PRO PREMIER.

    Thanks.

    -- Matt

    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-





        Public Sub NudgeSelectedMeasurementObject()
    
            'Declare LOCAL VARIABLES
            Dim MyCancelFlag As Boolean = False
    
            'Connect with the ACTIVE DOCUMENT
            Dim doc1
            With Application.DocumentCommands.Active(Nothing)
                .Run(doc1)
            End With
    
            'Unlock MEASUREMENT OBJECTS
            With Measure.MeasurementsCommands.Unlock(Nothing)
                .Lock = False
                .Run(doc1)
            End With
    
            'Give the user the MEASUREMENT SELECTION TOOL
            Try
    
                    'Make sure the POLY NUDGE TOOL is OFF
                    With ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
                        .CheckState=McCommand.mcCheckState.Unchecked
                        .Prompt = Nothing
                        .Interactive = False
                        .Run
                    End With
    
                    'Activate the MEASUREMENT SELECT TOOL in
                    With Measure.Measurements.ToolsCommands.Select(Nothing)
                        .Tool = eMMTool.SelectionTool
                        .Prompt = _
                            "Please select the MEASUREMENT FEATURE(s) you want to NUDGE!" & vbLf & vbLf & _
                            "Please press OK to CONTINUE or CANCEL to TERMINATE!"
                        .Interactive = True
                        .Run(doc1)
                    End With
    
                Catch
    
                    'Raise the CANCEL FLAG
                    MyCancelFlag = True
    
                End Try
    
            'If the user pressed OK
            If MyCancelFlag = False _
                Then
    
                    'Use TRY and CATCH to handle errors
                    Try
    
                            Debug.Print 111
                            Debug.Print Now()
    
                            'Call the routine that will trigger the NUDGE TOOL in INTERACTIVE MODE with PROMPT
                            UseNudgeToolInteractively
    
                            Debug.Print 222
                            Debug.Print Now()
    
                        Catch
    
                            Debug.Print 333
                            Debug.Print Now()
    
                        Finally
    
                            Debug.Print 444
                            Debug.Print Now()
    
                        End Try
    
                End If
    
            'Deactivate all tools by selecting the NO TOOL
            With Measure.Measurements.ToolsCommands.Select(Nothing)
                .Tool = eMMTool.NoTool
                .Run(doc1)
            End With
    
            'Lock the MEASUREMENT OBJECTS
            With Measure.MeasurementsCommands.Unlock(Nothing)
                .Lock = True
                .Run(doc1)
            End With
    
        End Sub
    
        Public Sub UseNudgeToolInteractively
    
            'Connect with the NUDGE TOOL
            Dim cm As McCommand = _
                ThisApplication.Commands("Select.Image.ToggleEditToolNudge").Instantiate
    
            'Activate the NUDGE TOOL
            cm.Execute
    
            'Display an INTERACTION BALLOON and wait for OK or CANCEL
            With Automate.ScriptingCommands.Interaction(Nothing)
                .Interactive = _
                    True
                .Text = _
                    "POLYGON NUDGE TOOL is ACTIVE"
                .Image = _
                    .GetImage("Select.Image.ToggleEditToolNudge")
                .Prompt= _
                    "Use the LEFT MOUSE BUTTON to edit the SELECTED OBJECT with the NUDGE TOOL." & vbLf & vbLf & _
                    "Use the MOUSE WHEEL to change the DIAMETER of the NUDGE TOOL." & vbLf & vbLf & _
                    "Press the N KEY to switch between the NUDGE TOOL and the MEASUREMENT SELECT TOOL." & vbLf & vbLf & _
                    "Press OK or CANCEL to FINISH."
                .Run(ThisApplication.ActiveDocument, Nothing)
            End With
    
            'Deactivate the NUDGE TOOL
            cm.Execute
    
        End Sub
    
    
Sign In or Register to comment.