![]() |
#1
|
|||
|
|||
![]()
Hi all!
i´ve been wondering if there´s a possibility to test if an application is running or not. example: because of the weird bitmap-convert-thing cmyk2rgb in coreldraw itself i´ve started creating a macro in coreldraw to export selection to bitmap (TIFF) and to open it in photoshop 7 (per vba), convert it there to rgb, save it and close it, then import it in coreldraw. but if the application itself (here photoshop) isn´t runnin' i´ll get an error-message. so the question is, how can be tested if photoshop is runnin or not? and if not, how can it be started per vba? thank you all for your suggestions ![]() |
#2
|
||||
|
||||
![]()
First question: how do you connect to Photoshop? Do you use GetObject method in VBA? If so, I would use CreateObject instead because this is supposed to launch the application if it is not already running (provided that Adobe implemented this correctly).
If this doesn't work, then probably the following code might help: Code:
Option Explicit Private Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type Private Const INFINITE = &HFFFF ' Infinite timeout Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, _ ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _ ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _ ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long Sub EnsurePhotoshopRunning() Dim hWnd As Long Dim nRet As Long Dim pi As PROCESS_INFORMATION Dim si As STARTUPINFO hWnd = FindWindow("Photoshop", vbNullString) If hWnd = 0 Then ' Photoshop is NOT running. Launch it. si.cb = Len(si) nRet = CreateProcess(vbNullString, "C:\Program Files\Adobe\Photoshop\Photoshop.exe", 0, 0, 0, 0, 0, vbNullString, si, pi) If nRet = 0 Then MsgBox "Unable to launch Adobe Photoshop", vbCritical Else WaitForInputIdle pi.dwProcessId, INFINITE CloseHandle pi.hProcess CloseHandle pi.hThread End If End If End Sub Make sure you have the correct application path in CreateProcess method. |
#3
|
|||
|
|||
![]()
Hi Alex,
first of all thank you for your fast reply. ![]() i referenced the 'adobe photoshop 7 object library' in my vba and it works perfectly.. i thought, there would be a simple way like if application.photoshop.isrunning then makethethings else photoshop.start sorry i am a beginner in vba ![]() thanks for your help |
#4
|
|||
|
|||
![]()
Does anybody know the window classname for Illustrator CS?
|
#5
|
|||
|
|||
![]()
Nevermind..got it. Illustrator9
Spent so much time looking on the web for it, instead of just finding a getclassname function. ![]() |
#6
|
|||
|
|||
![]()
Ok I have a script to first check if a selected program is running, in this case Illustrator...and if not you have the option to launch it. If it is running I was checking for open documents. I have a problem if illustrator is not running, you launch it. Its starting up for sure but when i run the script again it crashes at
Run time error 462 The remote machine does not exist or is unavailable. Code:
If Illustrator.Documents.Count > 0 Then I can press end & immediately run the script again & it gets past that. I thought maybe there was something like Corel's Delay VBA load but i don't see anything. Anyone has any idea i'm all ears. |
#7
|
||||
|
||||
![]()
Mark,
It looks like you are trying to access the different instance of illustrator. Did you call "Quit" in previous session to shut down the program without releasing the reference to it and then using the old reference to access the Illustrator's functionality? Could you show the complete code of your program to see how you manage automation sessions? P.S. I tried to find a download of Illustrator CS COM plugin but can't. Is it now part of the application or still a separate plugin? |
#8
|
|||
|
|||
![]()
Ok...I've narrowed down the problem a bit. I have a form with two buttons, GrabImage & Launch, a listbox...containing "Adobe Illustrator" & "Adobe Photoshop" in it. Upon selecting one, I run the code
Code:
Sub AppList_Click() GrabImage.Enabled = False AppImage.Picture = LoadPicture("G:\Script Files\Icons\Applications\" + AppList.Value + ".bmp") Dim hwnd As Long hwnd = IsApplicationRunning(AppList.Value) If hwnd <> 0 Then Launch.Enabled = False If AppList.Value = "Adobe Illustrator" Then If Illustrator.Documents.Count > 0 Then GrabImage.Enabled = True End If End If If AppList.Value = "Adobe Photoshop" Then If Photoshop.Documents.Count > 0 Then GrabImage.Enabled = True End If End If Else Launch.Enabled = True End If End Sub Code:
Private Sub Launch_Click() Call LaunchApplication(AppList.Value) Unload Me End Sub Code:
If Illustrator.Documents.Count > 0 Then |
#9
|
|||
|
|||
![]()
A new form, haven't really got the hang of Adobe's scripting but....just so you can see what i'm doing. The selection I have on illustrator needs work. Haven't figured out a way to just select all. There's a pageitems but can't seem to figure out how to use it. If it even means what I think it means.
Code:
Private Sub GrabImage_Click() If Application.Documents.Count = 0 Then MsgBox "Nothing to paste to. Open a document & try again." Exit Sub End If Dim hwnd As Long, UndoLevel As Integer UndoLevel = 0 Clipboard.Clear hwnd = IsApplicationRunning(AppList.Value) If AppList.Value = "Adobe Photoshop" Then If Photoshop.Documents.Count > 0 Then If Photoshop.ActiveDocument.Layers.Count > 1 Then Photoshop.ActiveDocument.Flatten UndoLevel = UndoLevel + 1 End If Photoshop.ActiveDocument.Selection.SelectAll Photoshop.ActiveDocument.Selection.Copy Photoshop.ActiveDocument.ActiveHistoryState = Photoshop.ActiveDocument.HistoryStates(Photoshop.ActiveDocument.HistoryStates.Count - (UndoLevel + 1)) ActivePage.Layers("Design").Activate ActivePage.Layers("Design").Visible = True ActivePage.Layers("Design").Editable = True ActivePage.Layers("Design").Printable = True ActiveLayer.Paste Call SizeToFit ActiveSelection.ConvertToBitmap , , , , 600 ActivePage.Layers("Design").Printable = False End If ElseIf AppList.Value = "Adobe Illustrator" Then If Illustrator.ActiveDocument.PageItems.Count > 0 Then Dim txtsh As Illustrator.TextFrame, sh As Illustrator.PathItem For Each txtsh In Illustrator.ActiveDocument.TextFrames txtsh.CreateOutline Next For Each sh In Illustrator.ActiveDocument.PathItems sh.Selected = True Next Illustrator.ActiveDocument.Copy PasteAIFormat End If If ActiveSelection.Shapes.Count > 0 Then Call SetOutlineToScale ActiveSelection.Group Call SizeToFit CorelScript.AlignToCenterOfPage 3, 3 ActiveSelection.Ungroup End If End If Clipboard.Clear Unload Me End Sub Hopefully I've explained my problem well enough, let me know if you see anything wrong or have any ideas. Thanks for the quick reply. P.S. You might find this useful ![]() http://partners.adobe.com/asn/illust...ptingGuide.pdf |
#10
|
||||
|
||||
![]()
Mark,
I believe your problem is in implicit Application object creation. Whenever you reference a global property of the Application object, like ActiveDocument in your example, the Application object will be created for you automatically. This reference is cached by your application until it quits, so once you connected to it, you cannot actually disconnect and if you close the application manually from the Illustrator or Photoshop then try to re-run your code it will try to reuse the old reference which is no longer there (that is, by the way, a mistake on Adobe's part - they should not quit until all the external references are gone, but that's another conversation). Anyway, to resolve the issue, you must use an explicit object instantiation. You must declare an application variable yourself and set its value to something. For example: Code:
Sub YourTestRun() Dim illy As Illustrator.Application .... Set illy = New Illustrator.Application ' This actually creates the application object ... ' Use the app reference as you please If illy.ActiveDocument.Count >0 Then ... ... Set illy = Nothing ' kill the reference .... End Sub The same applies to photoshop (as does it apply to CorelDRAW but at least CorelDRAW will not shut down on you and kill the links to its automation client). I hope this helps. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Trying to get my Time Recording script running... | johndankey | CorelDRAW/Corel DESIGNER VBA | 12 | 26-04-2004 22:48 |
Accesing CorelDraw 10 VBA Object Model without running it | dolmos | CorelDRAW/Corel DESIGNER VBA | 5 | 19-12-2003 07:52 |
Application and Default Settings | MrClark | CorelDRAW CS | 2 | 18-12-2003 09:35 |
takes Draw a long time to start a new document! | bbolte | CorelDRAW/Corel DESIGNER VBA | 5 | 14-05-2003 09:09 |
Font Substitution Upon Import | RobC | CorelDRAW/Corel DESIGNER VBA | 4 | 10-03-2003 23:06 |