Visio Guy

Visio Discussions => General Visio => Topic started by: alexburn on September 14, 2010, 12:28:27 PM

Title: Find/Select all shapes by color
Post by: alexburn on September 14, 2010, 12:28:27 PM
Is there any way that I can select all shapes on a page of a particular line color? The 'Select by type' function is almost what I need, although not specific enough to find particular shapes rather than all shapes.

I need to do this so that I can select all *red* lines imported from an existing CAD drawing so that I can then assign to a specific layer.

Thanks
Title: Re: Find/Select all shapes by color
Post by: Yacine on September 14, 2010, 01:23:10 PM
There's no such function to my knowledge, but I would suggest, that you use an intermediate file. eg: import the CAD drawing in an empty drawing, select all shapes, assign the desired layer, cut and paste in the right drawing.
Title: Re: Find/Select all shapes by color
Post by: alexburn on September 14, 2010, 01:55:21 PM
I know that there is no in-built function, but I am pretty certain that some VB code could easily achieve a solution.

The main problem I have is with CAD, as I only have a some light CAD software on my machine, and it doesnt have the power nor functionality to modify the DWG I have. The DWG I am using is a massive site plan so that are some 50,000+ objects in total. So far I have the CAD drawing imported ok into Visio, but to go through the entire drawing to find all objects of each particular colour is taking forever!
Title: Re: Find/Select all shapes by color
Post by: Yacine on September 14, 2010, 05:27:03 PM
OK, but that is not an answer to my suggestion. ;-D
Title: Re: Find/Select all shapes by color
Post by: alexburn on September 15, 2010, 06:44:59 PM
Your suggestion does not solve my problem. I have a CAD drawing with 1000's of items on 20+ CAD layers in 20+ different colours. I cannot import and convert the CAD drawing, all I can do is copy from CAD and past in Visio (without layer info). I need to select all items in the document that are *red* so that I can then assign them to *red layer* then select all items that are *blue* so that I can assign them to *blue layer*.
Title: Re: Find/Select all shapes by color
Post by: Nikolay on September 16, 2010, 02:45:07 AM
You could try the following VBA code (selects all shapes with fill color set to "RGB(255, 0, 0)", i.e. red).
If what you are interested in is actually not fill color, but line (border) color then you'll need to use "LineColor" instead of "FillForegnd".
You might also need to tweak the color value so that it matches your "red" (you could use ShapeSheet to get the RGB code for your "red")
Also, your shapes might be groped; in this case you might need to iterate into groups (in case you need sub-shapes), the code below iterates over top-level shapes only.
BTW, I think you can assign shape a layer using code as well.


Dim s As Shape
For Each s In ActivePage.Shapes
 If s.Cells("FillForegnd").ResultStr(0) = "RGB(255, 0, 0)" Then
   ActiveWindow.Select s, visSelect
 End If
Next
Title: Re: Find/Select all shapes by color
Post by: alexburn on September 17, 2010, 08:41:31 AM
Awesome, thanks very much- this is exactly what I was looking for!

Just a quick follow on question...

What code would I need to look at the currently selected shape's LineColor and find all shapes with matching LineColors?

Thanks again
Title: Re: Find/Select all shapes by color
Post by: Nikolay on September 17, 2010, 01:06:13 PM
I think you could use something like this:


resultColor = ""
If ActiveWindow.Selection.Count = 1 Then
   Set s = ActiveWindow.Selection(1)
   resultColor = s.Cells("LineColor").ResultStr(0)
End If
Title: Re: Find/Select all shapes by color
Post by: alexburn on September 17, 2010, 01:14:35 PM
Works perfectly! Thanks again for your help.