jeremypalmer
Technical User
I am developing a simple enhancement to Visio to help me draw longitudinally scaled drawings (i.e. scaled in one dimension only, and with changes of scale at various points). I want to use a shape (called a "Line of Way") with a rectangular geometry section to define the scale and starting distance of each section of the drawing. When I drop shapes onto the page, I want some VBA code to figure out what Line of Way the shape belongs to and hence determine its longitudinal distance from the start of the plan. I want to keep the geometry section of the Line of Way hidden so as not to clutter the drawing.
I have written the ShapeAdded method below. If I add a new shape (shpNew) to the document and it lies within a Line of Way (shpX) rectangle, the code gives the new shape a formula to work out its distance from the reference point (datum). I use properties with specific names to help the program work out whether the shape needs a distance (Prop.Km) and whether a containing shape is a Line of Way (Prop.Km0 and Prop.Scale).
Note how I use the visSpatialIncludeHidden flag, which the documentation says should take hidden geometry sections into account. However, the code works if my Line of Way geometry section is filled (Geometry1.NoFill = FALSE) and visible (Geometry1.NoShow = FALSE), but not otherwise.
Am I missing something? Is this a bug? If so, is there a fix? I suppose I could work around it with layers, but I'd rather avoid them because I use layers for something else already.
I have written the ShapeAdded method below. If I add a new shape (shpNew) to the document and it lies within a Line of Way (shpX) rectangle, the code gives the new shape a formula to work out its distance from the reference point (datum). I use properties with specific names to help the program work out whether the shape needs a distance (Prop.Km) and whether a containing shape is a Line of Way (Prop.Km0 and Prop.Scale).
Code:
Private Sub Document_ShapeAdded(ByVal shpNew As IVShape)
Dim shpX As Shape
Dim sLoW As String
If shpNew.CellExists("Prop.Km", 0) Then
For Each shpX In shpNew.SpatialNeighbors _
visSpatialContainedIn, _
0, _
[b]visSpatialIncludeHidden[/b])
If shpX.CellExists("Prop.Km0", 0) Then
sLoW = shpX.Name
shpNew.Cells("Prop.Km").Formula = sLoW & _
"!Prop.Km0 + " & _
sLoW & "!Prop.Scale*(PinX-" & sLoW & _
"!PinX)"
End If
Next shpX
End If
End Sub
Am I missing something? Is this a bug? If so, is there a fix? I suppose I could work around it with layers, but I'd rather avoid them because I use layers for something else already.