OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > Corel Photo-Paint VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-08-2010, 13:03
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default Macro to select Lightness

I am trying to create a PP X5 macro to select the Lightness of an image. Previously, I used one that Michael Cervantes wrote for me, but it will not work in X5.

I know the steps to do it manually, so I thought I would record it with the script recorder and use that info to make my macro for X5. I cannot seem to get it to work in X5. I think it might have something to do with the new color management??

These are the steps used to do it manually (with your image open, of course):

1. Mask>Select All (CTRL+A)
2. Edit>Copy (CTRL+C)
3. Mask>Enter Paint on Mask Mode (CTRL+K)
4. Edit>Paste>Paste As Selection
5. Mask>Exit POM mode (CTRL+K)

If you copy the selection to a new layer you'll see a pale/transparent copy of the image (everything 128 and above in grayscale range).

This is the .csc that is recorded:

Code:
WITHOBJECT "CorelPHOTOPAINT.Automation.15"
	.SetDocumentInfo 1600, 1200
	.MaskSelectAll 
	.EditCopy 
	.MaskPaint 1
	.EditPasteSelection 0, 1199, CHR(7) + "C:+AFw-Users+AFw-PATTIA+AH4-1+AFw-AppData+AFw-Local+AFw-Temp+AFw-XXXX3013.TMP", "sRGB IEC61966-2.1", "sRGB IEC61966-2.1"
	.MaskPaint 2
END WITHOBJECT

I changed it to this for my macro to make it work on any image:

Code:
Option Explicit

Sub SelectLightness()
    With CorelScript
        .MaskSelectAll
        .EditCopy
        .MaskPaint 1
        .EditPasteSelection
        .MaskPaint 2
    End With
End Sub
I think something is missing with the EditPasteSelection step, but what? Can someone help, please?

TIA
Patti
Reply With Quote
  #2  
Old 03-08-2010, 00:20
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default EditPasteSelection

You are correct on both assumptions. They added the ColorContextToAssign and ColorContextToConvert to the .EditPasteSelection and that is why you have the "sRGB IEC61966-2.1", "sRGB IEC61966-2.1" in your recorded code. The problem is, I can't get it to work consistently.

So I tried to write a VBA version, and it was still flaky, so I had to create a few workarounds. I think this will work, give it a shot and let me know if not. This was tested on X5 SP1.
Code:
Sub VBASelectLightness()
    Dim doc As Document
    
    Set doc = ActiveDocument
    
    doc.Mask.SelectAll
    doc.Background.Copy
    doc.Mask.PaintOnMask = True
    Application.FrameWork.Automation.InvokeItem "9ca437cb-34ea-4c4b-afca-5d403425815a"
    DoEvents
    doc.Mask.PaintOnMask = False
End Sub
-Shelby
Reply With Quote
  #3  
Old 04-08-2010, 14:33
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default

Quote:
Originally Posted by shelbym View Post
You are correct on both assumptions. They added the ColorContextToAssign and ColorContextToConvert to the .EditPasteSelection and that is why you have the "sRGB IEC61966-2.1", "sRGB IEC61966-2.1" in your recorded code. The problem is, I can't get it to work consistently.

So I tried to write a VBA version, and it was still flaky, so I had to create a few workarounds. I think this will work, give it a shot and let me know if not. This was tested on X5 SP1. [code]

-Shelby
It works fine, tested on high and low resolution images. You are the wizard of workarounds! Now, educate me a little...Can you please tell me what these two lines are doing? What is being invoked with those numbers (the clipboard contents??? paste??) And...how on earth do you know what is assigned to those numbers? I know there is an XML file, but do you have a list of what they are...or do you just remember?
Application.FrameWork.Automation.InvokeItem "9ca437cb-34ea-4c4b-afca-5d403425815a"
DoEvents
Now let me vent for a moment...

This is what's sooooo aggravating about Photo-Paint's lack of VBA support. We should be able to automate a simple task, without being a VBA wizard (love you Shelby!). Recording a script to help is just about useless anymore. Sigh.

BTW, in Photoshop, to select the lightness (a.k.a. luminosity) is super easy...all you do is CTRL click the RGB composite on the channels palette. You can also copy any channel this way. We need little things like that implemented in PP.

Okay, I'm done venting for now -- ha!

Meanwhile, I'm going to keep investigating this channel select thing. Maybe there are some easier steps to accomplish it.

Patti
Reply With Quote
  #4  
Old 04-08-2010, 16:22
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default

Quote:
Originally Posted by PAnderson
Now, educate me a little...
Wait, you expect me to tell you all my secrets. All right, you talked me into it, put shhhhh it is just between me and you.

Quote:
Originally Posted by PAnderson
What is being invoked with those numbers (the clipboard contents??? paste??) And...how on earth do you know what is assigned to those numbers?
Because I could not get the .EditPasteSelection to work reliably, yet as you said doing it manually worked fine I decide to simulate the manual method.

The following line:
Code:
Application.FrameWork.Automation.InvokeItem "9ca437cb-34ea-4c4b-afca-5d403425815a"
Does exactly that, it basically calls the Paste as New Section button, just as if you pressed it.

Now how did I find the crazy number for it. I created a new toolbar and added the single button "Paste as New Section". I then exported the workspace, exporting only the new toolbar I created. That will create a .xslt file that you can then look at and get the magic number. By exporting a single toolbar with a single button it is pretty easy to pick out the correct number. :-) (Thanks Steve for teaching me this trick.)

Now, I would have thought that would have worked, but again, the results were not realible, but will playing with it I notice if there was a short pause after the paste, it would then work. So I added the:
Code:
DoEvents
To simulate my pause, and sure enough it worked. The DoEvents, passes control back to the OS and then returns control back to VBA, since I am no telling it to do anything, it really just creates a long enough pause that things seem to work. Crazy I know!

-Shelby
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
guideline select macro bob_w General 0 04-02-2010 13:57
backspace with select keytecstaff CorelDRAW/Corel DESIGNER VBA 1 11-10-2006 10:59
How to select all shape ? -=HKLC=- CorelDRAW/Corel DESIGNER VBA 1 25-10-2004 01:10
Select All ddonnahoe CorelDRAW/Corel DESIGNER VBA 4 10-02-2004 10:14
VBA Select Printer? Jon Lorber CorelDRAW/Corel DESIGNER VBA 1 12-12-2003 10:36


All times are GMT -5. The time now is 08:39.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com