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

(entdel (entlast))

18 REPLIES 18
Reply
Message 1 of 19
poorestchump
1108 Views, 18 Replies

(entdel (entlast))

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
18 REPLIES 18
Message 2 of 19
Kent1Cooper
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, AIA
Message 3 of 19
poorestchump
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
Message 4 of 19
cab2k
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
Message 5 of 19
poorestchump
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
Message 6 of 19
Kent1Cooper
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, AIA
Message 7 of 19
poorestchump
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
Message 8 of 19
poorestchump
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
Message 9 of 19
cab2k
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?

Message 10 of 19
poorestchump
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
Message 11 of 19
Kent1Cooper
in reply to: poorestchump

Without studying it too deeply, I suspect the problem may be in the location of

(SETQ ALPH T)

in the ANIT function. Would I be correct in assuming that you would only want that set if you're using letters? I think maybe you want that to be part of the 'else' argument to the (if) function, and not *after* the (if) function is over, where it gets set every time, regardless of which style labels you're using. That would make later code convert text back and forth every time. If I'm correct, try it this way:

{code}
(defun ANIT (); for Alpha-Numeric Integer Toggle
(setq NUMBER
(if (zerop (atoi NUMBER)); if alphabetic
(itoa (- (ascii (strcase NUMBER)) 64))
; then - change to number
(progn ; else
(chr (+ (atoi NUMBER) 64)); change to letter
(SETQ ALPH T); and set marker
); end progn
); end if
); end setq
); end defun
{code}

Or, if I've misunderstood, maybe that setting needs to be grouped with the 'then' argument, changing to a number, instead:

{code}
(defun ANIT (); for Alpha-Numeric Integer Toggle
(setq NUMBER
(if (zerop (atoi NUMBER)); if alphabetic
(progn ; then - change to number
(itoa (- (ascii (strcase NUMBER)) 64))
(SETQ ALPH T); and set marker
); end progn
(chr (+ (atoi NUMBER) 64))
; else - change to letter
); end if
); end setq
); end defun
{code}

--
Kent Cooper
Kent Cooper, AIA
Message 12 of 19
cab2k
in reply to: poorestchump

{quote}Why do you assume the existing text will never have the Prefix &/or Suffix {quote}
Because you have made no provisions to detect the Prefix of Suffix.

Programing is easy if you have strict rules to follow. Conversely the difficulty rises as the rules get looser.
An example would be selecting text/attribute & detecting the Prefix & Suffix.
Rigid Rules:
The Prefix has n number of characters, this way we can always detect the Prefix.
The Prefix is defined in a list, this way we can always detect the Prefix from the list.

Ambiguous Rules:
The Prefix may or may not be present, therefore you must code a detection routine.
The Prefix may be any length & any characters, no way to detect the Prefix unless you can identify the Middle part of the string.

Can you lay down some Rules for your String Data?

My example would look like this:


Prefix is in a list OR the Prefix is n characters long.
OR the user must enter the exact Prefix. This is risky to rely on the user. 🙂


The Middle section of the string is always 3 characters long.

Suffix is in a list OR the Suffix is n characters long.


What are your Rules?


Another aspect of programing is the outline of events or pseudo code.
This helps define the items needed & the flow of the routine. Edited by: CAB2k on Dec 3, 2009 10:52 AM
Message 13 of 19
poorestchump
in reply to: poorestchump

Admittedly the location of prefix/suffix id may be wrong within the routine but there are no limitations to speak of (except perhaps autolisp limitations). I don't understand detect. I understand define which is done in the routine. The routine doesn't need to "detect" anything within the block that reads "prefix" or "suffix" or anything else. It creates (the user creates) the prefix or suffix, neither of which are required, just an option.

I get the impression that you think these are "tags?" that need to be identified in order for this to work. This doesn't seem to be the problem, or maybe I just don't understand what you're trying to convey.
jb
Message 14 of 19
poorestchump
in reply to: poorestchump

