Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get shape ID for later use 1

Status
Not open for further replies.

vb6novice

Programmer
Sep 23, 2002
288
US
Long Time VBA user - new to VBA in Visio - still haven't figured out how to refer to shapes and their properties (or is that Cells ?)

I have code that draws 4 lines on a page, then selects the 4 lines and joins them. After the join, I want to fill the joined shape with a color.

I recorded a macro to learn how to do this but it has the joined shape's ItemFromId index hard coded (see below).

[COLOR=red yellow]Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Fill Properties")
Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "RGB(255,255,150)"
Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowFill, visFillPattern).FormulaU = "1"
Application.EndUndoScope UndoScopeID1, True[/color]

If there are already shapes on the page when I run the code, the ItemFromId index probably won't be 5. How do I get the true ItemFromID index from the newly joined shape.


Thanks for your help.
 
Why do you want to draw four lines and then join them? The normal way in Visio is to drop a shape from a stencil.

When you drop a shape, you can assign the dropped shape to a variable and se that variable to update the shape.

In your macro, the UndoScope lines can be ignored.

Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "RGB(255,255,150)"

can be shorten to
ActivePage.Shapes(5).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "RGB(255,255,150)"


John... Visio MVP - Visio.MVPs.org
 
Thanks,John

I wanted to draw 4 lines and join them because I am trying to render an architectural perspective/isometric from a listing of coordinates which represent the corner points of a building's walls and windows, and similarly for the roof sections. Every wall and roof section has different coordinates and I want to be able to render the drawing with various perspective angles.

Is there a way to drop a rhombus or parallelogram and then move/set the four corners to the required coordinates?

 
With a non standard shape, you have the best approach, but make sure the shape is closed. Otherwise,it will not be fillable. It is possible to fill an open shape, but you will have to edit the shape's shapesheet and set the NoFill value of the Geometry sections to false. The shape will fill as long as each geometry section encompasses an area.

A shape made up of four lines, usually is made up of four Geometry sections and each Geometry section defines a line. None of the Geometry sections enclose anything more than a line. When you join, the Geometry sections merge and does encompass an area.

John... Visio MVP - Visio.MVPs.org
 
There are also the Microsoft educational shapes:

You might find what you are looking for there.

--
Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio Electrical for Visio Electronics Packages for Visio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top