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

Activating and using the SPLIT TOOL via a BUTTON in an APP . . .

All --

I have an application where I would like a button to:

    ** Turn on the SPLIT TOOL
    ** Allow the user to SPLIT OBJECTS
    ** Apply the SPLITS
    ** Turn off the SPLIT TOOL

The SplitDemo code below is the guts of the function I currently have supporting my SPLIT BUTTON.  Unfortunately if the user presses OK without actually creating a SPLIT LINE then the SPLITCOMMANDS.APPLY performs an AUTO SPLIT.  If the user presses CANCEL everything is okay.

It looks like the
                    .UseLines = True
is meant to control this behavior but it doesn't seem to work if there are no SPLIT LINES on the image.

Is there a way to check if there are any SPLIT LINES on the image between the
                'Activate the SPLIT TOOL and give the user a prompt
                With Measure.Measurements.ToolsCommands.SplitTool(Nothing)
and the
                'Perform any SPLITS
                With Measure.Measurements.SplitCommands.Apply(Nothing)
sections of this code?

Also . . .

Is there a good way to DEACTIVATE the SPLIT TOOL?  The only way that I could work out is to activate another TOOL (I chose the MEASUREMENT SELECT TOOL).

Thanks.

-- Matt

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

Public Sub SplitDemo ()

        Try

                'Activate the SPLIT TOOL and give the user a prompt
                With Measure.Measurements.ToolsCommands.SplitTool(Nothing)
                    .Tool = eMMTool.splittool
                    .Prompt = "Please SPLIT the appropriate POSITIVE AREAS and then press OK."
                    .Interactive = True
                    .Run(ThisApplication.ActiveDocument)
                End With

                'Perform any SPLITS
                With Measure.Measurements.SplitCommands.Apply(Nothing)
                    .UseLines = True
                    .SelectedOnly = False
                    .Run(ThisApplication.ActiveDocument)
                End With

            Catch

                'Do nothing

            Finally

                'Do nothing

            End Try

        'Activate the MEASUREMENT SELECT TOOL for the user
        With Measure.Measurements.ToolsCommands.Select(Nothing)
            .Tool = eMMTool.SelectionTool
            .Run(ThisApplication.ActiveDocument)
        End With

End Sub

Best Answers

  • Answer ✓
    Hi Matt,

    Here is the function that can test for Split lines:

        Public Function HasSplitLines As Boolean
            Dim im =ThisApplication.ActiveImage
            Return im IsNot Nothing AndAlso im.Properties.Exists("SplitLines") AndAlso im.SplitLines.Count>0
        End Function
    
        Public Sub TestSplitLines
            MsgBox "Spilt lines = " & HasSplitLines
        End Sub
    
    

    Activating any other tool is one of the ways of switching tools. You can also switch to NoTool:

            With Measure.Measurements.ToolsCommands.Select(Nothing)
                .Tool = eMMTool.NoTool
                .Run(ThisApplication.ActiveDocument)
            End With
    

    Yuri
  • Answer ✓
    Yuri --

    Thank you for those two pieces of CODE.

    They look like they will provide the missing links needed to resolve this challenge.

    I'll wire them in this afternoon.

    Thanks again.

    -- Matt

