Extracting cell values rather then cell formulas

Started by DC Kelley, April 27, 2010, 11:29:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DC Kelley

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?

Visio Guy

DCK,

Here's a few:

shp.Cells("PinX").ResultIU (always inches)
shp.Cells("PinX").Result("mm")
shp.Cells("PinX").Result(Visio.VisUnitCodes.visMillimeters)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

DC Kelley

#2
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.

Jumpy

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.

Visio Guy

shp.XYToPage will help. Usage is:

     shp.XYToPage(x, y, xprime, yprime)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

But if you are getting the Paths property, the coordinates are that of the parent object, so you might already have page-coordinates.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

DC Kelley

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.