Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
poorestchump
Posts: 79
Registered: ‎01-18-2005
Message 1 of 19 (294 Views)

(entdel (entlast))

294 Views, 18 Replies
12-02-2009 06:13 AM
Sloppy, cumbersome & old school mostly but "(entdel (entlast))" was working before I screwed this up somehow. It's a work in progress but... one baby step at a time, right? Any help is greatly appreciated. There's an attached dynamic block to try this on if someone can help.
Thanks,
jb

(princ "\nLoading san3.LSP program...jbailey, dec. 2009")
(princ "\nSequential number/letter replacement")
(prin1)
(defun alpha ()
(cond ((= (strcase number) "A")
(setq number "1")
(setq yn T)
)
((= (strcase number) "B")
(setq number "2")
(setq yn T)
)
((= (strcase number) "C")
(setq number "3")
(setq yn T)
)
((= (strcase number) "D")
(setq number "4")
(setq yn T)
)
((= (strcase number) "E")
(setq number "5")
(setq yn T)
)
((= (strcase number) "F")
(setq number "6")
(setq yn T)
)
((= (strcase number) "G")
(setq number "7")
(setq yn T)
)
((= (strcase number) "H")
(setq number "8")
(setq yn T)
)
((= (strcase number) "I")
(setq number "9")
(setq yn T)
)
((= (strcase number) "J")
(setq number "10")
(setq yn T)
)
((= (strcase number) "K")
(setq number "11")
(setq yn T)
)
((= (strcase number) "L")
(setq number "12")
(setq yn T)
)
((= (strcase number) "M")
(setq number "13")
(setq yn T)
)
((= (strcase number) "N")
(setq number "14")
(setq yn T)
)
((= (strcase number) "O")
(setq number "15")
(setq yn T)
)
((= (strcase number) "P")
(setq number "16")
(setq yn T)
)
((= (strcase number) "Q")
(setq number "17")
(setq yn T)
)
((= (strcase number) "R")
(setq number "18")
(setq yn T)
)
((= (strcase number) "S")
(setq number "19")
(setq yn T)
)
((= (strcase number) "T")
(setq number "20")
(setq yn T)
)
((= (strcase number) "U")
(setq number "21")
(setq yn T)
)
((= (strcase number) "V")
(setq number "22")
(setq yn T)
)
((= (strcase number) "W")
(setq number "23")
(setq yn T)
)
((= (strcase number) "X")
(setq number "24")
(setq yn T)
)
((= (strcase number) "Y")
(setq number "25")
(setq yn T)
)
((= (strcase number) "Z")
(setq number "26")
(setq yn T)
)
)
)
(defun numer ()
(cond ((= number "1")
(setq number "A")
)
((= number "2")
(setq number "B")
)
((= number "3")
(setq number "C")
)
((= number "4")
(setq number "D")
)
((= number "5")
(setq number "E")
)
((= number "6")
(setq number "F")
)
((= number "7")
(setq number "G")
)
((= number "8")
(setq number "H")
)
((= number "9")
(setq number "I")
)
((= number "10")
(setq number "J")
)
((= number "11")
(setq number "K")
)
((= number "12")
(setq number "L")
)
((= number "13")
(setq number "M")
)
((= number "14")
(setq number "N")
)
((= number "15")
(setq number "O")
)
((= number "16")
(setq number "P")
)
((= number "17")
(setq number "Q")
)
((= number "18")
(setq number "R")
)
((= number "19")
(setq number "S")
)
((= number "20")
(setq number "T")
)
((= number "21")
(setq number "U")
)
((= number "22")
(setq number "V")
)
((= number "23")
(setq number "W")
)
((= number "24")
(setq number "X")
)
((= number "25")
(setq number "Y")
)
((= number "26")
(setq number "Z")
)
)
)

(defun doit (/ )
(vl-load-com)
(command "-mtext" "0,0" "100,100" NEW_TEXT "")
(setq src (vlax-ename->vla-object (entlast)))
(setq targ (vlax-ename->vla-object targ))
(vlax-put targ 'TextString (vlax-get src 'TextString))
(entdel (entlast));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAS WORKING BEFORE!!!!!!!!!!!!!!!!!!!!!!!!!!!
)

