M
Matthias Cavigelli
Hi newsgroup
I am programming a Class Library in CSharp, which highly interacts with
Visio 2002.
Each shape in a selection needs to be replaced. So I drop a master for
each item in that selection, then copying the Shape Transformation
Section from the old shape to the new one. I notice that sometimes my
CSharp Library needed 4-8 times longer to do the task, compared to a VBA
solution.
I disabled the undo property of the application, which only cut
execution time by about 10%. I went on and think that I have found the
culprit: get_cellssrc calls. I changed get_cellssrc calls to get_cells
calls, however no major difference in my tests.
I made two tests, each in VBA and CSharp (source below):
== Test 1: Dropping a master for each shape in the selection
5 x 234(amount of shapes in selection)
VBA: 4, 4, 4, 5, 5 [seconds] -> av: 4.4
CSharp 2, 3, 3, 3, 4 [seconds] -> av: 3
The VBA could be optimized a little more, however more or less same
performance and not really significant differences.
== Test 2: Same as Test 1 but also copying Shape Transformation Section
from shape in selection to new shape(-> calling many times getcellsU())
VBA: 6, 9, 6, 6, 9 [seconds] -> av: 7.2
CSharp 26, 30, 40, 38, 35 [seconds] -> av: 33.8!!!!!!
Breakdown of .Net / CSharp solution, CSharp 450% slower!!!!!!
I use the .Net Framework 1.0, the Office PIA and Visio 2002 SR-1. All
tests were made on the same computer and in the same document.
Has anybody made similar experiences? What are the workarounds?
I cannot believe, that there is such a dramatic difference. What is
wrong with my solution?
Thanks for any help
Matthias, a little desperate:-(
====CSharp code=======================
private static void TestControl(bool copySection, Visio.Selection sel){
const int LOOPS = 5;
string msg = "";
DateTime start = new DateTime();
DateTime stop = new DateTime();
TimeSpan delta = new TimeSpan();
Visio.Master mst =
sel.Application.ActiveDocument.Masters[3];
Visio.Page apg = sel.Application.ActivePage;
for(int i = 0; i < LOOPS; i++){
start = DateTime.Now;
TransformSelection(copySection, sel, mst, apg);
stop = DateTime.Now;
delta = stop - start;
msg +=delta.Minutes + ": " + delta.Seconds + "\n";
}
System.Windows.Forms.MessageBox.Show(msg);
}
private static void TransformSelection(bool copySection,
Visio.Selection sel, Visio.Master mst, Visio.Page pg){
Visio.Shape shpNew;
foreach(Visio.Shape shpOld in sel){
shpNew = pg.Drop(mst, 0, 0);
if(copySection){
CopyShapeTransformationSection(shpOld, shpNew);
}
}
}
private static void CopyShapeTransformationSection(Visio.Shape
shpOld, Visio.Shape shpNew){
string[] cellNames = new string[]{"PinX", "PinY", "Width",
"Height", "LocPinX",
"LocPinY", "Angle",
"FlipX", "FlipY", "ResizeMode"};
foreach(string cellName in cellNames){
shpNew.get_CellsU(cellName).Formula =
shpOld.get_CellsU(cellName).Formula;
}
}
===VBA=======================
Public Sub WithCellsU()
Call TestControl(True)
End Sub
Public Sub NoCellsU()
Call TestControl(False)
End Sub
Private Sub TestControl(copySection As Boolean)
Const LOOPS As Integer = 5
Dim msg As String
Dim startDate As Date
Dim stopDate As Date
Dim deltaDate As Date
Dim mst As Visio.Master
Dim pg As Visio.page
Dim sel As Visio.Selection
Dim i As Integer
msg = ""
Set sel = ActiveWindow.Selection
Set mst = ActiveDocument.Masters(3)
Set pg = ActivePage
For i = 0 To LOOPS - 1
startDate = Now
Call TransformSelection(copySection, sel, mst, pg)
stopDate = Now
deltaDate = stopDate - startDate
msg = msg & Minute(deltaDate) & ": " & Second(deltaDate) &
vbNewLine
Next i
MsgBox msg
End Sub
Private Sub TransformSelection(copySection As Boolean, sel As
Visio.Selection, mst As Visio.Master, pg As Visio.page)
Dim shpNew As Visio.Shape
Dim shpVar As Variant
For Each shpVar In sel
Set shpNew = pg.Drop(mst, 0, 0)
If copySection Then
Call CopyShapeTransformations(shpVar, shpNew)
End If
Next shpVar
End Sub
Private Sub CopyShapeTransformations(shpOld As Variant, shpNew As
Visio.Shape)
Dim cellNames(9) As String
Dim cellName As Variant
cellNames(0) = "PinX"
cellNames(1) = "PinY"
cellNames(2) = "Width"
cellNames(3) = "Height"
cellNames(4) = "LocPinX"
cellNames(5) = "LocPinY"
cellNames(6) = "Angle"
cellNames(7) = "FlipX"
cellNames(8) = "FlipY"
cellNames(9) = "ResizeMode"
With shpNew
For Each cellName In cellNames
.CellsU(cellName).Formula = shpOld.CellsU(cellName).Formula
Next cellName
End With
End Sub
I am programming a Class Library in CSharp, which highly interacts with
Visio 2002.
Each shape in a selection needs to be replaced. So I drop a master for
each item in that selection, then copying the Shape Transformation
Section from the old shape to the new one. I notice that sometimes my
CSharp Library needed 4-8 times longer to do the task, compared to a VBA
solution.
I disabled the undo property of the application, which only cut
execution time by about 10%. I went on and think that I have found the
culprit: get_cellssrc calls. I changed get_cellssrc calls to get_cells
calls, however no major difference in my tests.
I made two tests, each in VBA and CSharp (source below):
== Test 1: Dropping a master for each shape in the selection
5 x 234(amount of shapes in selection)
VBA: 4, 4, 4, 5, 5 [seconds] -> av: 4.4
CSharp 2, 3, 3, 3, 4 [seconds] -> av: 3
The VBA could be optimized a little more, however more or less same
performance and not really significant differences.
== Test 2: Same as Test 1 but also copying Shape Transformation Section
from shape in selection to new shape(-> calling many times getcellsU())
VBA: 6, 9, 6, 6, 9 [seconds] -> av: 7.2
CSharp 26, 30, 40, 38, 35 [seconds] -> av: 33.8!!!!!!
Breakdown of .Net / CSharp solution, CSharp 450% slower!!!!!!
I use the .Net Framework 1.0, the Office PIA and Visio 2002 SR-1. All
tests were made on the same computer and in the same document.
Has anybody made similar experiences? What are the workarounds?
I cannot believe, that there is such a dramatic difference. What is
wrong with my solution?
Thanks for any help
Matthias, a little desperate:-(
====CSharp code=======================
private static void TestControl(bool copySection, Visio.Selection sel){
const int LOOPS = 5;
string msg = "";
DateTime start = new DateTime();
DateTime stop = new DateTime();
TimeSpan delta = new TimeSpan();
Visio.Master mst =
sel.Application.ActiveDocument.Masters[3];
Visio.Page apg = sel.Application.ActivePage;
for(int i = 0; i < LOOPS; i++){
start = DateTime.Now;
TransformSelection(copySection, sel, mst, apg);
stop = DateTime.Now;
delta = stop - start;
msg +=delta.Minutes + ": " + delta.Seconds + "\n";
}
System.Windows.Forms.MessageBox.Show(msg);
}
private static void TransformSelection(bool copySection,
Visio.Selection sel, Visio.Master mst, Visio.Page pg){
Visio.Shape shpNew;
foreach(Visio.Shape shpOld in sel){
shpNew = pg.Drop(mst, 0, 0);
if(copySection){
CopyShapeTransformationSection(shpOld, shpNew);
}
}
}
private static void CopyShapeTransformationSection(Visio.Shape
shpOld, Visio.Shape shpNew){
string[] cellNames = new string[]{"PinX", "PinY", "Width",
"Height", "LocPinX",
"LocPinY", "Angle",
"FlipX", "FlipY", "ResizeMode"};
foreach(string cellName in cellNames){
shpNew.get_CellsU(cellName).Formula =
shpOld.get_CellsU(cellName).Formula;
}
}
===VBA=======================
Public Sub WithCellsU()
Call TestControl(True)
End Sub
Public Sub NoCellsU()
Call TestControl(False)
End Sub
Private Sub TestControl(copySection As Boolean)
Const LOOPS As Integer = 5
Dim msg As String
Dim startDate As Date
Dim stopDate As Date
Dim deltaDate As Date
Dim mst As Visio.Master
Dim pg As Visio.page
Dim sel As Visio.Selection
Dim i As Integer
msg = ""
Set sel = ActiveWindow.Selection
Set mst = ActiveDocument.Masters(3)
Set pg = ActivePage
For i = 0 To LOOPS - 1
startDate = Now
Call TransformSelection(copySection, sel, mst, pg)
stopDate = Now
deltaDate = stopDate - startDate
msg = msg & Minute(deltaDate) & ": " & Second(deltaDate) &
vbNewLine
Next i
MsgBox msg
End Sub
Private Sub TransformSelection(copySection As Boolean, sel As
Visio.Selection, mst As Visio.Master, pg As Visio.page)
Dim shpNew As Visio.Shape
Dim shpVar As Variant
For Each shpVar In sel
Set shpNew = pg.Drop(mst, 0, 0)
If copySection Then
Call CopyShapeTransformations(shpVar, shpNew)
End If
Next shpVar
End Sub
Private Sub CopyShapeTransformations(shpOld As Variant, shpNew As
Visio.Shape)
Dim cellNames(9) As String
Dim cellName As Variant
cellNames(0) = "PinX"
cellNames(1) = "PinY"
cellNames(2) = "Width"
cellNames(3) = "Height"
cellNames(4) = "LocPinX"
cellNames(5) = "LocPinY"
cellNames(6) = "Angle"
cellNames(7) = "FlipX"
cellNames(8) = "FlipY"
cellNames(9) = "ResizeMode"
With shpNew
For Each cellName In cellNames
.CellsU(cellName).Formula = shpOld.CellsU(cellName).Formula
Next cellName
End With
End Sub