Answers

  • YuriG said:
    Hi Matt,

    Here is the function that can test for Split lines:

        Public Function HasSplitLines As Boolean
            Dim im =ThisApplication.ActiveImage
            Return im IsNot Nothing AndAlso im.Properties.Exists("SplitLines") AndAlso im.SplitLines.Count>0
        End Function
    
        Public Sub TestSplitLines
            MsgBox "Spilt lines = " & HasSplitLines
        End Sub
    
    

    Activating any other tool is one of the ways of switching tools. You can also switch to NoTool:

            With Measure.Measurements.ToolsCommands.Select(Nothing)
                .Tool = eMMTool.NoTool
                .Run(ThisApplication.ActiveDocument)
            End With
    

    Yuri

    Hi Yuri,

    I got a new problem.
    I using HasSplitLines function can return value at first time .
    When change another image it will popup error message as follow as showing..

    This is cause by the code '
    im.SplitLines.Count'.
    Is there any way to solve this problem?


    [Error Message]
    Error in Image-ProImage-Pro has encountered a problem.Cannot access property IMcImage.

    ErrorCode: -2147352573Message: Cannot access property IMcImage.Data: System.Collections.ListDictionaryInternalInnerException: NothingTargetSite: System.Object LateGet(System.Object, System.Type, System.String, System.Object[], System.String[], Boolean[])StackTrace:    at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)   at IMCAddIn.IMC_Module.TestSplitInesFunction()   at IMCAddIn.IMCPanel.Button3_Click(Object sender, EventArgs e)   at System.Windows.Forms.Control.OnClick(EventArgs e)   at System.Windows.Forms.Button.OnClick(EventArgs e)   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)   at System.Windows.Forms.Control.WndProc(Message& m)   at System.Windows.Forms.ButtonBase.WndProc(Message& m)   at System.Windows.Forms.Button.WndProc(Message& m)   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)HelpLink: NothingSource: HResult: -2147352573Call Stack: System.Object LateGet(System.Object, System.Type, System.String, System.Object[], System.String[], Boolean[]): Name: LateGet DeclaringType: Microsoft.VisualBasic.CompilerServices.LateBinding ReflectedType: Microsoft.VisualBasic.CompilerServices.LateBinding MemberType: Method MetadataToken: 100664934 Module: Microsoft.VisualBasic.dll IsSecurityCritical: False IsSecuritySafeCritical: False IsSecurityTransparent: True MethodHandle: System.RuntimeMethodHandle Attributes: PrivateScope, Public, Static CallingConvention: Standard ReturnType: System.Object ReturnTypeCustomAttributes: System.Object  ReturnParameter: System.Object  IsGenericMethod: False IsGenericMethodDefinition: False ContainsGenericParameters: False MethodImplementationFlags: Managed IsPublic: True IsPrivate: False IsFamily: False IsAssembly: False IsFamilyAndAssembly: False IsFamilyOrAssembly: False IsStatic: True IsFinal: False IsVirtual: False IsHideBySig: False IsAbstract: False IsSpecialName: False IsConstructor: False CustomAttributes: System.Collections.ObjectModel.ReadOnlyCollection`1[System.Reflection.CustomAttributeData] System.Object LateGet(System.Object, System.Type, System.String, System.Object[], System.String[], System.Type[], Boolean[]): Boolean TestSplitInesFunction(): Void Button3_Click(System.Object, System.EventArgs): Void OnClick(System.EventArgs): Void OnClick(System.EventArgs): Void OnMouseUp(System.Windows.Forms.MouseEventArgs): Void WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32): Void WndProc(System.Windows.Forms.Message ByRef): Void WndProc(System.Windows.Forms.Message ByRef): Void WndProc(System.Windows.Forms.Message ByRef): IntPtr Callback(IntPtr, Int32, IntPtr, IntPtr):

    Wesan
  • edited September 2021
    Hi Wesan,

    It works for me. What is your another image? Is it an image or image set? Try to test on different images, and also try to run the macro TestSplitLines directly (not from the button) to see if you find any clue. 

    Yuri
  • edited September 2021
    Hi Yuri,

    It works in every images when using IP-10 project's function. 
    Indeed, I got this error from click button in add-In module.
    But I have to use it in the add-In.
    What should I do? Please give me a help.


    Wesan
  • Hi Wesan,

    We need a way to reproduce the problem. Can you make a small test project that reproduces the problem and post it on the forum?

    Yuri

  • Hi Yuri,

    Please refer to the project file in the attached file. Thank you.


    Wesan
  • Hi Wesan,

    Thanks for the test project, I checked it and found a solution. The problem was related to accessing dynamic McImage properties from the addin. You should modify the code to fix the problem:

        Public Function HasSplitLines() As Boolean
            Dim im As McImage = ThisApplication.ActiveImage
            Dim chkResult As Boolean = True

            Return im IsNot Nothing AndAlso im.Properties.Exists("SplitLines") AndAlso im.Properties("SplitLines").Count > 0
        End Function


    Regards,

    Yuri
  •  Hi Yuri,

    I appreciate your help very much. o:) 


    Wesan
Sign In or Register to comment.