Jump to content

Recommended Posts

Posted

I am look for a LISP to convert texts (dtext mainly) with several words to each word its own text. I thought there once was a LISP like this, but my searches have come up empty.

 

In the attached drawing, I have the top text (white), what I need is for it to be in individual texts, as the lower texts (red).

Posted

Any formatting or special characters?

 

Is all the text left-justified or does it vary?

 

Might be of some interest....http://www.theswamp.org/index.php?topic=37370.0

Posted

Thanks, ReMark....As Expected Lee Mac's S2W.lsp works a treat for now, AFAIK they should all be LEFT justified as in the example drawing, if I find some that aren't I can remedy that easy enough.

 

Those other two, CHOP.lsp just hangs and Shatter.lsp made each word a 0 (at least on AutoCAD 2011).

Posted
As Expected Lee Mac's S2W.lsp works a treat for now

 

Excellent to hear SLW :thumbsup:

 

Here is an updated version of the code found here, the following should work with all Text justification (except Aligned / Middle / Fit):

 

[color=GREEN];;------------------=={ Sentence to Words }==-----------------;;[/color]
[color=GREEN];;                                                            ;;[/color]
[color=GREEN];;  Converts a selection of Text objects into separate Text   ;;[/color]
[color=GREEN];;  objects for each word, retaining all properties of the    ;;[/color]
[color=GREEN];;  original objects.                                         ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]
[color=GREEN];;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;[/color]
[color=GREEN];;------------------------------------------------------------;;[/color]

