Author Topic: Change MText to a single color  (Read 11570 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
Re: Change MText to a single color
« Reply #15 on: November 29, 2006, 12:35:24 PM »
Well after some attempts and by trying to assimilate how to handle string's in C#, I came up with a code that works, it may help someone in a future coding, I think.

Code: [Select]
private void OnClick_RemoveColor(object sender, EventArgs e)
{
    //Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
    string txtstr = textBox1.Text;
    char[] s = txtstr.ToCharArray();
    int cont = 0, flag = 0;
    string txt1 = "", let = "";
    for (int j = 0; j < txtstr.Length; j++)
    {
        try
        {
            let = s[cont].ToString();
            if (let == "\\")
            {
                if (s[(cont + 1)].ToString() == "C" || s[(cont + 1)].ToString() == "c")
                {
                    int i = (cont + 2);
                    while (s[i].ToString() != ";")
                        i = i + 1;
                    // remove true and book colors
                    if (s[i + 1].ToString() == "\\" && s[i + 2].ToString() == "c")
                    {
                        i = i + 2;
                        while (s[i].ToString() != ";")
                            i = i + 1;
                    }
                    txt1 = txt1 + s[i + 1].ToString();
                    cont = i + 2;
                }
                else
                    flag = 1;
            }
            else // color format found
            {
                txt1 = txt1 + let;

                // remove the color blocks
                int found;
                found = txt1.IndexOf("{");
                if (found >= 0)
                    txt1 = txt1.Remove(found, 1);
                found = txt1.IndexOf("}");
                if (found >= 0)
                    txt1 = txt1.Remove(found, 1);

                cont = 1 + cont;
            }
            // no color format found
            if (flag == 1)
            {
                txt1 = txt1 + let;
                cont = 1 + cont;
                flag = 0;
            }
        }
        catch
        {
            //ed.WriteMessage("Error");
        }
    }
    textBox1.Text = txt1; // change the contents
}

OK I have here three different code flavours to do a same task, using C++, ObjectARX, AutoLISP, VLISP & C#

With the exception of Glenn, I see a lot of views, but zero participation at all, I would like to know why, so in my future topics, I can post something of interest.

EndOfTopic

« Last Edit: November 29, 2006, 12:39:25 PM by LE »

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Change MText to a single color
« Reply #16 on: November 29, 2006, 12:42:41 PM »
I look to see if I can understand more advance languages, and to see what I can learn.  I appreciate all the code you post, as I learn something each time, especially if it's in a language I don't know, which is all but Lisp.  Thanks for all the code you post Luis.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Change MText to a single color
« Reply #17 on: November 29, 2006, 06:17:01 PM »
Luis,

You'll see in the code below, where I changed some of yours to give you a different way of looking at it, syntactically as least...too tired for anything else at the moment.

The main change was to treat the textbox string as an array of char's and process that:
Code: [Select]
// char[ ] s = txtstr.ToCharArray();
int cont = 0, flag = 0;
string txt1 = ""/*, let = ""*/;
for (int j = 0; j < txtstr.Length; j++)
{
try
{
//let = s[cont].ToString();

char let = txtstr[cont];

// if (let == "\\")

if (let == '\\')
{
//if (s[(cont + 1)].ToString() == "C" || s[(cont + 1)].ToString() == "c")
if (char.ToUpper(txtstr[cont + 1]) == 'C')
{
int i = (cont + 2);
/*
while (s[i].ToString() != ";")
i = i + 1;
*/
while (txtstr[i] != ';')
i++;

// remove true and book colors
//if (s[i + 1].ToString() == "\\" && s[i + 2].ToString() == "c")
if (txtstr[i + 1] == '\\' && txtstr[i + 2] == 'c')
{
i = i + 2;
/*
while (s[i].ToString() != ";")
i = i + 1;
*/
while (txtstr[i] != ';')
i++;
}
//txt1 = txt1 + s[i + 1].ToString();
txt1 += txt1 + txtstr[i + 1];
cont = i + 2;
}
else
flag = 1;
}
else // color format found
{
txt1 = txt1 + let;

// remove the color blocks
int found;
found = txt1.IndexOf("{");
if (found >= 0)
txt1 = txt1.Remove(found, 1);
found = txt1.IndexOf("}");
if (found >= 0)
txt1 = txt1.Remove(found, 1);

cont = 1 + cont;
}
// no color format found
if (flag == 1)
{
txt1 = txt1 + let;
cont = 1 + cont;
flag = 0;
}
}
catch
{
//ed.WriteMessage("Error");
}
}

Cheers,
Glenn.
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change MText to a single color
« Reply #18 on: November 29, 2006, 06:31:00 PM »
With the exception of Glenn, I see a lot of views, but zero participation at all, I would like to know why, so in my future topics, I can post something of interest.

Don't worry yourself about it Luis,  just keep on posting, like the rest of us.

Someone will tell you if they don't like your posts,  I'm sure  :lol:   .. and some of us haven't had time to read them.


Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

LE

  • Guest
Re: Change MText to a single color
« Reply #19 on: November 29, 2006, 06:36:44 PM »
Luis,

You'll see in the code below, where I changed some of yours to give you a different way of looking at it, syntactically as least...too tired for anything else at the moment.

The main change was to treat the textbox string as an array of char's and process that:

Cheers,
Glenn.

Glenn;

Got it, I was trying to implement that first.... but got lost... I see it now - they are more hoops in C# but start to like it.

Thank you.
« Last Edit: November 29, 2006, 06:47:15 PM by LE »

LE

  • Guest
Re: Change MText to a single color
« Reply #20 on: November 29, 2006, 06:42:10 PM »
Don't worry yourself about it Luis,  just keep on posting, like the rest of us.

Someone will tell you if they don't like your posts,  I'm sure  :lol:   .. and some of us haven't had time to read them.

He he.... Thanks.

I will post the project in the C# forum, at least just to have a new post and get more points..... yeah!!!!

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Change MText to a single color
« Reply #21 on: November 29, 2006, 06:49:27 PM »
A lot LESS hoops compared to say C++ if you ask me Luis ;)
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change MText to a single color
« Reply #22 on: November 29, 2006, 06:55:10 PM »

