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 17-05-2004, 14:56
Craig Tucker
Guest
 
Posts: n/a
Default Shape Looping...

All,
Is there a way to find/replace all shapes with the same name in CorelDRAW 10? I am importing multiple documents (actually the same document multiple times) into 1 document - thus duplicating the shape names that I need to change. The first shape it comes to gets the replace - the rest are left their original value.
Thanks much,
Craig...
Reply With Quote
  #2  
Old 17-05-2004, 15:51
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Shape Looping...

Craig,

Have you tried to use Page.FindShapes method? It can return a list of shapes matching your criteria. You can specify the name to look for and it will return you a list of shapes with the same name. Then you can just loop through them:

Code:
Dim s As Shape
For Each s In ActivePage.FindShapes("YourShapeName")
    ' Process the shape "s" here
Next s
Reply With Quote
  #3  
Old 17-05-2004, 16:15
Craig Tucker
Guest
 
Posts: n/a
Default

Oh thanks a ton Alex - Exactly what I needed!
Craig...
Reply With Quote
  #4  
Old 17-06-2004, 10:48
Craig Tucker
Guest
 
Posts: n/a
Default Shape Looping...

Hi Alex,
I finally got around to this and I can't seem to get it to work... Just a reminder that I'm still in V10...

Here's my current code
Set s = mPage.ActiveLayer.FindShape(lcLookFor)
If lbIsLogo = False Then
If Not s Is Nothing Then
s.Text.Contents = lcReplace

I tried pulling out the "Set s" and replacing with (and other combinations)
Dim s As Shape
For Each s In mPage.ActivePage.FindShapes(lcLookFor)...
but kept getting the object/property doesn't support... error on s.Text....
Any help would be appreciated...
Thanks, Craig...
Reply With Quote
  #5  
Old 17-06-2004, 11:45
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Shape Looping...

It means that you are finding shapes other than text. For example, one of your rectangles might be named the same way and you are picking it up. Obviously, s.Text.... won't work on a rectangle, or ellipse, or curve, etc.

Either fix your drawing to make sure that only text objects bear the name you are looking for, or add a check for text shapes:

Code:
Dim s As Shape
For Each s In ActivePage.FindShapes(lcLookFor)
    If s.Type = cdrTextShape Then
        s.Text.Contents = lcReplace
    End If
Next s
Reply With Quote
  #6  
Old 17-06-2004, 14:18
Craig Tucker
Guest
 
Posts: n/a
Default Shape Looping...

Hi Alex,
I get a compile error: Method or data member not found on .Text
CT...
Dim s As Shape
For Each s In ActivePage.FindShapes(lcLookFor)
If lbIsLogo = False Then
If Not s Is Nothing Then
s.Text.Contents = lcReplace
Reply With Quote
  #7  
Old 18-06-2004, 09:08
Craig Tucker
Guest
 
Posts: n/a
Default Shape Looping...

Hi Alex,
I get "Method or Data Member Not Found" -> If s.Type on compile with your sample...
Code:
Dim s As Shape 
For Each s In ActivePage.FindShapes(lcLookFor) 
    If s.Type = cdrTextShape Then 
        s.Text.Contents = lcReplace 
    End If 
Next s
Here's my current working code, but just finds the first shape, but not all w/ same name...
Code:
Set s = mPage.ActiveLayer.FindShape(lcLookFor)
                        If lbIsLogo = False Then
                            If Not s Is Nothing Then
                                s.Text.Contents = lcReplace
                                If s.Text.Type = cdrParagraphText And lbFTTF = True Then
Thanks again for the help,
Craig...
Reply With Quote
  #8  
Old 18-06-2004, 19:15
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Shape Looping...

Craig,

I don't know why you have a problem with my original code.

Here is a new one which I just tested on my CorelDRAW 10.427. Just create a few text objects and give them name "Label" through Object Manager.

Then run the following:

Code:
Sub ReplaceAllText()
    Const sNameToLookFor As String = "Label"
    Const sTextToSet As String = "Label #"
    
    Dim nLabelID As Long
    Dim s As Shape
    
    nLabelID = 1
    For Each s In ActivePage.FindShapes(sNameToLookFor, cdrTextShape)
        s.Text.Contents = sTextToSet & nLabelID
        nLabelID = nLabelID + 1
    Next s
End Sub
It will replace each text object with "Label #1", "Label #2", and so on.

There are two methods on Page - FindShape which returns the first object found; and FindShapes which returns a ShapeRange object, that is a list of all shapes found. You can iterate through them using For Each...Next as I showed in my above example.

In the code above I not only look for objects by name, but also by object type - particularly for text objects only, so I don't need to add another test to see the type of the object found to ensure it is a text.

I hope this helps...
Reply With Quote
  #9  
Old 18-06-2004, 19:20
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Shape Looping...

Craig,

On another thought, do you use VBA or stand alone Visual Basic. The thing is that VB has it's own Shape object, that is a form control which can look like a circle, rectangle, etc. So you end up with two Shape objects - one from VB and one from CorelDRAW and because VB type libraries are listed first in the References dialog, VB uses the form shape by default. To resolve ambiguity, you can either go to References dialog and move CorelDRAW type library higher in the list, or just specify CorelDRAW type library explicitly when declaring the variable:

Code:
Dim s As CorelDRAW.Shape
Reply With Quote
  #10  
Old 21-06-2004, 09:15
Craig Tucker
Guest
 
Posts: n/a
Default Shape Looping...

Code:
Dim s As CorelDRAW.Shape
That was it! Thanks a ton, Craig...
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
a shape on top of another Seelenquell CorelDRAW/Corel DESIGNER VBA 15 01-03-2008 08:08
Moving Shape to another page using C++ moodwin CorelDRAW/Corel DESIGNER VBA 4 18-03-2005 02:01
Howto uniquely identify a shape in VBA code jemmyell CorelDRAW/Corel DESIGNER VBA 9 11-02-2005 21:05
Getting the center X on a text shape Rick Randall CorelDRAW/Corel DESIGNER VBA 4 03-08-2004 18:27
finding node angles? IanVincent CorelDRAW/Corel DESIGNER VBA 4 12-12-2003 23:32


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


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