([color=BLUE]defun[/color] c:s2w ( [color=BLUE]/[/color] _splitwords _textwidth ang dxf ent enx fun inc lst pnt sel spc tot wid )

   ([color=BLUE]defun[/color] _splitwords ( str [color=BLUE]/[/color] pos )
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] pos ([color=BLUE]vl-string-position[/color] 32 str))
           ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] 1 ([color=BLUE]substr[/color] str 1 pos)) (_splitwords ([color=BLUE]substr[/color] str ([color=BLUE]+[/color] pos 2))))
           ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 1 str))
       )
   )

   ([color=BLUE]defun[/color] _textwidth ( enx )
       (([color=BLUE]lambda[/color] ( lst ) ([color=BLUE]-[/color] ([color=BLUE]caadr[/color] lst) ([color=BLUE]caar[/color] lst))) ([color=BLUE]textbox[/color] enx))
   )

   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color] '((0 . [color=MAROON]"TEXT"[/color]) (-4 . [color=MAROON]"<NOT"[/color]) (-4 . [color=MAROON]"<OR"[/color]) (72 . 3) (72 . 4) (72 . 5) (-4 . [color=MAROON]"OR>"[/color]) (-4 . [color=MAROON]"NOT>"[/color]))))
       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] sel))
           ([color=BLUE]setq[/color] ent ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc)))
                 enx ([color=BLUE]entget[/color] ent)
                 tot 0.0
                 lst [color=BLUE]nil[/color]
           )
           ([color=BLUE]foreach[/color] item (_splitwords ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1 enx)))
               ([color=BLUE]setq[/color] dxf ([color=BLUE]entget[/color] ([color=BLUE]entmakex[/color] ([color=BLUE]subst[/color] item ([color=BLUE]assoc[/color] 1 enx) enx)))
                     wid (_textwidth dxf)
                     tot ([color=BLUE]+[/color] tot wid)
                     lst ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] dxf wid) lst)
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]<[/color] 1 ([color=BLUE]length[/color] lst))
               ([color=BLUE]progn[/color]
                   ([color=BLUE]setq[/color] wid (_textwidth enx)
                         spc ([color=BLUE]/[/color] ([color=BLUE]-[/color] wid tot) ([color=BLUE]float[/color] ([color=BLUE]1-[/color] ([color=BLUE]length[/color] lst))))
                         lst ([color=BLUE]reverse[/color] lst)
                         ang ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 50 enx))
                   )
                   ([color=BLUE]if[/color]
                       ([color=BLUE]and[/color]
                           ([color=BLUE]=[/color] 0 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 72 enx)))
                           ([color=BLUE]=[/color] 0 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 73 enx)))
                       )
                       ([color=BLUE]setq[/color] pnt ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 enx)))
                       ([color=BLUE]setq[/color] pnt ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 11 enx)))
                   )
                   ([color=BLUE]cond[/color]
                       (   ([color=BLUE]=[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 72 enx)) 0)
                           ([color=BLUE]setq[/color] fun ([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]+[/color] spc ([color=BLUE]cdr[/color] a))))
                       )
                       (   ([color=BLUE]=[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 72 enx)) 1)
                           ([color=BLUE]setq[/color] fun ([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]+[/color] spc ([color=BLUE]/[/color] ([color=BLUE]+[/color] ([color=BLUE]cdr[/color] a) ([color=BLUE]cdr[/color] b)) 2.0)))
                                 pnt ([color=BLUE]polar[/color] pnt ([color=BLUE]+[/color] ang [color=BLUE]pi[/color]) ([color=BLUE]/[/color] ([color=BLUE]-[/color] wid ([color=BLUE]cdar[/color] lst)) 2.0))
                           )
                       )
                       (   ([color=BLUE]=[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 72 enx)) 2)
                           ([color=BLUE]setq[/color] fun ([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]+[/color] spc ([color=BLUE]cdr[/color] b)))
                                 pnt ([color=BLUE]polar[/color] pnt ([color=BLUE]+[/color] ang [color=BLUE]pi[/color]) ([color=BLUE]-[/color] wid ([color=BLUE]cdar[/color] lst)))
                           )
                       )
                   )
                   ([color=BLUE]mapcar[/color]
                       ([color=BLUE]function[/color]
                           ([color=BLUE]lambda[/color] ( a b [color=BLUE]/[/color] dxf )
                               ([color=BLUE]setq[/color] dxf ([color=BLUE]car[/color] a)
                                     dxf ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 10 pnt) ([color=BLUE]assoc[/color] 10 dxf) dxf)
                                     dxf ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 11 pnt) ([color=BLUE]assoc[/color] 11 dxf) dxf)
                                     pnt ([color=BLUE]polar[/color] pnt ang (fun a b))
                               )
                               ([color=BLUE]entmod[/color] dxf)
                           )
                       )
                       lst ([color=BLUE]append[/color] ([color=BLUE]cdr[/color] lst) '(([color=BLUE]nil[/color] . 0.0)))
                   )
                   ([color=BLUE]entdel[/color] ent)
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Posted

I have a few old drawings done previous to my employment with column headings of several words in 1 text and varying spacing to align with the columns. Needless to say that looks like heck and I MUST fix them. :ouch:

 

I had to work on other things this afternoon, but tomorrow I will be using this quite a lot. I reworked one drawing today and your LISP worked very very well. :notworthy:

 

Hopefully it will get a good workout tomorrow. :thumbsup:

Posted

That's great to hear SLW, I always like to know that a program that I have written is being put to good use and, by removing some of the more tedious drafting jobs, boosting the morale of it's operator :)

  • 2 years later...
Posted

I have a sentence in mtext and all the words are separated with TAB spacer. What is the modification to make so that it only breaks the tabs between words and not regular spaces.

 

Thank you.

Posted (edited)
I have a sentence in mtext and all the words are separated with TAB spacer. What is the modification to make so that it only breaks the tabs between words and not regular spaces.

 

Thank you.

 

hi fervour welcome to CADtutor & happy new year.

im not sure, if you can post an example so other members could assist.

perhaps vl-string-translate : Replaces characters in a string with a specified set of characters?

(vl-string-translate source-set dest-set str)

 

Or --> this?

Edited by hanhphuc
Link added
Posted

Thanks Lee. I have extended my inquiries on theswamp thread.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...