getting object position via vba

Moderator: Kathy_9

Post Reply
paperjams
Posts: 3
Joined: Wed Dec 09, 2020 10:59 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit

getting object position via vba

Post by paperjams »

Hello,
I'm working on designing an app that consists of a single background and many many buttons.
I have the look layed out in paintshop pro 2020, and I would like to get the positions of all the buttons.
Each element is in it's own layer.
The background is it's own layer/object and each button is it's own layer.
Is there a way to get the position of each button relative to the size of the entire image?

Also the buttons are created automatically by a script that uses TextTool as captured from the macro recorder. What i'm encountering sometimes is that the font size is to big and overruns the button. How would I detect this and scale back the font size?
-james
LeviFiction
Advisor
Posts: 5985
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8, 9, X, XI, X2, X8,X9, 2018, 2019
Location: USA

Re: getting object position via vba

Post by LeviFiction »

To get the rectangle to represents any selected object the command is GetVectorSelectionRect

Code: Select all

    info = App.Do( Environment, 'GetVectorSelectionRect', {})
That returns a dictionary with one of the keys being 'VectorRect'. This returns a tuple (non-editable array) of three values: 0) Another tuple of 2 values (x,y), 1) Width, 2)Height.

Code: Select all

    info = App.Do( Environment, 'GetVectorSelectionRect', {})
    x,y = info['VectorRect'][0]
    width,height = info['VectorRect'][1], info['VectorRect'][2]
As for text.

If you know the size of the object you're comparing the size of the text to, you can easily just check the rectangles and then use the TextEx command to change the size of the text, and then recheck until it comes out how you want.
paperjams
Posts: 3
Joined: Wed Dec 09, 2020 10:59 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit

Re: getting object position via vba

Post by paperjams »

Thanks that makes sense and now for the embarrassing part.
I'm using photo-paint 2020 :oops: which would explain why the docs didn't match up...

The concept should still apply, just need to find the commands for it in the correct product documentation.
User avatar
Ken Berry
Site Admin
Posts: 21462
Joined: Fri Dec 10, 2004 9:36 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Intel NUC7i7BNB J31145-306
processor: Core i7-7567U + 32 GB Optane
ram: 16 GB
Video Card: Intel Iris Plus 650
sound_card: Realtek High Definition Audio
Hard_Drive_Capacity: 2TB
Monitor/Display Make & Model: Kogan 32" 4K 3840 x 2160
Corel programs: VS 2020; PSP 2020; MS3D; ASP 3; DRAW 17
Location: Levin, New Zealand

Re: getting object position via vba

Post by Ken Berry »

You could also register again in the CorelDRAW community at https://community.coreldraw.com/ It looks after Photo-Paint, not us.
Ken Berry
paperjams
Posts: 3
Joined: Wed Dec 09, 2020 10:59 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit

Re: getting object position via vba

Post by paperjams »

sounds good, I will head over there.
Sorry for the noise.
Post Reply