(Defun C:san3 (/ );change pref suf no loop pref change old_text_list old_text new_text new_text new_list text
(setq yn nil)
(setq CHANGE nil)
(setq NUMBER (getstring "\nEnter starting number or letter: "))
(alpha)
(setq PREF (getstring 1 "\nEnter prefix: "))
(setq SUF (getstring 1 "\nEnter suffix: "))
(setq INC (getint "\nIncrement <1>: "))
(if (= INC nil)
(setq INC 1)
)
(setq LOOP T)
(while LOOP
(initget "eXit Override Increment")
(setq targ (car (nentsel "\nOverride/Increment/eXit
*Expert Elite*
Kent1Cooper
Posts: 5,795
Registered: ‎09-13-2004
Message 2 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 06:47 AM in reply to: poorestchump
I don't know why (entget (entlast)) wouldn't be working any more, but on another note, I have a suggestion for a significant streamlining.

You can replace *both* your entire 'alpha' and 'numer' functions with a very much shorter *combined* function, which can determine for itself whether the text you give it represents a letter or a number, and change it to the corresponding value of the other type:

{code}
(defun ANIT (txt); for Alpha-Numeric Integer Toggle
(setq txt
(if (zerop (atoi txt)); if alphabetic
(itoa (- (ascii (strcase txt)) 64)); change to number
(chr (+ (atoi txt) 64)); change to letter
); end if
); end setq
); end defun
{code}

Load that up, and then:

Command: (anit "A")
"1"
Command: (anit "f")
"6"
Command: (anit "24")
"X"
Command: (anit "3")
"C"
....etc....

It could be expanded if you like, to check *whether* the given text is either a single letter character or represents an integer within the right range. But since you don't have any such check in your code, maybe you have control over that, and can be certain that it always will be one of those, in which case there's no need.

--
Kent Cooper
Kent Cooper
Valued Contributor
poorestchump
Posts: 79
Registered: ‎01-18-2005
Message 3 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 07:10 AM in reply to: poorestchump
Kent,
I knew I could count on you for something... if I can just make it work.
(entdel (enlast)) works at the command line, by the way.
Thanks for the tip. I need all the help I can get.
jb
Distinguished Contributor
cab2k
Posts: 463
Registered: ‎12-15-2003
Message 4 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 08:07 AM in reply to: poorestchump
Another numbering Tool, if you care to join, it's free.

Incremental Numbering Tool & Automatic Numbering by Lee McDonald
http://www.theswamp.org/index.php?topic=28727.0
Valued Contributor
poorestchump
Posts: 79
Registered: ‎01-18-2005
Message 5 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 11:01 AM in reply to: poorestchump
Something's still wrong. Anybody?
Use previously attached block to try if interested in helping a dumacss get this out of my hair.
Thanks,
jb

(princ "\nLoading Cntch.LSP program...jbailey, dec. 2009")
(princ "\nSequential number/letter replacement")
(prin1)
(defun ANIT (); for Alpha-Numeric Integer Toggle
(setq NUMBER
(if (zerop (atoi NUMBER)); if alphabetic
(itoa (- (ascii (strcase NUMBER)) 64)); change to number
(chr (+ (atoi NUMBER) 64)); change to letter
); end if
); end setq
); end defun


(defun doit (/ )
(vl-load-com)
(command "-mtext" "0,0" "100,100" NEW_TEXT "")
(setq src (vlax-ename->vla-object (entlast)))
(setq targ (vlax-ename->vla-object targ))
(vlax-put targ 'TextString (vlax-get src 'TextString))
(entdel (entlast));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAS WORKING BEFORE!!!!!!!!!!!!!!!!!!!!!!!!!!!
)

(Defun C:san4 (/ );change pref suf no loop pref change old_text_list old_text new_text new_text new_list text
(setq yn nil)
(setq CHANGE nil)
(setq NUMBER (getstring "\nEnter starting number or letter: "))
(setq PREF (getstring 1 "\nEnter prefix: "))
(setq SUF (getstring 1 "\nEnter suffix: "))
(setq INC (getint "\nIncrement <1>: "))
(if (= INC nil)
(setq INC 1)
)
(setq LOOP T)
(while LOOP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;BEGIN PROGRAM
(initget "eXit Override Increment")
(setq targ (car (nentsel "\nOverride/Increment/eXit
*Expert Elite*
Kent1Cooper
Posts: 5,795
Registered: ‎09-13-2004
Message 6 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 02:00 PM in reply to: poorestchump
It occurs to me to wonder why you're putting in a piece of Mtext with its content taken from the NEW_TEXT variable, then imposing that content on 'targ' by extracting it out of that Mtext, and then deleting the Mtext. Why not just impose NEW_TEXT on 'targ' directly, and skip the Mtext altogether? E.g. change the 'doit' function to just

{code}
(defun doit (/ )
(vl-load-com)
(setq targ (vlax-ename->vla-object targ))
(vlax-put targ 'TextString NEW_TEXT)
)
{code}

If that will work for you, the misbehaving function won't be around to misbehave at all.

--
Kent Cooper
Kent Cooper
Valued Contributor
poorestchump
Posts: 79
Registered: ‎01-18-2005
Message 7 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 02:06 PM in reply to: poorestchump
In as few words as possible...
I'M STUPID!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
aND THAnks FOr POintinG that out.
jb

BTW, the entdel started working as I got a little further along. Now I'm having problems getting the alpha characters to letter sequentially. Edited by: jerryb@dtihome.com on Dec 2, 2009 10:12 AM
Valued Contributor
poorestchump
Posts: 79
Registered: ‎01-18-2005
Message 8 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 02:52 PM in reply to: poorestchump
Now I'm really confused. The "number" starts with "-16"... next number: "001"... next number: "00A"... next number "001"... "00A"... "001"...
What the Whell am i doing?

(defun ANIT (); for Alpha-Numeric Integer Toggle
(setq NUMBER
(if (zerop (atoi NUMBER)); if alphabetic
(itoa (- (ascii (strcase NUMBER)) 64)); change to number
(chr (+ (atoi NUMBER) 64)); change to letter
); end if
); end setq
(SETQ ALPH T)
); end defun


(defun doit (/ )
(vl-load-com)
(vl-load-com)
(setq targ (vlax-ename->vla-object targ))
(vlax-put targ 'TextString NEW_TEXT)
)

(Defun C:san4 (/ );change pref suf no loop pref change old_text_list old_text new_text new_text new_list text
(setq CHANGE nil)
(setq NUMBER (getstring "\nEnter starting number or letter: "))
(if (= (wcmatch NUMBER "@"))
(ANIT)
)
(setq NUMBER (atoi NUMBER))
(setq NUMBER (- NUMBER INC))
(setq NUMBER (itoa NUMBER))
(if (= ALPH T)
(ANIT)
)
(setq PREF (getstring 1 "\nEnter prefix: "))
(setq SUF (getstring 1 "\nEnter suffix: "))
(setq INC (getint "\nIncrement <1>: "))
(if (= INC nil)
(setq INC 1)
)
(setq LOOP T)
(while LOOP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;BEGIN PROGRAM
(initget "eXit Override Increment")
(setq targ (car (nentsel "\nOverride/Increment/eXit
Distinguished Contributor
cab2k
Posts: 463
Registered: ‎12-15-2003
Message 9 of 19 (294 Views)

Re: (entdel (entlast))

12-02-2009 03:15 PM in reply to: poorestchump
jb,
Would you mind explaining exactly what you are trying to do?
I see that outside the loop you are setting up by getting from the user the starting number, the increment value, the prefix and suffix.
Then in the loop the user selects an existing text object. This is where I lost track of what you want.

I assume the existing text will never have the Prefix &/or Suffix.
You want to Increment the existing text & add the prefix & suffix OR ignore what is in the text and replace it with your values?

Valued Contributor
poorestchump
Posts: 79
Registered: ‎01-18-2005
Message 10 of 19 (294 Views)

Re: (entdel (entlast))

12-03-2009 04:27 AM in reply to: poorestchump
Why do you assume the existing text will never have the Prefix &/or Suffix (before beginning the routine?), because there's no error checking? I don't understand why you would ask such a question.
This routine is to sequentially number/alphabetize tag#'s & addresses in dynamic blocks. I didn't mention that? Maybe you're too advanced for this routine. I use Autolisp, not Vlisp... and not very well, obviously.
jb
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!