TheSwamp
Code Red => .NET => Topic started by: slappy on August 25, 2010, 03:43:37 PM
-
Any thoughts?
Doing a symble check of:
String.Empty
on the contents doesn't seem to work.
Here is what I've tried
Dim txt As DBText = TryCast(tr.GetObject(id, OpenMode.ForRead), DBText)
If txt IsNot Nothing Then
If txt.TextString.Trim() = String.Empty Then
txt.UpgradeOpen()
txt.[Erase]()
End If
Continue For
End If
Dim mTxt As MText = TryCast(tr.GetObject(id, OpenMode.ForRead), MText)
If mTxt IsNot Nothing Then
Dim result As String = mTxt.Contents
If result.Trim = String.Empty Then
mTxt.UpgradeOpen()
mTxt.[Erase]()
End If
End If
Thanks
Chris
-
if (string.IsNullOrEmpty(text.TextString.Trim())) is this available in vb
-
Is there ever an instance or will AutoCad allow you to have an empty string
-
if (string.IsNullOrEmpty(text.TextString.Trim())) is this available in vb
It is! I'll see if that works.
-
Is there ever an instance or will AutoCad allow you to have an empty string
You would think... :lol:
However, there is the option to purge it and it tells me there is one and that it is removed during a manual "-purge". Draw your own conclusions. :evil:
-
Is there ever an instance or will AutoCad allow you to have an empty string
If you have one of those "power" users that erase text by replacing the contents with a single space, you can get these.
-
[offTopic]
I'll have to stop looking at VB.net code ;
a language that has the same operator for Assignment and Logical Comparison gives me a headache.
[/backToIt]
-
I just did the empty space thing and it was flagged to be erased
-
Is there ever an instance or will AutoCad allow you to have an empty string
If you have one of those "power" users that erase text by replacing the contents with a single space, you can get these.
Why, can't you screw up automagically all by yourself?
let db = acApp.DocumentManager.MdiActiveDocument.Database
use tr = db.TransactionManager.StartTransaction()
let btr = db.CurrentSpaceId.GetObject OpenMode.ForWrite :?> BlockTableRecord
// Empty text
let tx = new DBText()
btr.AppendEntity tx |> ignore
tr.AddNewlyCreatedDBObject(tx, true)
// Zero length geometry
let pl = new Polyline()
btr.AppendEntity pl |> ignore
tr.AddNewlyCreatedDBObject(pl, true)
tr.Commit()
-
Hi,
With mtexts, you have to consider formated strings: "{\fArial|b0|i0|c0|p34; }" is an empty mtext content.
The way I deal with this here (http://www.theswamp.org/index.php?topic=33516.0).
// ...
DBText txt = tr.GetObject(id, OpenMode.ForRead) as DBText;
if (txt != null)
{
if (txt.TextString.Trim() == string.Empty)
{
txt.UpgradeOpen();
txt.Erase();
}
continue;
}
MText mTxt = tr.GetObject(id, OpenMode.ForRead) as MText;
if (mTxt != null && UnFormatMtext(mTxt.Contents).Trim() == string.Empty)
{
mTxt.UpgradeOpen();
mTxt.Erase();
}
//...
private string UnFormatMtext(string str)
{
StringBuilder sb = new StringBuilder(str);
string[] patterns = new string[14] {
"\\A", "\\T", "\\C", "\\Q", "\\W", "\\H", "\\F",
"\\a", "\\t", "\\c", "\\q", "\\w", "\\h", "\\f"};
while (sb.ToString().Contains(MText.BlockBegin))
{
int begin = sb.ToString().IndexOf(MText.BlockBegin);
int end = sb.ToString().IndexOf(MText.BlockEnd, begin);
StringBuilder sub =
new StringBuilder(sb.ToString().Substring(begin + 1, end - begin - 1));
foreach (string pat in patterns)
{
while (sub.ToString().Contains(pat))
{
int n = sub.ToString().IndexOf(pat);
sub.Remove(n, sub.ToString().IndexOf(';', n) - n + 1);
}
}
sb.Remove(begin, end - begin + 1);
sb.Insert(begin, sub.ToString());
}
int i = 0;
while ((i = sb.ToString().IndexOf("\\S", i)) != -1)
{
int j = sb.ToString().IndexOf(';', i);
if (j != -1)
{
int k = sb.ToString().IndexOf('/', i);
if (k != -1 && k < j)
{
sb.Remove(j, 1); ;
sb.Remove(i, 2);
continue;
}
k = sb.ToString().IndexOf('#', i);
if (k != -1 && k < j)
{
sb.Remove(j, 1);
sb.Remove(k, 1);
sb.Insert(k, '/');
sb.Remove(i, 2);
continue;
}
k = sb.ToString().IndexOf('^', i);
if (k != -1 && k < j)
{
sb.Remove(j, 1);
sb.Remove(k, 1);
sb.Insert(k, '/');
sb.Remove(i, 2);
continue;
}
i++;
}
}
patterns = new string[7] { "\\P", "\\p", "\\L", "\\p", "\\O", "\\o", "\\~" };
foreach (string pat in patterns)
{
sb.Replace(pat, string.Empty);
}
return sb.ToString();
}
-
gile,
Have you played with
MtextFragment class
and
ExplodeFragements() method in the MText Class to strip the formatting ??
I recall Tony posted a link(on the newsgroup) to a sample on his site.
-
This erased them
Dim pad As String = ""
If txt.TextString = pad.PadRight(txt.TextString.Count) Then
txt.UpgradeOpen()
txt.Erase()
End If
-
It did not work for Mtext you could use what Kerry what mentioned
Or maybe do a string.split and use "\" as the dilimter and check for <=1
-
Thanks Kerry.
I didn't play with ExplodeFragments() before, I'm glad having learned something new this morning.
Here's a new example, inspired by Tony's sample.
// ...
DBText txt = tr.GetObject(id, OpenMode.ForRead) as DBText;
if (txt != null)
{
if (txt.TextString.Trim() == string.Empty)
{
txt.UpgradeOpen();
txt.Erase();
}
continue;
}
MText mTxt = tr.GetObject(id, OpenMode.ForRead) as MText;
if (mTxt != null && GetStripedMtextContents(mTxt).Trim() == string.Empty)
{
mTxt.UpgradeOpen();
mTxt.Erase();
}
//...
private string m_str;
private string GetStripedMtextContents(MText mt)
{
m_str = string.Empty;
mt.ExplodeFragments(new MTextFragmentCallback(FragmentCallback));
return m_str;
}
private MTextFragmentCallbackStatus FragmentCallback(MTextFragment fragment, object obj)
{
m_str += fragment.Text;
return MTextFragmentCallbackStatus.Continue;
}