Get shape with ID and set color not working

0

0rbital

I'm having an issue I need help on.

I have an indicator on a page called Indicator.91 with the ID being 91. I
want to set a shape to this indicator and change the color to green or red
depending on a value. Now the examples I've seen on how to get a shape by ID
number look like this:

// Get a shape by ID = 91:
Visio.Shape shp2 = (Visio.Page)viscontrol.Window.Page.Shapes.ItemFromID(91);

That gives me a compile error stating ItemFromID is not supported by the
language (Visio 2007 and .Net 2005 C#). So I have done it like this:

vsoPage = vsoApp.ActivePage;
shpZ8_604 = vsoPage.Shapes.get_ItemFromID(91);
shpZ8_604.get_Cells("FillForegnd").Formula = "RGB(0,255,0)";

That compiles fine and stepping through the code I see shpZ8_604 does in
fact get set to Indicator.91 but the fillForegnd (or FillBkgnd) line executes
fine but the color does not change. There's no protections set at this
point and I can right click and change the fill color of the indicator fine.

Any ideas?
 
J

JuneTheSecond

Hi 0rbital,

It may be because the master on the drawing is not changed.
Would you please to chnage color of the master, too.
 
0

0rbital

Could it be layer related? The valves are on one layer while the indicators
are on another.
 
0

0rbital

That doesn't seem to be the issue either. I'm really perplexed and this is
the last hurdle I need to resolve to finish the application. Indicator.91
is the only indicator on the page and it will not change color through code.
I don't get it, but if I add another indicator I can't get it to change color
either. Valves are no problem.

This code works just fine and will change the valve to red:
shp = vsoPage.Shapes.get_ItemFromID(idshpV8_604);
shp.get_Cells("FillForegnd").Formula = Red;

This code should work exactly like the above but results in no color change:
shpZ8_604 = vsoPage.Shapes.get_ItemFromID(idshpZ8_604);
shpZ8_604.get_Cells("FillForegnd").Formula = Red;
 
0

0rbital

This is quite irritating now as I can change the color of any shape on the
drawing except the indicators. I'm starting to get closer to what's
happening I just don't know why. This amount of frustration is definitely
leading me to tell my company to never do automated P&ID drawings in Visio
again.

On the actual drawing itself if I right click on any indicator and select
format fill and pick a color it changes color and the foreground cell
updates. If I click on that the fill foreground cell and change the formula
in in the formula bar it will not change. Only selecting the format fill
from the right click context menu will change the color. I'm assuming it's
some feature of the smartshapes in Visio 2007 that's preventing this but I
can't use .FormulaForce either same result.
 
0

0rbital

THANK YOU! That was the issue the indicator was grouped with the text.
Problem solved.
 
0

0rbital

Anyone have some C# code to set all subshapes fillforeground color in a
grouped shape? While I can ungroup and get them to work it has a very
strange side effect of sending part of the grouped shape down to the lower
left corner of the drawing and I cannot move it from the that spot. This is
basically the circle with the line through the middle indicator from the
instruments shapes with a small square box connected it and then grouped
together. The small square box stays put and I can change that color but the
circle jumps to the lower left and will not let me move it anywhere with no
protections on. I can rotate or change the text in it but not move it.
 
P

Paul Herber

Anyone have some C# code to set all subshapes fillforeground color in a
grouped shape? While I can ungroup

You should never need to ungroup shapes. Often the subshapes reference
the coordinates of the containing shape, ungrouping than, as you
found, will make the shape go to pieces!

not C# but it's an algorithm you can use
shp: shape
shapeCounter: integer
for shapeCounter = 1 to shp.shapes.count
shp.shapes[shapeCounter]. your code to set the subshape property
end
 
0

0rbital

Thanks that did the trick. That was my last hurdle to get over, now I can
get to the meat of the code.

Paul Herber said:
Anyone have some C# code to set all subshapes fillforeground color in a
grouped shape? While I can ungroup

You should never need to ungroup shapes. Often the subshapes reference
the coordinates of the containing shape, ungrouping than, as you
found, will make the shape go to pieces!

not C# but it's an algorithm you can use
shp: shape
shapeCounter: integer
for shapeCounter = 1 to shp.shapes.count
shp.shapes[shapeCounter]. your code to set the subshape property
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top