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 29-05-2008, 21:13
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 Naming Shapes

This is an answer to another post, I felt it deserved its own thread. Basically the question what how do you name shapes, find the shapes, and then do something with them. Here is a little example.
Code:
Sub NameShapesX3()
    Dim s As Shape
    Dim srAll As ShapeRange
    Dim srDeleteMe As ShapeRange
    
    Set srAll = ActivePage.Shapes.FindShapes()
    srAll.RemoveRange srAll.FindAnyOfType(cdrGroupShape, cdrGuidelineShape)
    
    'Name all the shapes that do not have outline and fill or blank text strings
    For Each s In srAll
        If s.Fill.Type = cdrNoFill And s.Outline.Type = cdrNoOutline Then s.Name = "DeleteMe"
        If s.Type = cdrTextShape Then
            If Trim(s.Text.Story.Text) = "" Then s.Name = "DeleteMe"
        End If
    Next s
    
    'Find all the shapes we just named
    Set srDeleteMe = ActivePage.FindShapes("DeleteMe")
    
    'Display Message box on how many shapes Found
    MsgBox "Number of shapes named: " & srDeleteMe.Shapes.Count
    
    'Now lets do something with them
    For Each s In srDeleteMe
        'If it is a blank text string fill it with the word DeleteMe
        If s.Type = cdrTextShape Then
            s.Text.Story = "DeleteMe"
        Else
            'Just a shape add a red 4 point outline
            s.Outline.SetProperties 0.111, , CreateCMYKColor(0, 100, 100, 0)
        End If
    Next s
End Sub
Hope you find the example helpful!

-Shelby
Reply With Quote
  #2  
Old 29-05-2008, 23:51
norbert_ds
Guest
 
Posts: n/a
Default

Thanks Shelby!!

Is there a way to add an object name via Corel's user interface rather than via a script?

Regards
Norbert
Reply With Quote
  #3  
Old 30-05-2008, 01:44
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 Yep

Open the Object Manager Docker select the shape you want to name and right click, then click rename.

You can also do something similar with the Object Data Docker. That docker lets you build your own fields for more custom data if you like.

And finally if you don't need the data accessible through a UI, you can use the shape.properties to build custom fields also for data.

-Shelby
Reply With Quote
  #4  
Old 03-06-2008, 22:12
norbert_ds
Guest
 
Posts: n/a
Default Cool

You are absolutely fantastic.

Thanks Shelby!!
Reply With Quote
  #5  
Old 02-07-2008, 12:24
jess916
Guest
 
Posts: n/a
Default Exporting shape names to text file

Is there any way to export the shape names to a text file?
Reply With Quote
  #6  
Old 02-07-2008, 12:58
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 ExportNames

Sure you just loop the shapes in the active page and output like this. You could also modify this to do all the shapes for each page if needed, but this should get you started:
Code:
Sub OutputShapeNames()
    Dim s As Shape
    
    Open "C:\Temp\ShapeNames.txt" For Output As #1 'Open your file
    
    For Each s In ActivePage.Shapes
        If s.Name <> "" Then Print #1, s.Name 'Check for name, then output
    Next s
    
    Close #1 'Close the file
End Sub
-Shelby
Reply With Quote
  #7  
Old 03-07-2008, 16:32
jess916
Guest
 
Posts: n/a
Default Thanks!

Thanks Shelby! Sorry one more question for you. I have about 20 different patterns of a total of 1500 shapes. Is it possible to write code to search for each specific pattern and name it accordingly. I noticed that when I conduct a find object, it looks for the specific outlines (ie Width: exactly 0.076, Overprint outline: Off, Color:Black...) would this be what I should use to find each shape and then name it like you did with the previous code?
Reply With Quote
  #8  
Old 03-07-2008, 17:12
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 Search....

You can use what ever makes your shape unique to name the. Whether it is a fill color, outline thickness, size or what ever.

This is all a little easier to do in X4 with CQL, but can be down in older version as well. You just need to identify what makes the shapes unique.

-Shelby
Reply With Quote
  #9  
Old 03-07-2008, 17:34
jess916
Guest
 
Posts: n/a
Default Last thing...

One last thing... I noticed that the output file is in alphabetical order. Is there anyway that shapes could be listed according to location? For example if I have shapes with the following names I would want the text file to read... ABC, BCD, CDE, BCD, CDE, ABC instead of in alphabetical order. Is that even possible?

ABC BCD CDE
BCD CDE ABC

Thank you again for your quick response!
Reply With Quote
  #10  
Old 03-07-2008, 20:12
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 Order...

It is actually in the order of the shapes, as it loops through each one....that aside....as long as there is a consistent pattern it should be able to code for it.

-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
CorelDRAW X3 VBA Code - Shape & Color LIster JudyHNM Code Critique 2 05-04-2007 14:02
Find only shapes with compound path zlatev CorelDRAW/Corel DESIGNER VBA 1 15-02-2005 07:05
Deleting Shapes on the Guides Layer Rick Randall CorelDRAW/Corel DESIGNER VBA 2 28-09-2004 11:07
Transfer shapes from Draw to Paint; Using CorelScript in VB6 DWGraphics Corel Photo-Paint VBA 1 18-08-2004 20:49
Generic code to process all shapes in a document glennwilton CorelDRAW/Corel DESIGNER VBA 0 05-09-2003 03:13


All times are GMT -5. The time now is 12:54.


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