Author Topic: Macro rel to abs and reverese formulas in Geometry Section  (Read 5234 times)

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Macro rel to abs and reverese formulas in Geometry Section
« on: August 24, 2013, 06:42:28 AM »
In Visio 2013 Visio makes sometimes relative formula in geometry section.
If you feel them not convinient, you can convert the formula to absolute formulas by saveing the drawing as Visio 2007 or old version and open again the saved drawing.
If you feel still not convient, you can directly convert the formulas with simple macro.

This is a macro to convert relative formulas to absolute formula.

Code
Option Explicit

Sub Rel2AbsRows()

    Dim shp As Visio.Shape
    Dim Irow As Long
    Dim Nrow As Long
    Dim Igeo As Long
    Dim Ngeo As Long
   
    Set shp = ActiveWindow.Selection(1)
   
    Ngeo = shp.GeometryCount - 1
   
    If Ngeo < 0 Then Exit Sub
   
    For Igeo = 0 To Ngeo
   
        Nrow = shp.RowCount(visSectionFirstComponent + Igeo) - 1
       
        For Irow = 1 To Nrow
            If shp.RowType(visSectionFirstComponent + Igeo, 1) = visTagRelMoveTo Then
                shp.RowType(visSectionFirstComponent + Igeo, 1) = visTagMoveTo
            ElseIf shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagRelLineTo Then
                shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagLineTo
            ElseIf shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagRelEllipticalArcTo Then
                shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagEllipticalArcTo
            End If
        Next Irow
       
    Next Igeo

End Sub

This is a macro to convert absplute formulas to relative.

Code
Sub AbsRows2Rel()

    Dim shp As Visio.Shape
    Dim Irow As Long
    Dim Nrow As Long
    Dim Igeo As Long
    Dim Ngeo As Long
   
    Set shp = ActiveWindow.Selection(1)
   
    Ngeo = shp.GeometryCount - 1
   
    If Ngeo < 0 Then Exit Sub
   
    For Igeo = 0 To Ngeo
   
        Nrow = shp.RowCount(visSectionFirstComponent + Igeo) - 1
       
        For Irow = 1 To Nrow
            If shp.RowType(visSectionFirstComponent + Igeo, 1) = visTagMoveTo Then
                shp.RowType(visSectionFirstComponent + Igeo, 1) = visTagRelMoveTo
            ElseIf shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagLineTo Then
                shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagRelLineTo
            ElseIf shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagEllipticalArcTo Then
                shp.RowType(visSectionFirstComponent + Igeo, Irow) = visTagRelEllipticalArcTo
            End If
        Next Irow
       
    Next Igeo

End Sub

However I think the best way is Visio has the menu to convert rel to abs or reverse.  :)
« Last Edit: January 14, 2017, 02:37:50 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/