Kent1,
When putting in code at the command line, ("a" is the "number" I'm using - and I believe the "number" has no relevance) the "number" returns "-16). When using an actual integer, it returns T. I moved the increment, prefix & suffix setq's when I realized what was happening when the call had no "inc"... other than that, I tried your "anit" routine as a separate function to call from the command line and that's what I got. Any ideas?
Am I missing something in Cab's remarks?
Thanks,
jb
Message 15 of 19
cab2k
in reply to: poorestchump

So now we get to the pseudo code.
User enters Prefix, Suffix, Starting Number or Character & Increment Value.
Begin LOOP
User selects attribute & NEW string is used to replace the existing string.
Increment is applied to the New String to get the next string to use.

Options for user to enter a New value, New Increment or Exit.
End of LOOP


What is supposed to happen if the User Selects the wrong attribute?
You could allow only specified Tag Names
You could provide an Undo option

Rules for Middle string:
Will always be 3 characters
Will be padded with Zeros
May be numeric or Alpha but will use zeros as pad characters
If alpha, allow lower case?

Rules for Increment Value:
Do not allow Zero
Do not allow negative numbers
Max value 9

Rules for Prefix & Suffix:
May be none ""
Allow any length
Allow any valid Alpha numeric characters

Characters Disallowed in Symbol Table Names
less-than and greater-than symbol
/ \ forward slash and backslash
" quotation mark
: colon
? question mark
* asterisk
| vertical bar
, comma
= equal sign
` backquote
; Semi-colon (ASCII 59)
Message 16 of 19
poorestchump
in reply to: poorestchump

Cab,
Rule #1: make the routine work how it's supposed to.
Rule #2: worry about user errors later.
Rule #3: test, test, test
Rule #4: add more error checks when necessary... rinse & repeat.
The End.
Message 17 of 19
poorestchump
in reply to: poorestchump

Apparently I did something to make the numeric numbers add up right but the alpha numbers are still a problem (staying numeric).
Huh?
jb
Message 18 of 19
Kent1Cooper
in reply to: poorestchump

The (anit) function was designed to replace your original (alpha) and (numer) functions. Those only accounted for integers from 1 to 26 and letters from A to Z, so I figured it wouldn't need to handle other things [see the last paragraph in my first post].

I used (atoi) as the test for which kind of substitution to make, because it returns 0 if the text string you give it is [or starts with] a letter. But it also returns 0 if the text string is "0" or starts with zero(es) and doesn't have other numerical characters, neither of which were possibilities in the original picture. And (anit) applied to "0", or "00E" or whatever, because of what (atoi) returns, thinks it's being given a letter. So it gets the ASCII code for the character [or the first one if there's more than one], and for 0, that's 48. It dutifully subtracts 64 from that, as it would from the ASCII code for any capital letter, turns the result back into text, and thus returns "-16".

It returns "T" if used on "20" -- is that [a text-string "T"] what you mean rather than T [without quotation marks, for True]? And that's only if the "20" is a text string, not a true *integer* 20 -- using it on a real integer returns an error message.

I suspect you need to do something to assure that the numerical value isn't zero, or that any letter-designator that's been padded with leading zeros has them removed first, before you apply (anit) to it. Or, you need the test in (anit) to be a lot more sophisticated, but I'd want to know the "rules" CAB2k is asking about, before trying to figure out how to adjust it.

--
Kent Cooper


jerryb wrote...
....the "number" returns "-16). When using an actual integer, it returns T. .... I tried your "anit" routine as a separate function to call from the command line and that's what I got. ....
Kent Cooper, AIA
Message 19 of 19
poorestchump
in reply to: poorestchump

There's one I just figured out all by myself... Yay!!! Now to fool the routine into thinking I know what I'm doing and turn a 0 into a fictitious letter besides "@" or...
Thanks Kent,
jb

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

Post to forums  

Autodesk Design & Make Report

”Boost