![]() |
#1
|
||||
|
||||
![]()
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 -Shelby |
#2
|
|||
|
|||
![]()
Thanks Shelby!!
Is there a way to add an object name via Corel's user interface rather than via a script? Regards Norbert |
#3
|
||||
|
||||
![]()
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 |
#4
|
|||
|
|||
![]()
You are absolutely fantastic.
Thanks Shelby!! |
#5
|
|||
|
|||
![]()
Is there any way to export the shape names to a text file?
|
#6
|
||||
|
||||
![]()
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 |
#7
|
|||
|
|||
![]()
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?
|
#8
|
||||
|
||||
![]()
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 |
#9
|
|||
|
|||
![]()
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! |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |