In an effort to stop copy/pasting functions that I reuse in multiple commands I tried compiling two functions in a .NET dll and adding a project assembly reference to that dll and a using clause in a fully-operational command.
The dll:
namespace BL_clsUtils
{
public class clsUtilFunctions
{
public string ParseElement(string pStr, char pDelim, int pPos)
{
char Delim;
string sStr = pStr;
Delim = pDelim;
//pPos is the index of the delimiter.
//if pPos is 3 then we are looking for the third delimiter
//First, check that the position of the desired delimiter
//is within pStr. If SingleElement, the string sStr is shortened
//to the end of the first element to be returned
// "a; kite;" becomes "a"
//Get the final element in a string
if (pPos > ParseCount(pStr, pDelim))
{
string res = pStr; ;
int lastDelim = ParseCount(res, pDelim);
while (ParseCount(res, pDelim) > 0)
{
res = res.Substring(res.IndexOf(",") + 2);
}
return res;
}
if (pPos == 0) { return ""; }
else //Position > 0 -- Parse string at Positionth delimiter.
{
string res = "";
int DelimNum = 0;
for (int i = 0; i <= sStr.Length - 1; i++)
{
if (sStr[i] == Delim)
{
DelimNum++;
}
if (DelimNum == pPos - 1)
{
res = res + sStr[i];
}
if (DelimNum == pPos)
{
if (res.IndexOf(Delim) >= 0) { res = res.Substring(2); }
return res;
}
}
return res;
} //else
}//private string ParseElement(string pStr, char pDelim, int pPos)
public int ParseCount(string s, char c)
{
int count = 0;
for (int i = 0; i <= s.Length - 1; i++)
{
if (s[i] == c)
{
count++;
}
}
return count;
}//private int ParseCount(string s, char c)
}
}
I then tried to instantiate the class in a RhinoCommon command thusly:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
try{
clsUtilFunctions util = new clsUtilFunctions();
util.ParseElement("This is a test; test no 2", ';', 1);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
RS2023_6_frmEditDocData form = new RS2023_6_frmEditDocData();
}
I commented the code pertaining to the dll and checked the parameters of RunCommand() and they match expectations (doc.name is correct and mode is “interactive”.
The last line is code that executes when the try…catch block is not present.
The compiler recognizes the class, clsUtilFunctions, since it allows me to instantiate the class and call ParseElement () without compiler error.
When I put a break point at the first line and last line, neither point is hit, nor does the command do anything. No exceptions, no prompt and no entry into the command.
I tried simply instantiating the class, without calling functionality and the result is the same.
What am I doing wrong?