Author Topic: Routine improvement  (Read 2182 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Routine improvement
« on: April 26, 2018, 09:48:42 AM »
Am I shootin' for the Moon here?
This old routine requires the user to type one character at a time and hit enter for each one.
The result is blocks (polylines not actual text) representing those characters being inserted for the purpose of laser engraving on our metal products. What I could use help on is trying to type in all characters and hit enter once to complete the process.
I know this is probably a stretch, but any ideas how to accomplish this would be greatly appreciated. Thanks.
Code: [Select]
(DEFUN C:LASERTXT()
;  This routine will:
;          Create & set current the "CNC" layer with a color of "140"
;          Create layer  called "TICS"
;          Insert (8) blocks representing single digit numbers OR letters as polylines
;                 - scale of (1) and a height of .249
;
;  All 8 characters must then be indicated.... by typing
;         a single character and pressing enter for each
;  User must select an insertion point for the each character  (users choice)
;
;  Insertion points will appear as lines (tics) and must be selected accordingly
;           as each character is placed in the drawing
;
;  Inserted blocks are exploded
;  Layer "TICS" is deleted and drawing is purged at conclusion
;
; The following drawing files must be available for this to work:
;
;   0 thru 9 and  A thru Z

(COMMAND "-LAYER" "m" "TICS" "")
(COMMAND "-LAYER" "m" "cnc" "c" "255" "CNC" "s" "cnc" "")

(INITGET 128)
 (SETQ NUM1 (GETKWORD "\n1st Character : "))

(INITGET 128)
 (SETQ NUM2 (GETKWORD "\n2nd Character: "))

(INITGET 128)
 (SETQ NUM3 (GETKWORD "\n3rd Character: "))

(INITGET 128)
 (SETQ NUM4 (GETKWORD "\n4th Character: "))

(INITGET 128)
 (SETQ NUM5 (GETKWORD "\n5th Character: "))

(INITGET 128)
 (SETQ NUM6 (GETKWORD "\n6th Character: "))

(INITGET 128)
 (SETQ NUM7 (GETKWORD "\n7th Character: "))

(INITGET 128)
 (SETQ NUM8 (GETKWORD "\n8th Character: "))

(COMMAND "-insert" NUM1 PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM2 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM3 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM4 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM5 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM6 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM7 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(COMMAND "-insert" NUM8 "ENDPOINT" PAUSE "1" "1" "0")
(command "explode" "last")

(setq ss (ssget "X" '((8 . "TICS"))))
(command ".erase" ss "")

(COMMAND "-PURGE" "ALL" "" "N")

)


tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Routine improvement
« Reply #2 on: April 26, 2018, 10:45:48 AM »
Looks like you could ask the user for the string, then parse the string into the individual characters.

Code: [Select]

(setq x (getstring "\nEnter an 8 character string ") q 1 k '())
(repeat 8
  (setq k (append (list (substr x q 1)) k) q (1+ q)) 
)
(reverse k)

User enters "ABCDEFGH"
Returns a list ("A" "B" "C" "D" "E" "F" "G" "H")
Then you could iterate this list inserting the appropriate geometry

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Routine improvement
« Reply #3 on: April 26, 2018, 05:39:40 PM »
Here's a quick one based off your example:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:lasertxt (/ p)
  2.   ;; RJP - 04.26.2018
  3.                      (vl-remove-if-not
  4.                        '(lambda (x) (wcmatch (chr x) "[A-Za-z0-9]"))
  5.                        (vl-string->list (getstring "\nEnter your string of 8 characters: "))
  6.                      )
  7.              )
  8.     (cond ((and (or (tblobjname "block" l) (findfile (strcat l ".dwg")))
  9.                 (setq p (getpoint (strcat "\nPick a point to place " l ": ")))
  10.            )
  11.            (command "-insert" l "ENDPOINT" p "1" "1" "0")
  12.            (command "explode" "last")
  13.           )
  14.           ((print (strcat "Block " l " not found!!")))
  15.     )
  16.   )
  17.   (princ)
  18. )
« Last Edit: April 27, 2018, 09:32:12 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Routine improvement
« Reply #4 on: April 27, 2018, 11:50:18 AM »
Wow, a truly awesome piece of work!

Your Routine (short and sweet) allows for any number of characters.
I certainly did not expect that.

Thank you so much for your handy-work!
No steaks though......guess I owe a whole cow and a keg of the good stuff.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Routine improvement
« Reply #5 on: April 27, 2018, 02:19:19 PM »
Wow, a truly awesome piece of work!

Your Routine (short and sweet) allows for any number of characters.
I certainly did not expect that.

Thank you so much for your handy-work!
No steaks though......guess I owe a whole cow and a keg of the good stuff.
Glad it helps you out :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Routine improvement
« Reply #6 on: April 27, 2018, 06:27:16 PM »
Your Routine (short and sweet) allows for any number of characters.
I certainly did not expect that.

Rontine sounds better!  :-D
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Routine improvement
« Reply #7 on: April 27, 2018, 11:20:35 PM »
Your Routine (short and sweet) allows for any number of characters.
I certainly did not expect that.

Rontine sounds better!  ;D
🍻
« Last Edit: April 27, 2018, 11:26:47 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MeasureUp

  • Bull Frog
  • Posts: 465
Re: Routine improvement
« Reply #8 on: April 29, 2018, 09:23:58 PM »
"Rontine sounds better!"
I like this.
:laugh: