Visio Guy

Visio Discussions => Programming & Code => Topic started by: DC Kelley on April 27, 2010, 11:29:35 PM

Title: Extracting cell values rather then cell formulas
Post by: DC Kelley on April 27, 2010, 11:29:35 PM
When I can not find it in Developing Visio Solutions (MS Press), this forum has become the place I most often turn to... thanks everyone for such a good resource. 

Today's annoying programming issue is how to avoid having to develop my own parser to re-interpret the cell formulas.  I need to extract the actual placement on the page of some shapes, I will be then using the X,Y point data to mathematically place other objects. 

I know how to extract the cell formulas with fragments like

                text = text & vbCrLf & "   " & _
                    shpObj.CellsSRC(curGeomSect, curRow, curCell).LocalName & ": " & _
                    shpObj.CellsSRC(curGeomSect, curRow, curCell).Formula


But I don't see an obvious way to avoid this and just get the current actual value that the formula is producing in that cell.   In other words, consider the Show Shapesheet command where you can toggle between the actual value and the underlying formula with a right-click button -  I need something like that to give me the final value programmatically. 

How do I extract the actual data value from the shape's cell?
Title: Re: Extracting cell values rather then cell formulas
Post by: Visio Guy on April 28, 2010, 12:06:17 AM
DCK,

Here's a few:

shp.Cells("PinX").ResultIU (always inches)
shp.Cells("PinX").Result("mm")
shp.Cells("PinX").Result(Visio.VisUnitCodes.visMillimeters)
Title: Re: Extracting cell values rather then cell formulas
Post by: DC Kelley on April 28, 2010, 02:52:51 AM
Quote from: Visio Guy on April 28, 2010, 12:06:17 AM
shp.Cells("PinX").ResultIU (always inches)
shp.Cells("PinX").Result("mm")
shp.Cells("PinX").Result(Visio.VisUnitCodes.visMillimeters)

Great, I had lost track of the ResultIU method.  That works well.  

I'm building up a routine to grab the points in my ploygons now.  I had to step back and convert any arc types back to line types as a pre-step, but otherwise it seem direct.  

Is there any easy way to translate it to the page coor system, or must I add the offset of the shape transform points myself to get the page values?  Update, is the answer to this as simple as

xxx.Result(Visio.VisUnitCodes.visPageUnits)
Update #2, no that does not work, it simply used the inches I have set for the page, no translaton occurs.
Title: Re: Extracting cell values rather then cell formulas
Post by: Jumpy on April 28, 2010, 09:55:58 AM
In the ShapeSheet there are functions (Loc, LoctoPar,..) which translate coords in shapes to the coordinate system of the page and vice versa.
But I don't know if they have an equivalent in VBA. If not you could either add User.cells to your shapes and use the functions there (akward) or calculate them yourself based on PinX/Y, LocPinX/Y and the Rows of the ShapeTransform section, like you suggested yourself.

I use the last method myself, because I don't know about a VBA method that does the trick, but if one of the other members knows a better way, I would like to learn that, too.
Title: Re: Extracting cell values rather then cell formulas
Post by: Visio Guy on April 28, 2010, 10:47:50 AM
shp.XYToPage will help. Usage is:

     shp.XYToPage(x, y, xprime, yprime)
Title: Re: Extracting cell values rather then cell formulas
Post by: Visio Guy on April 28, 2010, 10:50:40 AM
But if you are getting the Paths property, the coordinates are that of the parent object, so you might already have page-coordinates.
Title: Re: Extracting cell values rather then cell formulas
Post by: DC Kelley on April 29, 2010, 12:24:46 AM
I just don't seem to understand this, something is missing, please say it again for me. 

I see XYToPage method, and that is can be called for a shape on a page or master object, but I don't get what xprime and yprime are to be set to.  It says: y-coordinate corresponding to y in the Page or Master object's coordinate system.   But if I had that, I would not need such a function.  Oh! Never mind, I am not thinking like a VB person, this is the RETURN value set and I presume I need to give it the dummy variable to fill out.  Sorry, too much C on my mind. 

So then the question becomes how do  I use this with the individual (and variable number of) points of my geometry shape?  I can not go from

X = shpObj.CellsSRC(curGeomSect, curRow, 0).Result(visio.VisUnitCodes.visPageUnits)
Y = shpObj.CellsSRC(curGeomSect, curRow, 1).Result(visio.VisUnitCodes.visPageUnits)

to be

shpObj. XYToPage(x, y, xprime, yprime)

And the method XYToPage is not exposed as part of the CellsSRC -  its not clear to me how to call it on the geometry cells.  The text refer to "a point" as if that is clear, but i just do not get how this works with a shape with multiple points.
Title: Re: Extracting cell values rather then cell formulas
Post by: DC Kelley on April 30, 2010, 05:18:18 PM
bump
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 62 (show)
Files included: 25 - 925KB. (show)
Memory used: 773KB.
Tokens: post-login.
Cache hits: 7: 0.00089s for 22,301 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]