Author Topic: Help joining text together into one piece of mtext  (Read 7010 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Help joining text together into one piece of mtext
« on: October 22, 2010, 06:40:56 PM »
I am working on combining a few routines that I have that work with text and in the process I want to fix one of them. I have a routine that joins text together into one piece of mtext. The routine works fine as long as the first piece of text is already mtext, but I don't want my users to have to think about it. I know I could call the express tools command txt2mtxt, but I am trying to avoid that for a variety of reasons.

I have the command most of the way there, but for some reason the text moves a bit when it is converted, which I do not want, I would like for it to stay at the correct insertion point. I know that there are many on here with far better skills than I at LISP, so I thought I would ask for a little help.

Also on another note, I want it to be able to remove tabs from regular text and mtext, if you can look at the tabs portion as well and tell me what's wrong with it. (For now, I have remarked out what I need to in order to make this mode not selectable).

I appreciate any help that you can provide.


[edit:kdub. Modify Thread Title.]
« Last Edit: October 22, 2010, 07:54:11 PM by cmwade77 »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help joining text together into one piece of mtext
« Reply #1 on: October 23, 2010, 12:11:20 AM »
Haven't looked at your code but,
This won't do it for you?
http://www.theswamp.org/index.php?topic=35382.msg406001#msg406001
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help joining text together into one piece of mtext
« Reply #2 on: October 23, 2010, 12:18:59 AM »
Oh, sorry Chris I see you have some other things going on there.
Maybe more time tomorrow. 

ZZZZZZZZZZZZZZZZZz
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hermanm

  • Guest
Re: Help joining text together into one piece of mtext
« Reply #3 on: October 23, 2010, 02:59:03 AM »
vl-string-subst replaces only the first instance it finds:
Code: [Select]
Command: !astring
"abc\tdef\t\tqrst\t"
Command: (vl-string-subst "" "\t" astring)
"abcdef\t\tqrst\t"
Command: !bstring
"abcdefabc"
Command: (vl-string-subst "qrs" "abc" bstring)
"qrsdefabc"

So, you can test after each pass, and call the function again on the modified string if any tabs remain.

Code: [Select]
(defun detab (astring / )
  (if (vl-string-position 9
      (setq astring (vl-string-subst "" "\t" astring)))
      (setq astring(detab astring)))
  astring
)
Command: (detab astring)
"abcdefqrst"

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help joining text together into one piece of mtext
« Reply #4 on: October 25, 2010, 11:09:56 AM »
I do repeat the tab test; however, it seems that in 2011 \t is not the code for tabs for some reason.

If I list a piece of text with tabs in it, I get the following result:

Quote
This is a        test with    tabs in           it.

In the properties palette it displays the same way. In 2010 it would have had the \t in place of tabs in both locations. So, I am not sure what the problem is.

hermanm

  • Guest
Re: Help joining text together into one piece of mtext
« Reply #5 on: October 25, 2010, 05:10:48 PM »
I see what you mean :(
Attached image from a 3rd party text editor in 2011 shows the tabs as non-printing chars (which they are, obviously)

but:

Command: (chr 9)
"\t"

Stumped. for the moment.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help joining text together into one piece of mtext
« Reply #6 on: October 25, 2010, 05:19:07 PM »
I do repeat the tab test; however, it seems that in 2011 \t is not the code for tabs for some reason.

If I list a piece of text with tabs in it, I get the following result:

Quote
This is a        test with    tabs in           it.

In the properties palette it displays the same way. In 2010 it would have had the \t in place of tabs in both locations. So, I am not sure what the problem is.


What do you get when you use this to select the mtext you are testing?
Code: [Select]
(assoc 1 (entget(car(entsel))))and this
Code: [Select]
(vl-string->list (cdr (assoc 1 (entget(car(entsel))))))
« Last Edit: October 25, 2010, 05:22:55 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help joining text together into one piece of mtext
« Reply #7 on: October 25, 2010, 05:22:17 PM »
I do get the \t that way....but it will require some reworking of my code. I was hoping to keep only the vla stuff, but if it won't work that way, then I may have to opt for the old way of working it.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help joining text together into one piece of mtext
« Reply #8 on: October 25, 2010, 05:38:36 PM »
How about this?
Code: [Select]
(vl-list->string (vl-remove 9 (vl-string->list (cdr (assoc 1 (entget(car(entsel))))))))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help joining text together into one piece of mtext
« Reply #9 on: October 25, 2010, 06:51:52 PM »
Thanks CAB, the link to the code above worked for combining into mtext. The code for tabs works some of the time, but I have attached an example of what occasionally happens. The first picture is what it starts with, the second is what I end up with. Any ideas? I have also attached the latestcode.
« Last Edit: October 25, 2010, 06:55:29 PM by cmwade77 »

Sam

  • Bull Frog
  • Posts: 201
Re: Help joining text together into one piece of mtext
« Reply #10 on: October 26, 2010, 02:37:05 AM »
dear sir
i thing help for u
very useful tool
from lee mac
http://www.cadtutor.net/forum/showthread.php?43115-Text-2-MText-Upgraded
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Joe Burke

  • Guest
Re: Help joining text together into one piece of mtext
« Reply #11 on: October 26, 2010, 06:52:09 AM »
For what it's worth...

In general the string returned by (cdr (assoc 1 (entget <mtext ename>))) is more reliable than what (vlax-get <mtext object> 'TextString) returns.

Example: the mtext string on screen is "this <delta symbol> that". The vlisp function returns "this ? that". Entget returns "this Δ that".

Stuff I learned while working on StripMtext with Steve Doman.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Help joining text together into one piece of mtext
« Reply #12 on: October 26, 2010, 06:06:34 PM »
The problem with that method is if the text is too long, it only returns a small portion of the text. For my needs, I generally will not have the symbols, but I will have long (sometimes extremely long) pieces of text to work with.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help joining text together into one piece of mtext
« Reply #13 on: October 27, 2010, 12:54:14 AM »
For what it's worth...

In general the string returned by (cdr (assoc 1 (entget <mtext ename>))) is more reliable than what (vlax-get <mtext object> 'TextString) returns.
Agreed.

The problem with that method is if the text is too long, it only returns a small portion of the text. For my needs, I generally will not have the symbols, but I will have long (sometimes extremely long) pieces of text to work with.
Just step through the entity data, strcat all 1 and 3 dxf codes and you'll have your string.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help joining text together into one piece of mtext
« Reply #14 on: October 27, 2010, 08:20:24 AM »
Maybe this?
Code: [Select]
;;  CAB 01.08.2010    
;;  If 2 dxf 1's ignore the first occurrence
(defun Get-String (ent / str dxf1)
  (if (= (type ent) 'VLA-OBJECT)
     (setq ent (vlax-vla-object->ename ent))
  )
  (setq str "" dxf1 "")
  (mapcar (function (lambda (x)
     (cond
       ((= (car x) 3)(setq str (strcat str (cdr x))))
       ((= (car x) 1)(setq dxf1 (cdr x)))
     )))
    (entget ent)
  )
  (setq str (strcat str dxf1))
)
« Last Edit: October 27, 2010, 08:49:07 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.