Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Text to Geometry Lisp code needed, please assist me!

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
ksmith84
2465 Views, 14 Replies

Text to Geometry Lisp code needed, please assist me!

Hello everybody.  I am new to the forums so I hope this is in the correct directory...

 

Ok, so I have been searching forever it seems to get an efficient conversion tool to replicate TXTEXP. After careful study of the forums and trying combinations of such tips, I've come up with a string of commands... I need help on turning this string into a LISP routine for job use. Having a LISP will save us considerable drawing time even in this condensed form~

The commands are this:

 

- The code is enacted with a wide text (Arial for example) in model space -

- start lisp routine with rectangular window selection only -

ZOOM OBJECT {PAUSE FOR SELECTION} ; (==STORE COORDINATES==)

CMDECHO 0; DISABLES COMMAND READOUT TO PREVENT CMD LINE CLUTTER
COPY P  0,0 0;   MAKES DUPLICATE OF THE SELECTED OBJECT
TXTEXP P ;   INITIATE EXPLODE
ZOOM P;    RESTORE CAMERA POSITION
REGION P UNION ; (==RECALL COORDINATES FOR UNION AND ONLY SELECT REGIONS==) *
EXPLODE P CMDECHO 1;  CONVERT TO POLYLINES, RESTORE SYS VARIABLE AND END SCRIPT
<start closing note here with blank line>
\nThe selected text has been exploded.
\nDouble check the oulines of any number 4 in the selected set.
{end lisp routine}

 

I am novice still at writing LISP routines, and have modified several, but have never been able to figure out coordinate storage or multiple command lisps such as this (which this code calls Previous selection /and/ coordinate sets often).

 

Thank you for any assistance on this!

 

 

Ken


~¤~
^C^CMoonwalk
14 REPLIES 14
Message 2 of 15
ksmith84
in reply to: ksmith84

The initial "copy" command is to create a duplicate of the text for other purposes within the drawing. 🙂


~¤~
^C^CMoonwalk
Message 3 of 15
alanjt_
in reply to: ksmith84

Why are you trying to replicate TXTEXP? Will what you are wanting to do accomplish something TXTEXP will not?

Message 4 of 15
ksmith84
in reply to: alanjt_

Heya Alan.  Thanks for the quick response.

 

Yes I am needing an AutoCad Mechanical 2009 friendly (and user-friendly) command that can create simple outlines of any text.  TXTEXP works well to convert it to geometry, but through several more commands am only able to make just outlines.  The text has to be done on a mass scale (200 or so words) per drawing, to be hatched in later.  The customer does not want the little marks that TXTEXP leaves behind when they receive the drawing.

 

I have been working a code which is incomplete but has the proccess needed to get this done:

 

