Visio Guy

Visio Discussions => Programming & Code => Topic started by: Lazyman on October 04, 2020, 07:35:48 AM

Title: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 04, 2020, 07:35:48 AM
Hi visio guys,
I have a set of shapes on a page and iwant to access to only rectangle shapes. Is there a shape property that I can use to discriminate between rectangles, lines, etc.
Thanks.
Title: Re: Make a distinction between shapes type on a visio page
Post by: Paul Herber on October 04, 2020, 08:15:41 AM
If your shapes were created from a stencil shape called "Rectangle" then the shape Master name will be "Rectangle"  and your code can check for this. However, if you used the drawing tools on the toolbar/ribbon then you are out of luck. All those shapes are just named "Shape.xxx" where xxx is a number.
Title: Re: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 04, 2020, 11:24:52 AM
Thank you Paul for your feedback. My shapes have been created from the toolbar. So, I will redraw via the basic stencil and try to catch the type from there. I will let you know.
Thks.
Title: Re: Make a distinction between shapes type on a visio page
Post by: Nikolay on October 04, 2020, 12:47:39 PM
You can also mark the shape yourself by adding some custom property., like "type"
Yoh can add custom proertis using shape data window or shape sheet.
Title: Re: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 08, 2020, 02:30:20 PM
Thank you foryour feedbacks. I have redrawn my shapes from the stencils instead of the toolbar ribbon and now i can discriminate the shapes according to their types. Now I want to rename the shapes. Therefore, I have added a row (at index 4) in the "User defined cells" section of the shape sheet.

How can i refer to the value of this property? For other properties, I do: shape.Cells("name_of_the_property").FormulaU. Is it ok for user defined cells?
Title: Re: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 09, 2020, 04:43:47 PM
Hi, to reach the new property (called name) in the user defined section, I tried the instruction in python
shape.Cells("User. Name").Value
It does not work.
Any hint please? Thanks.
Title: Re: Make a distinction between shapes type on a visio page
Post by: Nikolay on October 09, 2020, 05:00:19 PM
"Value" is not valid property. There is "Result" (or "Formula"/"FormulaU", depending on what you are after). You could try:

Cells("User.Name").Result("")

Without auto-complete and parameter information every single step becomes a *** adventure (c) Deadwood ;D That's one of the reasons why people still use VB to work with Visio
Or you have managed to make the python auto-suggest and show parameter info after you type '.' or '(' ?
Title: Re: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 09, 2020, 08:37:29 PM
Hi Nikolai, I have put
shape.Cells("User. Name").Result("" ) then Formula then Formula and I always get an error message.
Currently, the value of the user defined property is "MyShape"
I can get the value of quite all the properties in the shapesheet except those in the user section.
Title: Re: Make a distinction between shapes type on a visio page
Post by: Surrogate on October 10, 2020, 05:17:34 AM
you want get or set value ?
Result (https://docs.microsoft.com/en-us/office/vba/api/visio.cell.result) used for get value becuase it is read-only property
Title: Re: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 10, 2020, 07:21:53 AM
I want to get the value of the property. I tried result, result("")
Title: Re: Make a distinction between shapes type on a visio page
Post by: Yacine on October 10, 2020, 08:24:06 AM
try
shape.Cells("User. Name").ResultStr("")
Title: Re: Make a distinction between shapes type on a visio page
Post by: Lazyman on October 10, 2020, 09:43:50 AM
Cool, it is OK now. Thank you guys.