Home Image-Pro General Discussions
Options

How to return data from a function written as a simplescript?

    Public Function Open_Img(imgFilePath As String) As SimpleScript
        Open_Img = New SimpleScript
        Open_Img.SaveUndoSteps = False
        Dim docList
        Dim image
        Dim doc

        With Application.DocumentCommands.Open(Open_Img)
            .Filenames = New String() {imgFilePath}
            .Run(docList)
        End With

        With Application.DocumentCommands.ActiveImage(Open_Img)
            .Run(image)
        End With

        With Application.DocumentCommands.Active(Open_Img)
            .Run(doc)
        End With
	'Return doc??
	'Return image??
	How can I get anything out of this function?
	End Function

Best Answer

  • Options
    Answer ✓
    In this case the variable is passed byref so it will be returned from the function.

    That said, the main reason for using this syntax is to keep the code compatible with the interactive macro designer. If you are going to code your macros manually you can use a much simpler syntax without needing a SimpleScript object.

        Public Function GetImageDocument() As IMcDocument
    
            Dim docList1 As System.Collections.IList
    
            With Application.DocumentCommands.Open(Nothing)
                .Filenames = New String() {ThisApplication.Path(mcPathType.mcptSampleImages) & "Count and Size\micro_etch.tif"}
                .Run(docList1)
            End With
    
            Return docList1(0)
    
        End Function
    

    PIerre


Answers

  • Options
    edited February 2015
    You could do something like this:
        Public Function NewMacro(ByRef doc) As SimpleScript
            NewMacro = New SimpleScript
            Dim docList1 = New List(1), doc1
    
            With Application.DocumentCommands.Open(NewMacro)
                .Filenames = New String() {ThisApplication.Path(mcPathType.mcptSampleImages) & "Count and Size\micro_etch.tif"}
                .Run(docList1)
            End With
    
            With Application.DocumentCommands.Activate(NewMacro)
                .Run(docList1(0), doc1)
            End With
    
            With Automate.ScriptingCommands.CodeCommand(NewMacro)
                If .Run() Then
                    ' User Code Here
                    doc = doc1
                End If
            End With
    
        End Function
    
  • Options
    Pierre, thanks for the help. I've been working with IPP for 10 yrs but now trying to make the switch to 9.1 is painful. So from your code, it looks like the "doc" variable can be passed in, how to get the information contained in doc1 out to use in a calling subroutine like a normal function would be used. I guess I'm not getting it :).
Sign In or Register to comment.