(defun C:TTG (/ p1 p2 p3 p4)

; Our selection set
(setq ss1(
(setq p1 (getpoint "\First corner of selection window: ")
(setq p3 (getpoint "\Second corner of selection window: ")
(setq p2 (list (car p1)(cadr p3)))
(setq p4 (list (car p3)(cadr p1)))
)

(setvar 'cmdecho 0)

; Zoom into the objects for best clarity
(command "ZOOM" "OBJECT" "P")
(command "REGEN")

; Create duplicate - this can be hidden if needed
(command "COPY" "P" "" "0,0" "0")

; Destroy new text
(command "TXTEXP" "P")

; Camera reset
(command "ZOOM" "P")

; Create the outlines
(command "REGION" "P")

; Recall selection set and filter out everything else
(command "UNION" "WP" p1 p2 p3 p4 (setq ss1 (ssget "X" '((0 . "REGION")))) "")
(command "EXPLODE" "P")
(setvar 'cmdecho 1)

(prompt "\n\nThe Selected text has been exploded.\nDouble check the outlines of all number 4.")

(princ); End routine

)

 

I keep getting "malformed list" though it seems to read the entire lisp file.  Any ideas?


~¤~
^C^CMoonwalk
Message 5 of 15
ksmith84
in reply to: ksmith84

The only issue is with the font I am using, the number 4 is not drawn properly and half of it stays as a polyline rather than being converted to a region. The font is Arial Narrow (Bold).

~¤~
^C^CMoonwalk
Message 6 of 15
smaher12
in reply to: ksmith84


@ksmith84 wrote:
The only issue is with the font I am using, the number 4 is not drawn properly and half of it stays as a polyline rather than being converted to a region. The font is Arial Narrow (Bold).

You can try this. Sorry as I was not able to solve the number 4 issue as well.

 

(defun C:tmp (/ p1 p2 ss ss1)
  (setq old-echo (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  
  (setq p1 (getpoint "\nPick first corner: "))
  (setq p2 (getcorner p1 "\nSpecify opposite corner: "))
  (if (setq ss (ssget "W" p1 p2 '((0 . "*TEXT"))))
    (progn
      (command "zoom" "o" ss "")
      (command "copy" ss "" "" "")
      (sssetfirst nil ss)
      (C:Txtexp)
      (command "region" "_P" "")
      
   (setq ss1 (ssget "W" p1 p2 '((0 . "REGION"))))
      (command "union" ss1 "")
      (command "explode" ss1)
      (command "zoom" "p")
      (prompt "\nThe Selected text has been exploded. Double check the outlines of all number 4.")
    ); progn
  ); if
  (setvar 'cmdecho old-echo)
 (princ)
)

 

Message 7 of 15
ksmith84
in reply to: smaher12

Thank you very much smaher12!! The lisp works perfectly!

~¤~
^C^CMoonwalk
Message 8 of 15
smaher12
in reply to: ksmith84


@ksmith84 wrote:
Thank you very much smaher12!! The lisp works perfectly!

You are weclome. Glad I could help. Enjoy...

Message 9 of 15
ksmith84
in reply to: smaher12


@smaher12 wrote:

@ksmith84 wrote:
Thank you very much smaher12!! The lisp works perfectly!

You are weclome. Glad I could help. Enjoy...


 

Modified the code a bit to have a simple Yes/No option at the start, for when you want to /keep a copy of the original text/ or if you wish to delete the text.  Working on another code for the 'number 4' txtexp problem.  Based off of what I've learned here, there may be a deeper rooted command that may come in handy!  Thanks for all the help with this!  🙂


~¤~
^C^CMoonwalk
Message 10 of 15
smaher12
in reply to: ksmith84

Just for simplicity I would do the following:

 

(defun C:ttg1 (/ p1 p2 ss ss1)
  (setq old-echo (getvar 'cmdecho))
  (setvar 'cmdecho 0)

  (initget 1 "Y N")
  (setq option (getkword "\nDo you want to keep the source text? (Yes/No): "))
  (setq p1 (getpoint "\nPick first corner: "))
  (setq p2 (getcorner p1 "\nSpecify opposite corner: "))
  (if (setq ss (ssget "W" p1 p2 '((0 . "*TEXT"))))
    (progn
      (command "zoom" "o" ss "")

      (if (= option "Y")
        (command "copy" ss "" "" "")
      )
 
      (sssetfirst nil ss)
      (C:Txtexp)
      (command "region" "_P" "")
      
   (setq ss1 (ssget "W" p1 p2 '((0 . "REGION"))))
      (command "union" ss1 "")
      (command "explode" ss1)
      (command "zoom" "p")
      (prompt "\n~¤~TTG complete.")
    ); progn
  ); if
  (setvar 'cmdecho old-echo)
 (princ)
)

 

Message 11 of 15
ksmith84
in reply to: smaher12

Ah, got ya. So lisp code can have variations... What I mean is instead of defining code for both options, state "what to do" only on Yes, and just run the regular code otherwise.

~¤~
^C^CMoonwalk
Message 12 of 15
smaher12
in reply to: ksmith84


@ksmith84 wrote:
Ah, got ya. So lisp code can have variations... What I mean is instead of defining code for both options, state "what to do" only on Yes, and just run the regular code otherwise.

You got it... Also, if you only need a copy of the text occasionally you may want consider doing the following as it will save you the step of entering N each time you run the code.

 

  (initget "Y N")
  (setq option (getkword "\nDo you want to keep the source text? [Yes/No] <N>: "))

 

Message 13 of 15
ksmith84
in reply to: smaher12

Been digging around a bit.  The solution might be easier than I thought... When the text is proccessing the number 4, after the text is exploded, the polyline left behind always has the vertex in the same draw order.  In theory, PEDIT could solve this via the Edit Vertex > Move (to the next vertex) - see screenshot.


~¤~
^C^CMoonwalk
Message 14 of 15
alanjt_
in reply to: ksmith84


@ksmith84 wrote:

Been digging around a bit.  The solution might be easier than I thought... When the text is proccessing the number 4, after the text is exploded, the polyline left behind always has the vertex in the same draw order.  In theory, PEDIT could solve this via the Edit Vertex > Move (to the next vertex) - see screenshot.


 

 

Newer versions of cad allow for vertex editing in grip mode.

 

FYI: when posting a screenshot, don't use blue objects on a black background. The screenshot will always be low quality and very difficult to look at.

Message 15 of 15
ksmith84
in reply to: ksmith84

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost