OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 20-01-2005, 11:41
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default Howto uniquely identify a shape in VBA code

Hi all,

I am writing a macro to scale all the objects in a drawing by the relative size of one shape. This shape is on layer 2 and is nudged to size over a bitmap on layer 1. This is for tracing bitmaps and referencing them to real-world sizes. An example is a small flat item photographed over a .250 x .250 grid. I would like to give the scaling reference shape (a library synbol) an identity that can be read as a property in VBA so I can find it in the drawing, get it's X-axis dimension and then scale all objects by the delta of the current size versus the target size. I have all the code to do that, but I have to manually select the scaling reference shape. How can I name this shape internally and maybe even encode the ultimate target X dimension??

TIA

-James Leonard
Reply With Quote
  #2  
Old 11-02-2005, 02:09
zlatev
Guest
 
Posts: n/a
Default In CorelDraw 12

There is "Name" property in Object Data Manager. (Window - Dockers - Object Data Manager)

After you set the Name property, you can cycle through the objects on Layer 2 and find the shape by using condition like (assuming that oCurrentShape contains a Shape from Layer2):
Code:
If oCurrentShape.ObjectData("Name").Value = "MyResizeShape" Then
' Do something
End If
Hope it makes sense to you. I have only tested in in CD12.

Why dont you like the user to select the shape?
Reply With Quote
  #3  
Old 11-02-2005, 07:18
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: In CorelDraw 12

There is a shortcut to the Name property:

Code:
If oCurrentShape.Name = "MyResizeShape" Then 
' Do something 
End If
You can also use Shape.StaticID which guarantees uniqueness. While there could be more than one shape with the same name, the shape IDs are unique, but you can't change them and using Name is a bit easier and more intuitive and I prefer using SHa[e whenever possible.

You can also find a shape by name or StaticID quickly by using Shapes.FindShape method:

Code:
Dim s As Shape
Set s = ActivePage.Shapes.FindShape("MyResizeShape")
If Not s Is Nothing Then
    ' Do Something
End If
Reply With Quote
  #4  
Old 11-02-2005, 10:02
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default

Hi,

Thanks to all for your replies on this topic! I want to reserve the name field for plain-english display names of managed shapes while uniquely identifying types of shapes so I can write some very smart manipulation code. The scaler is only the first. I have been researching Datafields and ObjectData. Here is a snippet of code I am playing with to create document-global Datafields and then associate ObjectData with a particular shape. While the shape is open in the Shape Manager, it will be selected, otherwise I want these very routines to locate shapes by class and manipulate them according to embedded parameters.

Set ManagedShape = Nothing

If ActiveSelection.Shapes.Count > 0 Then

Set ManagedShape = ActiveSelection.Shapes(1)

End If

'Check if the custom DataFields are installed in this document
'and add/install them if not

bFound = False
For Each df In ActiveDocument.DataFields
If df.Name = "InlayDesignerShape" Then
bFound = True
Exit For
End If
Next df

'not found, add it

If bFound = False Then

ActiveDocument.DataFields.Add ("InlayDesignerShape")

ManagedShape.ObjectData("InlayDesignerShape").Value = 992#

Else

'ShapeTypeVal = ManagedShape.ObjectData("InlayDesignerShape").Value

End If

Comments on the applicability of this approach will be greatly appreciated!
__________________
-James Leonard
CNC Inlay Guy - www.CorelDRAWCadCam.com
Reply With Quote
  #5  
Old 11-02-2005, 11:12
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

This should work too. At least if you want these values to be visible to the end user through the Object Data Manager docker.

I would replace this piece of code:

Code:
Set ManagedShape = Nothing 
If ActiveSelection.Shapes.Count > 0 Then 
    Set ManagedShape = ActiveSelection.Shapes(1) 
End If
With just a simpler shortcut which does exactly the same:

Code:
Set ManagedShape = ActiveShape
You might as well investigate the custom object data which can be set through VBA by using Shape.Properties collection. These properties are quite easy to use in VBA and they are not shown in the Object Data Manager (good for some internal marking). They are also per-shape, that is, you don't have to set up any global data field first... You can also associate custom data with layers and the document itself.
Reply With Quote
  #6  
Old 11-02-2005, 12:52
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,787
Blog Entries: 11
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

I use the object data all the time. So I created a sub, that would check for the field and add it if it does not exsist. If you are going to use them alot you might consider somthing like this:

Code:
CheckDataItem ("InlayDesignerShape")

Private Sub CheckDataItem(diName As String)

Dim df As DataField

For Each df In ActiveDocument.DataFields
    If df.Name = diName Then Exit Sub 'Checks To See If DataItem Exists
Next df

ActiveDocument.DataFields.add diName, , True, True 'If DataItem Does Not Exists Create It

End Sub
Anyway, hope it helps,

Shelby
Reply With Quote
  #7  
Old 11-02-2005, 17:16
jemmyell jemmyell is offline
Senior Member
 
Join Date: Jan 2005
Location: Orange County, California, USA, Earth, Solar System, Milky Way Galaxy
Posts: 157
Default

Hi all,

again , thanks for all the insight. I do believe the global document objectdata will be fairly easy to use, but I can't make heads or tails of the syntax required to use shape.properties.objectdata. Does anybody have a code snippet showing insertion of new datafield dataitem and get/set of the value?
__________________
-James Leonard
CNC Inlay Guy - www.CorelDRAWCadCam.com
Reply With Quote
  #8  
Old 11-02-2005, 17:45
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Here are some examples on how to store custom data in document: http://www.oberonplace.com/forum/vie....php?p=854#854

The same applies to storing the data in layer, page, or shape. Also the online help contains a few more examples about using the Properties collection. Just hit F1 on the method name to see some help for it.
Reply With Quote
  #9  
Old 11-02-2005, 17:56
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,787
Blog Entries: 11
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

Alex is there a Find for the shape.properties? I mean if I have some code like this:

Code:
s.Properties("Color", 0) = "Yellow"
Can I easily find all the shapes I have assigned Yellow? Thanks for the insight.

Shelby
Reply With Quote
  #10  
Old 11-02-2005, 21:05
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

No, unfortunately there is not. You need to loop through shapes and do the lookup yourself.
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
Simple Bar code generator Webster Code Critique 2 06-09-2010 01:41
HOW-TO call coreldraw12 find dialog from VBA code???? wOxxOm CorelDRAW/Corel DESIGNER VBA 4 02-03-2008 08:32
Text ENCODE Craig Tucker CorelDRAW/Corel DESIGNER VBA 10 26-01-2005 13:59
activeselection cloning s_federici CorelDRAW/Corel DESIGNER VBA 2 05-11-2004 09:59
How can I extract a piece of a bitmap object using VBA code oswaldon Corel Photo-Paint VBA 2 25-04-2004 19:37


All times are GMT -5. The time now is 02:47.


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