BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Updating shape props programmatically

Started by Helkost, April 22, 2024, 11:26:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I am developing an application in c# which converts an excel file with an elaborate dataset into a visio document.

Just for context, the excel file lists a certain amount of PCs, Switches, Extenders, complete with their network, graphics and datapath ports, and all their cable data (therefore showing for each used pc port its destination).

So, I managed to make the whole part about generating the visio document (also thanks to John's amazing blog and this forum) but I am being stumped with the update function.

The update is as follows: the user, after generating a visio document, might change some information - i.e. the number of datapaths on a PC, maybe also remove some connections, etcetera, and will then need to update the generated Visio accordingly.

Given that the previously generated document might be quite complex and the user may already have manipulated some connections by hand to make them look nicer and easier to follow, we only want to update the shape that is being changed while leaving the rest untouched.

Since one of the possible changes that might happen is the deletion of a shape, I access the Visio.Page shapes in a for loop counting backwards:

       Visio.Page visioPage = CurrApp.ActivePage;
            for (int i = visioPage.Shapes.Count; i > 0; --i)
                Visio.Shape sh = visioPage.Shapes[i];


after a few checks, I want to update the actual shape "sh":

                //data is a dictionary containing current excel dataset.
                if (data.ContainsKey(sh.NameU))
                    _ = data.TryGetValue(sh.NameU, out var excelShape);

                    excelShape.UpdateShapeData(ref sh);

                    data.RemoveShape(sh.NameU); //shape has been processed

UpdateShapeData is a function which accesses Visio.Shape cells directly and updates their FormulaU, and eventually, remaining shapes in excel dataset will be added to current page.
None of this is giving me any error, but at the end of the whole thing, the document is not updated - no new shapes, shapes no longer existing not removed, etcetera. the only thing I can think of is that I'm working on copies of the actual shapes on the document.

FYI, part of the routines that I use (for example to drop new shapes) are the exact same routines I use to generate the visio document, and in the "generate" case they work perfectly.

Any clues on what I might be doing wrong ?


ok, well, I'll leave it here because I am an idiot and I deserve the scorn: I forgot to add the shutdown procedure.   :-[

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 158 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1049KB.
Tokens: post-login.
Cache hits: 14: 0.00167s for 26,766 bytes (show)
Cache misses: 3: (show)
Queries used: 15.

[Show Queries]