Download Example File
Import with Dialog Script
To understand how this example works, open ScriptMaker/Manage Scripts and edit the "Import with Dialog" script.
Set Field[Image::Image; Let([ theimport = CNSImage_Import( “”; “”; "Please select an image…
The script uses the Set Field script step to set the “Image::Image” field with the image that is imported via the plug-in. Select the Set Field script step and click the “Calculated result:” Specify button in the bottom left corner.
Let([ theimport = CNSImage_Import( “”; “”; “Please select an image to import”) ]; If( theimport = “ERROR: Import: User Cancelled.” ; Image::Image; theimport ) )
In this calculation, the CNSImage_Import function is called inside a Let function. This is not required to use the CNSImage_Import function, but this allows us to trap for the user cancelling the dialog. The data returned from the CNSImage_Import function is stored in the “theimport” variable, and then the If statement is used to check if the variable contains the “ERROR: Import: User Cancelled.” error. If it does, we set the Image::Image field to itself, otherwise we return the variable so the image is placed in the field.
Take a look at just the plug-in’s function call from above.
CNSImage_Import( “”; “”; “Please select an image to import”)
The function has separate parameters for specifying different settings during the import. To understand what the above code is doing, take a look at the prototype of the function:
CNSImage_Import ( Path ; TypeList ; Prompt )
The first parameter is the path and filename of the image to import. You can also leave this parameter blank "" to open a file dialog, which is what the calculation in this example does. The second parameter is the list of image types you want to allow the user to import. If this is left blank like in this example, the user can import any type of image the plug-in supports. Finally, the third parameter is simply a message to be displayed in the file dialog. In this example, we have this set as “Please select an image to import”.
For more information about this function, see the CNSImage_Import function in the Function Reference.