I will post the project in the C# forum, at least just to have a new post and get more points..... yeah!!!!

Yeah,   .... posting there I'm more likely to at least see it,  ... just don't lost it in one of the "social" furums, some of us would never see it   :-)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

LE

  • Guest
Re: Change MText to a single color
« Reply #23 on: November 29, 2006, 07:10:19 PM »
Luis,

You'll see in the code below, where I changed some of yours to give you a different way of looking at it, syntactically as least...too tired for anything else at the moment.

The main change was to treat the textbox string as an array of char's and process that:
Code: [Select]
// char[ ] s = txtstr.ToCharArray();
int cont = 0, flag = 0;
string txt1 = ""/*, let = ""*/;
for (int j = 0; j < txtstr.Length; j++)

OK.... I copied (without checking your code) in my class, and is giving undesired results... I'll check that later at home, I know you did that on the fly... and will move the MtextEditor project to the C# forum...

Thanks.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Change MText to a single color
« Reply #24 on: November 29, 2006, 07:15:54 PM »
It definately was on the fly Luis, sorry about that. It was more intended to give you another idea/way of looking at it is all.

Cheers,
Glenn.
Me

LE

  • Guest
Re: Change MText to a single color
« Reply #25 on: November 29, 2006, 07:18:02 PM »
It definately was on the fly Luis, sorry about that. It was more intended to give you another idea/way of looking at it is all.

Yes I know  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change MText to a single color
« Reply #26 on: November 29, 2006, 07:22:14 PM »
Luis, The Mtext class has an  mtext.ExplodeFragments method  ... can you us that ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

LE

  • Guest
Re: Change MText to a single color
« Reply #27 on: November 29, 2006, 07:27:43 PM »
Luis, The Mtext class has an  mtext.ExplodeFragments method  ... can you us that ?

Yes... was the first one I tried.... and the idea is to show different ways... (well, when I do not have nothing else to do - lately it has been a lot, that's how I waste my time... in case you know if a company needs some help doing some janitorial services, let me know, I have Friday and Saturday open.... )

http://www.theswamp.org/index.php?topic=13650.msg164984#msg164984
« Last Edit: November 29, 2006, 07:31:30 PM by LE »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change MText to a single color
« Reply #28 on: November 29, 2006, 07:37:21 PM »
ok, didn't really try to digest the CPP earlier ...

Have you tried the ExplodeFragments in C# ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

LE

  • Guest
Re: Change MText to a single color
« Reply #29 on: November 29, 2006, 07:41:40 PM »
ok, didn't really try to digest the CPP earlier ...

Have you tried the ExplodeFragments in C# ?

nope.... but I would see if I can, later at home... it must be basically the same as my code in ARX... well it is just a guess.


Does anyone knows if exist a software to port C++ to C# (I know there is one from C# to C++).... just curios.

I would like to port my code of GBPoly... just to waste my time... as normal.... he he