Table export from .net AutoCAD command, exports random characters

Table export from .net AutoCAD command, exports random characters

krishnakumar.arunachalam
Explorer Explorer
261 Views
2 Replies
Message 1 of 3

Table export from .net AutoCAD command, exports random characters

krishnakumar.arunachalam
Explorer
Explorer

Hi All, I have a .NET plugin, which is executed if user types the command. This .NET command exports the table rows and columns and put in a .csv, after that i convert into excel and upload in some external system. 

 

Below .NET code exports for me the table rows and column, but it put some random characters. As you see below code, i had to hardcode so many things and my code is getting messier, as random characters keep coming.  Can you please tell me how to ensure i can avoid those ? I understand newline characters users had put and i had no choice to replace newline, but for others i am surprised why the API's give this

 

Autodesk.AutoCAD.DatabaseServices.Table tb = (Autodesk.AutoCAD.DatabaseServices.Table)tr.GetObject(per.ObjectId, OpenMode.ForRead);

 

if (tb != null)
{
for (int i = 0; i < tb.Rows.Count; i++)
{
var s = "";
var z = "";
for (int j = 0; j < tb.Columns.Count; j++)
{
// Get the contents of our cell
var c = tb.Cells[i, j];
string pattern = @"{\\W\d.\d\d;";
string newstring = Regex.Replace(c.GetTextString(FormatOption.ForEditing), pattern, "");
string pattern1 = @"{\\W\d.\d;";
string newstring1 = Regex.Replace(newstring, pattern1, "");
string removalOfNewLine = Regex.Replace(newstring1, @"[\r\n]+", "");
z = removalOfNewLine.Replace("\\A1", "").Replace("#{\\H1x;", "#").Replace("}", "").Replace(@"{\H0.91667x;", "").Replace(@"{\H1x;\W0.7;", "").Replace(@"\H1x;", "").Replace(";", "");
var y = z + ";";
s = s + y;
}
sb.Append(s);
sb.AppendLine();
}
}

0 Likes
262 Views
2 Replies
Replies (2)
Message 2 of 3

ActivistInvestor
Mentor
Mentor

Try reposting or editing your original post, and use the insert code button on the toolbar to insert the code.

0 Likes
Message 3 of 3

daniel_cadext
Advisor
Advisor

maybe use FormatOption.ForEditing | FormatOption.IgnoreMtextFormat, or just FormatOption.IgnoreMtextFormat

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes