CODE TO SET FULL FILE NAME (PATH & FILE & EXTENSION) FOR QUICK SAVE ANALYSIS AND PUBLICATION . . .
2020-09-11-174452
All --
The CODE below is embedded within an APP I wrote for an IMAGE-PRO PREMIER 9.3 user back in 2016.
They have asked me if we can alter the APP to give them more control of the names of the IMAGE FILES.
I know that if the
IMAGE-PRO + FILE + OPTIONS + FILE + QUICK SAVE + PROMPT FOR FILE NAME OPTION
is activated, they will be prompted for the FILE NAME for the ANALYSIS IMAGE and then they will be prompted for the FILE NAME for the PUBLICATION IMAGE.
Is there a way for the CODE to set the FILE NAME that will be used?
I poked around in the HELP FILES and could not find an answer.
I tried
ThisApplication.Settings("QuickSave","Publication").Set("File","aaa.jpg") ThisApplication.Settings("QuickSave","Analysis").Set("File","bbb.tif")
and
ThisApplication.Settings("QuickSave","Publication").Set("Filename","aaa.jpg") ThisApplication.Settings("QuickSave","Analysis").Set("Filename","bbb.tif")
Neither of these worked. IMAGE-PRO wanted to use the FILENAME that was already affiliated with the image.
I tried to change the DISPLAY NAME for the IMAGE but QUICK SAVE ignored the DISPLAY NAME and went somewhere else to get the name it uses.
Is there CODE that will allow me to use the QUICK SAVE FEATURE and a FILE NAME that my CODE sets independent of what the image has been saved as before (example with a DATE & TIME STAMP)?
Thanks in advance.
-- Matt
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Private Sub button_SaveImage_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button_SaveImage.Click
'Declare LOCAL VARIABLES
Dim imageA, docA, windowA
Dim varList1 = New List(1)
Dim varList2 = New List(1)
'Set the DEFAULT PATH for the QUICK SAVE ANALYSIS and QUICK SAVE PUBLICATION
ThisApplication.Settings("QuickSave","Publication").Set("Path",textBox_WorkingFolder.Text)
ThisApplication.Settings("QuickSave","Analysis").Set("Path",textBox_WorkingFolder.Text)
'Connect with the ACTIVE IMAGE
With Application.DocumentCommands.ActiveImage(Nothing)
.Run(imageA)
End With
With Application.DocumentCommands.Activate(Nothing)
.Run(imageA, docA)
End With
With Application.WindowCommands.Define(Nothing)
.Run(docA, windowA)
End With
'Perform the QUICK SAVE ANALYSIS
With Application.WindowCommands.QuickSaveSelectedForAnalysis(Nothing)
.Run(varList1)
End With
'Activate the APPROPRIATE IMAGE
With Application.DocumentCommands.Activate(Nothing)
.Run(imageA, docA)
End With
'Perform the QUICK SAVE ANALYSIS
With Application.WindowCommands.QuickSaveSelectedForPublication(Nothing)
.Run(varList2)
End With
'Activate the APPROPRIATE IMAGE
With Application.DocumentCommands.Activate(Nothing)
.Run(imageA, docA)
End With
End Sub
'Declare LOCAL VARIABLES
Dim imageA, docA, windowA
Dim varList1 = New List(1)
Dim varList2 = New List(1)
'Set the DEFAULT PATH for the QUICK SAVE ANALYSIS and QUICK SAVE PUBLICATION
ThisApplication.Settings("QuickSave","Publication").Set("Path",textBox_WorkingFolder.Text)
ThisApplication.Settings("QuickSave","Analysis").Set("Path",textBox_WorkingFolder.Text)
'Connect with the ACTIVE IMAGE
With Application.DocumentCommands.ActiveImage(Nothing)
.Run(imageA)
End With
With Application.DocumentCommands.Activate(Nothing)
.Run(imageA, docA)
End With
With Application.WindowCommands.Define(Nothing)
.Run(docA, windowA)
End With
'Perform the QUICK SAVE ANALYSIS
With Application.WindowCommands.QuickSaveSelectedForAnalysis(Nothing)
.Run(varList1)
End With
'Activate the APPROPRIATE IMAGE
With Application.DocumentCommands.Activate(Nothing)
.Run(imageA, docA)
End With
'Perform the QUICK SAVE ANALYSIS
With Application.WindowCommands.QuickSaveSelectedForPublication(Nothing)
.Run(varList2)
End With
'Activate the APPROPRIATE IMAGE
With Application.DocumentCommands.Activate(Nothing)
.Run(imageA, docA)
End With
End Sub
0
Answers
If you want to prompt user to save image under user-defined name, then you should just use SaveAs command, like this:
It will cover saving to TIF or JPG.
If you want to have an equivalent of "Save for publication", then you should use "Snap" command (to burn all overlays in) and then SaveAs (close Snap image in the end).
Yuri
If you want to use your old code for Quick save, then you can control Prefix of the file name from a macro:
and the index will be generated automatically, if files with the same name already exist.
For newly captured files you can also define DisplayName, which will then be used for QuickSave:
Sub SetDisplayName ThisApplication.ActiveImage.DisplayName="MyNameForPublication" End Sub
Note, that for images opened from files, QuickSave will try using existing FileName.Yuri
Regarding QuickSave: FileName has priority for QuickSave. Maybe your captured images are saved on capture, so they have file name already and simply assigning DisplayName will not affect QuickSave.
A workaround for that is to clear file name, so quick save will use DisplayName:
Sub SetDisplayName Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub If im.File IsNot Nothing Then 'reset existing file name im.File.FullPathName="" End If 'set display name to be used with QuickSave im.DisplayName="MyNameForPublication" End Sub
Regarding compression: I tested it in IP 10.0.7 and don't see the problem, the compression is set properly from the first time. If you see this issue in 9.3, then you can use the workaround you've found.Best regards,
Yuri
You shouldn't rely on DisplayName to identify the file, but rather use File.FullPathName or File.FileName. You can also strip extension using .NET function System.IO.Path.GetFileNameWithoutExtension(...)
Yuri
Yes, you can use ActiveDocument.FileName, it returns the same name.
Yuri