E
Eunice
Hi, I am Eunice and just a begginer.
I coded some basic by C# and tried to add-on in Visio 2003. My purpose on
the program is that I try to get some shape properties such as text, ID,
from-shape ID and to-shape ID and then write the information to a text format
file. I added-on the file under the tool menu in Visio 2003. During compling
the code in visual studio. Net 2003, I don't have error. But whenever I click
the menu added-on under tool menu in visio 2003, I got the following error.
***************
An unhandled exception of type 'System.NullReferenceException' occurred
Additional information: Object reference not set to an instance of an object.
***********************
Could you help me out to solve this error? I will attach my simple code as
well.
The code has my all trials. So sorry to look mess up.
Thanks a lot. Have a nice day.
Eunice.
************** <VisioExEAddon.cs>*************
using System;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Collections;
using System.Resources;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Visio;
namespace MatchMaker1 {
public class VisioEXEAddon {
public static Microsoft.Office.Interop.Visio.Application visioApplication;
static void Main(string[] args)
{
string message = "";
//int argIndex = 0;
AddonDialog addonDialog = null;
ResourceManager resourceMgr = null;
//ArrayList shapeValueArray = new ArrayList();
//Shape textinfo;
//Microsoft.Office.Interop.Visio.Application visioApplication;
resourceMgr = new
ResourceManager"MatchMaker1.ProjectStrings",
typeof(VisioEXEAddon).Assembly);
// Create a string to display argument details.
//message += resourceMgr.GetString("strArgumentCount") +
args.Length.ToString() + "\r\n\r\n";
//message += resourceMgr.GetString("strArgumentDetails") +
"\r\n";
//for (argIndex = 0; argIndex < args.Length; ++argIndex) {
// message += args[argIndex] + "\r\n";
//}
//shape1.Add(visioApplication.ActivePage.Shapes[1].ID.ToString());
//shape1.Add(visioApplication.ActivePage.Shapes[1].NameU);
//shape1.Add(visioApplication.ActivePage.Shapes[1].Text);
//shape1.Add(visioApplication.ActivePage.Shapes[1].Type.ToString());
//shape1.Add(visioApplication.ActivePage.Shapes[1].Master.ToString());
try
{
//textinfo =
StoreShapeInfo.GetShapeItem(visioApplication.ActivePage.Shapes, 1);
//message += "ShapeID : "+ textinfo.ID + "\r\n\r\n";
//message += "Text : "+ textinfo.Text + "\r\n\r\n";
//message += "NameU : "+ textinfo.NameU + "\r\n\r\n";
//message += "Type : "+ textinfo.Type + "\r\n\r\n";
//message += "Master : "+ textinfo.Master + "\r\n\r\n";
//message += "ShapeID :" + visioApplication.ActivePage.Shapes[1].ID +
"\r\n\r\n";
//message += "NameU :" + visioApplication.ActivePage.Shapes[1].NameU +
"\r\n\r\n";
//message += "Text :" + visioApplication.ActivePage.Shapes[1].Text +
"\r\n\r\n";
//message += "Master :" + visioApplication.ActivePage.Shapes[1].Master +
"\r\n\r\n";
//message += "Type :" + visioApplication.ActivePage.Shapes[1].Type +
"\r\n\r\n";
//for (int s = 0; s< shape1.Count ; s++)
//{
//string type= "v ";
//string blank= " ";
//pub.Text += type + NetronLight.Store.objectIDs + blank +
NetronLight.Store.texts+"\n";
//string vertex = type + NetronLight.Store.objectIDs + blank +
NetronLight.Store.texts;
//message += "Shape Values : " + shape1 + "\r\n\r\n";
//sw.WriteLine(vertex);
//}
System.Array shapeValueArray = Array.CreateInstance( typeof(string), 12);
shapeValueArray.SetValue(visioApplication.ActivePage.Shapes[1].ID.ToString(), 1);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject.ToString(), 2);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisRowIndices.visRowXFormOut.ToString(), 3);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisCellIndices.visXFormWidth.ToString(), 4);
shapeValueArray.SetValue(visioApplication.ActivePage.Shapes[2].ID.ToString(), 5);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject.ToString(), 6);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisRowIndices.visRowXFormOut.ToString(), 7);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisCellIndices.visXFormWidth.ToString(), 8);
shapeValueArray.SetValue(visioApplication.ActivePage.Shapes[3].ID.ToString(), 9);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject.ToString(),
10);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisRowIndices.visRowXFormOut.ToString(), 11);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisCellIndices.visXFormWidth.ToString(), 12);
//Return the formulas of the cells.
//Dim avarFormulaArray() As Variant
//ArrayList formulaArray = new ArrayList();
System.Array formulaArray = Array.CreateInstance( typeof(string), 12);
//System.Array formulaArray;
visioApplication.ActivePage.GetFormulasU(ref shapeValueArray, out
formulaArray);
//Debug.Print "Shape 1 width is "; avarFormulaArray(0)
//Debug.Print "Shape 2 height is "; avarFormulaArray(1)
//Debug.Print "Shape 3 angle is "; avarFormulaArray(2)
for (short index = 0; index < 12; index++)
{
//message += "Shape information :" + formulaArray.GetValue(index)
+ "\r\n\r\n";
message += "Shape information :" + formulaArray.GetValue(index) +
"\r\n\r\n";
}
// Display the argument details in a dialog box.
addonDialog = new AddonDialog();
addonDialog.Args.Text = message;
addonDialog.ShowDialog();
}
catch (Exception err)
{
StoreShapeInfo.DisplayException(visioApplication.AlertResponse,
err.Message);
}
}
}
}
I coded some basic by C# and tried to add-on in Visio 2003. My purpose on
the program is that I try to get some shape properties such as text, ID,
from-shape ID and to-shape ID and then write the information to a text format
file. I added-on the file under the tool menu in Visio 2003. During compling
the code in visual studio. Net 2003, I don't have error. But whenever I click
the menu added-on under tool menu in visio 2003, I got the following error.
***************
An unhandled exception of type 'System.NullReferenceException' occurred
Additional information: Object reference not set to an instance of an object.
***********************
Could you help me out to solve this error? I will attach my simple code as
well.
The code has my all trials. So sorry to look mess up.
Thanks a lot. Have a nice day.
Eunice.
************** <VisioExEAddon.cs>*************
using System;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Collections;
using System.Resources;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Visio;
namespace MatchMaker1 {
public class VisioEXEAddon {
public static Microsoft.Office.Interop.Visio.Application visioApplication;
static void Main(string[] args)
{
string message = "";
//int argIndex = 0;
AddonDialog addonDialog = null;
ResourceManager resourceMgr = null;
//ArrayList shapeValueArray = new ArrayList();
//Shape textinfo;
//Microsoft.Office.Interop.Visio.Application visioApplication;
resourceMgr = new
ResourceManager"MatchMaker1.ProjectStrings",
typeof(VisioEXEAddon).Assembly);
// Create a string to display argument details.
//message += resourceMgr.GetString("strArgumentCount") +
args.Length.ToString() + "\r\n\r\n";
//message += resourceMgr.GetString("strArgumentDetails") +
"\r\n";
//for (argIndex = 0; argIndex < args.Length; ++argIndex) {
// message += args[argIndex] + "\r\n";
//}
//shape1.Add(visioApplication.ActivePage.Shapes[1].ID.ToString());
//shape1.Add(visioApplication.ActivePage.Shapes[1].NameU);
//shape1.Add(visioApplication.ActivePage.Shapes[1].Text);
//shape1.Add(visioApplication.ActivePage.Shapes[1].Type.ToString());
//shape1.Add(visioApplication.ActivePage.Shapes[1].Master.ToString());
try
{
//textinfo =
StoreShapeInfo.GetShapeItem(visioApplication.ActivePage.Shapes, 1);
//message += "ShapeID : "+ textinfo.ID + "\r\n\r\n";
//message += "Text : "+ textinfo.Text + "\r\n\r\n";
//message += "NameU : "+ textinfo.NameU + "\r\n\r\n";
//message += "Type : "+ textinfo.Type + "\r\n\r\n";
//message += "Master : "+ textinfo.Master + "\r\n\r\n";
//message += "ShapeID :" + visioApplication.ActivePage.Shapes[1].ID +
"\r\n\r\n";
//message += "NameU :" + visioApplication.ActivePage.Shapes[1].NameU +
"\r\n\r\n";
//message += "Text :" + visioApplication.ActivePage.Shapes[1].Text +
"\r\n\r\n";
//message += "Master :" + visioApplication.ActivePage.Shapes[1].Master +
"\r\n\r\n";
//message += "Type :" + visioApplication.ActivePage.Shapes[1].Type +
"\r\n\r\n";
//for (int s = 0; s< shape1.Count ; s++)
//{
//string type= "v ";
//string blank= " ";
//pub.Text += type + NetronLight.Store.objectIDs
NetronLight.Store.texts
//string vertex = type + NetronLight.Store.objectIDs
NetronLight.Store.texts
//message += "Shape Values : " + shape1
//sw.WriteLine(vertex);
//}
System.Array shapeValueArray = Array.CreateInstance( typeof(string), 12);
shapeValueArray.SetValue(visioApplication.ActivePage.Shapes[1].ID.ToString(), 1);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject.ToString(), 2);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisRowIndices.visRowXFormOut.ToString(), 3);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisCellIndices.visXFormWidth.ToString(), 4);
shapeValueArray.SetValue(visioApplication.ActivePage.Shapes[2].ID.ToString(), 5);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject.ToString(), 6);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisRowIndices.visRowXFormOut.ToString(), 7);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisCellIndices.visXFormWidth.ToString(), 8);
shapeValueArray.SetValue(visioApplication.ActivePage.Shapes[3].ID.ToString(), 9);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject.ToString(),
10);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisRowIndices.visRowXFormOut.ToString(), 11);
shapeValueArray.SetValue(Microsoft.Office.Interop.Visio.VisCellIndices.visXFormWidth.ToString(), 12);
//Return the formulas of the cells.
//Dim avarFormulaArray() As Variant
//ArrayList formulaArray = new ArrayList();
System.Array formulaArray = Array.CreateInstance( typeof(string), 12);
//System.Array formulaArray;
visioApplication.ActivePage.GetFormulasU(ref shapeValueArray, out
formulaArray);
//Debug.Print "Shape 1 width is "; avarFormulaArray(0)
//Debug.Print "Shape 2 height is "; avarFormulaArray(1)
//Debug.Print "Shape 3 angle is "; avarFormulaArray(2)
for (short index = 0; index < 12; index++)
{
//message += "Shape information :" + formulaArray.GetValue(index)
+ "\r\n\r\n";
message += "Shape information :" + formulaArray.GetValue(index) +
"\r\n\r\n";
}
// Display the argument details in a dialog box.
addonDialog = new AddonDialog();
addonDialog.Args.Text = message;
addonDialog.ShowDialog();
}
catch (Exception err)
{
StoreShapeInfo.DisplayException(visioApplication.AlertResponse,
err.Message);
}
}
}
}