Author Topic: Lisp to create simple text strings.  (Read 2179 times)

0 Members and 1 Guest are viewing this topic.

Lonnie

  • Newt
  • Posts: 183
Lisp to create simple text strings.
« on: September 08, 2023, 05:09:06 PM »
I am hoping for some help creating a lisp.
I have a bunch of pdf's I am making into dwg's. Most of the time it won't create text it creates vectors that will not convert to text. As a result I have a whole bunch of different pipe/duct/pressure text I have to retype.

Typically all I have to do is change the numbers and keep the text consistent.
Below is a lisp routine with two lisp that do ducts and gas pressures.

Quote

(defun c:T5T (/ mytext1 mytext2 textString p1 *w1* *w2* *w3* )

  (setq *w1* "(E) "
        *w2* "\" ("
        *w3* " CFH)"
  )

  (setq mytext1 (getstring "\nEnter the size: "))
  (setq mytext2 (getstring "\nEnter the CFM: "))

  (setq textString (strcat *w1* mytext1 *w2* mytext2 *w3*))
  (setq p1 (getpoint "\nSpecify insertion point: "))

  ; Insert the text
  (command "_text" p1 "0" textString)

  ; Erase all selected objects
  ; if (setq ss (ssget (list (cons 0 "~Text") (cons 0 "~MText"))))
  ;   (command "_erase" ss)
  ; )

  (princ)
)


Sorry for some reason my t4t lisp won't quote. It just hang the preview\save. Below is that attached lsp with both routines.

 Right now I am doing it with
words
(w1 w2 etc)

And

Questions
(mytext1 mytext2)

T4T was my first list I had to do

T5T was the second set.

By the time I am done I may have 15 different ones for various labels.
Does anyone have a better suggestion on how to go about this?

« Last Edit: September 08, 2023, 05:16:00 PM by Lonnie »

masao

  • Newt
  • Posts: 97
Re: Lisp to create simple text strings.
« Reply #1 on: September 10, 2023, 12:46:39 AM »
I am hoping for some help creating a lisp.
I have a bunch of pdf's I am making into dwg's. Most of the time it won't create text it creates vectors that will not convert to text. As a result I have a whole bunch of different pipe/duct/pressure text I have to retype.

Typically all I have to do is change the numbers and keep the text consistent.
Below is a lisp routine with two lisp that do ducts and gas pressures.

Quote

(defun c:T5T (/ mytext1 mytext2 textString p1 *w1* *w2* *w3* )

  (setq *w1* "(E) "
        *w2* "\" ("
        *w3* " CFH)"
  )

  (setq mytext1 (getstring "\nEnter the size: "))
  (setq mytext2 (getstring "\nEnter the CFM: "))

  (setq textString (strcat *w1* mytext1 *w2* mytext2 *w3*))
  (setq p1 (getpoint "\nSpecify insertion point: "))

  ; Insert the text
  (command "_text" p1 "0" textString)

  ; Erase all selected objects
  ; if (setq ss (ssget (list (cons 0 "~Text") (cons 0 "~MText"))))
  ;   (command "_erase" ss)
  ; )

  (princ)
)


Sorry for some reason my t4t lisp won't quote. It just hang the preview\save. Below is that attached lsp with both routines.

 Right now I am doing it with
words
(w1 w2 etc)

And

Questions
(mytext1 mytext2)

T4T was my first list I had to do

T5T was the second set.

By the time I am done I may have 15 different ones for various labels.
Does anyone have a better suggestion on how to go about this?

hi~i dont know your various labels text how to permutation. so i use "cond" to write it.

you can test it. have a good day.

BIGAL

  • Swamp Rat
  • Posts: 1429
  • 40 + years of using Autocad
Re: Lisp to create simple text strings.
« Reply #2 on: September 10, 2023, 08:17:50 PM »
Just watch out with Text there are 2 options it has a height or not. In your text style for your code you need height set to 0. If it has a size like 2.5 the text command skips that question so your code will do strange things. I would add at start of code which text style to use (setvar 'textstyle "yours") so make sure height is set to 0.

You can check for it and use correct (command "Text" will try to find.
A man who never made a mistake never made anything

Lonnie

  • Newt
  • Posts: 183
Re: Lisp to create simple text strings.
« Reply #3 on: September 13, 2023, 11:11:09 AM »
First thank you for your effort masao it get me a lot further along.
Secondly I am so sorry I've not gotten back to you all. The lisp did not work off the bat and workload comes first. As BIGAL predicted. The size being set was a problem. It simply changed the angle to whatever number and placed a 0 as the only piece of text. I had that problem when I first worked on my original lisp so I am confident I can fix that part. When done with no height set it works but I've not look at it well enough to try changing the words.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Lisp to create simple text strings.
« Reply #4 on: September 20, 2023, 08:52:41 AM »
I'm not exactly sure what you're trying to accomplish but this might help.

Code - Auto/Visual Lisp: [Select]
  1. ;; create text object in dwg
  2. (defun c:T5T (/ mytext1 mytext2 textString p1 w1 w2 w3)
  3.  
  4. ; constant variables
  5.   (setq w1 "(E) "
  6.         w2 "\" ("
  7.         w3 " CFH)"
  8.   )
  9.  
  10.   ; user input
  11.   (setq mytext1 (getstring "\nEnter the size: "))
  12.   (setq mytext2 (getstring "\nEnter the CFM: "))
  13.  
  14.   ; create variables
  15.   (setq textString (strcat w1 mytext1 w2 mytext2 w3))
  16.   (setq p1 (getpoint "\nSpecify insertion point: "))
  17.  
  18.   ; create entity
  19.     (list
  20.       '(0 . "TEXT")
  21.       (cons 10 p1)
  22.       (cons 8 (getvar "clayer"))
  23.       (cons 40 (getvar "textsize"))
  24.       (cons 1 textString)
  25.       (cons 7 (getvar "textstyle"))
  26.       '(72 . 1) ; = horz. centered
  27.       (cons 11 p1)
  28.       '(73 . 1) ; = vert. bottom
  29.     )
  30.   ); entmake
  31. ); defin
  32.  
TheSwamp.org  (serving the CAD community since 2003)