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

HELP- text label ascending

31 REPLIES 31
SOLVED
Reply
Message 1 of 32
ScottMason
4562 Views, 31 Replies

HELP- text label ascending

I need help editing a basic lisp i have found. I really like this for labelling parts in my drawings because it is just set up click and go, but when i have multiples i have to go back and copy the "tag" that i add for another panel for all multiples. I would really like to be able to "Shift+click" and have the lisp continue with the current number, and when i release shift, go back to ascending numbers until shift is held again. Is this possible? Thank you anyone.

Scott

 

;;; TX+INTEGERS+TX
(defun c:TAG (/ p n ni pref suff nns ntx ntxx oecho osn ds th txt)

  (setq	oecho (getvar "cmdecho")
	osn   (getvar "osmode")
  )
  (if (= 0 (getvar "dimscale"))(setq ds 1.0)(setq ds (getvar "dimscale")))
  (setq th (getvar "dimtxt"))
  (setq txt (* th ds))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)
  (if nn
    (setq nn (fix nn))
    (setq nn 1)
  )
  (if (= nn 0)(setq nn 1))
  (princ "\n Increment numbers by < ")
  (princ nn)
  (princ " >? : ")
  (setq ni (getint))
  (if (= ni nil)
    (setq ni nn)
    (setq nn ni)
  )

  (if np
    (setq np (fix np))
    (setq np nn)
  )
  (princ "\n Start or continue with number < ")
  (princ np)
  (princ " >? : ")
  (setq n (getint))
  (if (= n nil)
    (setq n np)
    (setq np n)
  )
  (setq nns (itoa n))

  (princ "\n Prefix text < ")
  (princ pre)
  (princ " >? or <.> for none: ")
  (setq pref (getstring t))
  (if (= pref ".")
    (progn
      (setq pre nil)
      (setq pref nil)
    )
    (progn
      (if (= pref "")
	(setq pref pre)
	(setq pre pref)
      )
      (if pref
	  (setq ntx (strcat pref nns))
      )
    )
  )

  (princ "\n Suffix text < ")
  (princ suf)
  (princ " >? or <.> for none: ")
  (setq suff (getstring t))
  (if (= suff ".")
    (progn
      (setq suf nil)
      (setq suff nil)
    )
    (progn
      (if (= suff "")
	(setq suff suf)
	(setq suf suff)
      )
      (if suff
	(if pref
	  (setq ntxx (strcat pref nns suff))
	  (setq ntxx (strcat nns suff))
	)
      )
    )
  )
  (setq p (getpoint "\n Insert: "))
  (setq oecho (getvar "cmdecho"))

  (while p
    (if	suff
      ;(command "text" "j" "mc" p "" "" ntxx)
      (entmake (list (cons 0 "TEXT")
		     (cons 10 p)
		     (cons 11 p)
		     (cons 1 ntxx)	; actual text
		     (cons 7 (getvar "TEXTSTYLE"))
		     (cons 40 txt)
		     (cons 72 4)
	       )
      )
      (if pref
	;(command "text" "j" "mc" p "" "" ntx)
	(entmake (list (cons 0 "TEXT")	
		    (cons 10 p)	
		    (cons 11 p)	
		    (cons 1 ntx); actual text
		    (cons 7 (getvar "TEXTSTYLE"))
		    (cons 40 txt)
		    (cons 72 4)
	      )
     )
	;(command "text" "j" "mc" p "" "" n)
	(entmake (list (cons 0 "TEXT")	
		    (cons 10 p)	
		    (cons 11 p)	
		    (cons 1 n); actual text
		    (cons 7 (getvar "TEXTSTYLE"))
		    (cons 40 txt)
		    (cons 72 4)
	      )
     )
      )
    )
    (setq p   (getpoint "\n Next number location: ")
	  n   (+ ni n)
	  nns (itoa n)
	  np n
    )
    
    (if	suff
      (if pref
	(setq ntxx (strcat pref nns suff))
	(setq ntxx (strcat nns suff))
      )
    )
    (if	pref
      (if suff
	(setq ntxx (strcat pref nns suff))
	(setq ntx (strcat pref nns))
      )
    )
  )
  (setvar "cmdecho" oecho)
  (setvar "osmode" 63)
  (princ)
)

(princ "\n Type > TAG <  to insert text with ascending integers.")


;;;*********************************************************

 

31 REPLIES 31
Message 2 of 32
Gary_J_Orr
in reply to: ScottMason

not exactly what you asked for, but close... (and I'm going to leave out any discussion about optimizing the code, I'm just addressing the specific question that you asked):

 

An easy approach is to add in a new variable for autoincrement as a toggle that can be introduced when you are selecting consecutive points. Doing this will mean having to hit enter twice to exit the command (instead of just once as it is now) but it is an approach that gets close to your request without much reworking.

 

At the beginning of the routine (where you are setting your initial variables) add this new one:

(setq AutoInc 1)

 

then, where you ask for additional points replace this:

    (setq p   (getpoint "\n Next number location: ")
	  n   (+ ni n)
	  nns (itoa n)
	  np n
    )

 

with this:

    (setq TestP (getpoint "\n Next number location \(hit \<enter\> to stop\/restart number incrementing\): "))
    (if (not TestP)
      (setq AutoInc 	(* -1 AutoInc)
	    p 		(getpoint "\n Next number location: ")
	    );setq
      (setq p TestP)
      );if test point
    (if (> AutoInc 0)
      (setq n   (+ ni n)
	    nns (itoa n)
	    np n
	    );setq
      );if Autoswitch

 again, not exactly what you asked for, but a possible (easy) workable solution

-Gary

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 3 of 32
Kent1Cooper
in reply to: ScottMason

Another not-quite-exactly approach would be to offer an option such as typing an R, for Repeating the previous number.  It would involve using (initget) to allow R to be entered at a (getpoint) prompt, and if it is, not incrementing the number, or maybe stepping the number back one and then having it incremented upward [to what it was last time] as usual, before making the Text.  It would be one more keystroke to hit R and Enter/space than it would to hit just Enter as in the other suggestion, but when you're done, one Enter would end the routine, and if you're a right-hand-mouse person, R-space with the left hand could well be faster than Enter, whether the latter is done by moving your left hand across or by taking your right hand off the mouse to hit it.  Does that sound worth pursuing?

Kent Cooper, AIA
Message 4 of 32
pbejse
in reply to: ScottMason

A simple demo for you using initget

 

(Defun c:demo ( / addmode p n )
;;;	pBe May2014			;;;
;;	Demonstrationj purposes only	;;;
(setq addmode 1)  
(setq n (getint "\nEnter Start Number: ")
      n (1- n))
  
	(while (progn
		(initget "T")
		 (setq p (getpoint "\n Insert <Press \"T\" for change mode>: ")))
	  		(if (listp p)
				(progn
				  (setq n (+ n (if (zerop addmode) 0 1)))
				  	(entmake
					  (list (cons 0 "TEXT")
					    (cons 10 p) (cons 11 p)
					    (cons 1 (itoa n)) 	; actual text
					    (cons 7 (getvar "TEXTSTYLE"))
					    (cons 40 1.0)
					    (cons 72 4)
					  )
					)
				  )
			  (setq addmode (boole 6 1 addmode))
			      )
	  )
  (princ)
  )
	

 

Command: Demo

 Insert <Press "T" for change mode>: <<user pick a point>>  place the text with string equivalent of number

 Insert <Press "T" for change mode>: <<user press T>> then press enter, operation switches to static mode

 Insert <Press "T" for change mode>: <<user pick a point>>  place the text with string equivalent of number

 Insert <Press "T" for change mode>: <<user press T>>  then press enter, operation switches add mode

 Insert <Press "T" for change mode>: <<user pick a point>>  place the text with string equivalent of number

 Insert <Press "T" for change mode>: <<user press Enter>> program terminated

 

Again **For Demonstraton purposes Only***

Have not had the time to write a complete coding

 

pBe

 

EDIT: Kent beat me to it... Smiley Happy anyhoo, it demonstrates what we meant by using initget

 

HTH

Message 5 of 32
Gary_J_Orr
in reply to: Kent1Cooper

actually Kent... in the suggestion that I posted, and given the settings that I run... enter is provided via a right-click... my hand would never have to touch the keyboard after the process starts... 😉

 

Of course, the spacebar acts as enter as well with my settings so it is left/right hand neutral to hit "enter" if the keyboard is desired...

 

I'm a great fan of "ease of use" and initget, especially with a call for a given letter or other specific key, would actually require that you hit that specific key, and if you miss then you have to do it again. Of course you can set a flag to allow arbitrary input which would allow any keystroke (and ot enter) and eventually achieve the goal... there are many ways to approach such and it all comes down to what is easier for the end user.

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 6 of 32
pbejse
in reply to: Gary_J_Orr


@Anonymous wrote:

 

...I'm a great fan of "ease of use"..


In that case, we can use grread in conjunction with the Express Tools function (acet-sys-shift-down).

 

This next demo utilize that function to remain in static mode while the shfit button is pressed.

 

(Defun c:demo2 ( / pressed p n )
;;;	pBe May2014			;;;
;;	Demonstrationj purposes only	;;;
(setq n (getint "\nEnter Start Number: ")
      n (1- n))
(while (null Stop)	
	(princ "\nNext point: <Press Shift for Static mode")(princ)
  	
	(setq Op (grread))(setq pressed (acet-sys-shift-down))
        (cond
              ((= (car Op) 3)(setq pt (trans (cadr op) 1 0)))
              ((= (cadr Op) 32)(setq Stop T))
              )
  	(setq n (+ n (if pressed 0 1)))
		  	(entmake
			  (list (cons 0 "TEXT")
			    (cons 10 pt) (cons 11 pt)
			    (cons 1 (itoa n)) 	; actual text
			    (cons 7 (getvar "TEXTSTYLE"))
			    (cons 40 1.0)
			    (cons 72 4)
			  )
			)
      )(princ)
  )

 

command: demo2

 

HTH

Message 7 of 32
ScottMason
in reply to: pbejse

the demo2 seems to work ok, but my crosshairs dont seem to change to the "command running" visual type of crosshairs, also i would need a way to input a prefix to the numerals, our numbering system is an alphanumeric (i.e. BC-72) where BC- would be entered in as the text prefix and the integer of 72 or whatever number would be the integer to change with each click. I dont mind a rewrite of the code for ease of use but i did like the fact that the code would recognize the current dimscale/text style but that could be achieved in other ways. (clicking on a previously generated "tag" at the initilization of the command or something similar) 

Thank you guys for the help

 

Message 8 of 32
Gary_J_Orr
in reply to: pbejse


@pbejse wrote:

@Anonymous wrote:

 

...I'm a great fan of "ease of use"..


In that case, we can use grread in conjunction with the Express Tools function (acet-sys-shift-down).

 

 

HTH


I've never heard of that ET function...

Given that, and without completely rewriting the OP's original code (which could use a bit of reworking, but one issue at a time...) in the original code replacing:

    (setq p   (getpoint "\n Next number location: ")
	  n   (+ ni n)
	  nns (itoa n)
	  np n
    )

 with:

    (setq p (getpoint "\n Next number location: "))
    (if (not (acet-sys-shift-down))
      (setq n (+ ni n))
      )
    (setq nns (itoa n))
    (setq np  n)
    

 would give the OP exactly what was asked for... pressing the shift key when picking the point will keep the previous number, releasing it will continue with the auto incrementing... first problem solved.

 

-G

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 9 of 32
ScottMason
in reply to: Gary_J_Orr

Hey Gary, that change worked great. But as the OP I am not the author of the original code. I went to the author and he did not know how to achieve this result so I brought it here. I do not have any problems with your suggestions of optimization of the code. I am open to suggestions now that the primary goal has been met. 

Message 10 of 32
Gary_J_Orr
in reply to: ScottMason

Thanks, but I can't take any real credit for it... it was pbejse that supplied the functionality (which I was previously unaware of) that truly solved your problem.
As to the reworking that it needs... I noticed issues with suffix/prefix combinations when testing it do to it's structure. I'll post a "next step" cleanup version that here in a few, complete with one that includes comments as to what is changed where, and why for you and the original author to review if you would like to see the "evolution"

Quick question: would you like a "number padding" option (ie 1 could become 01, 001, or 0001, etc)
-Gary.
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 11 of 32
Kent1Cooper
in reply to: ScottMason


@Anonymous wrote:

.... I really like this for labelling parts in my drawings ..., but when i have multiples i have to go back and copy the "tag" that i add for another panel for all multiples. I would really like to be able to "Shift+click" and have the lisp continue with the current number, and when i release shift, go back to ascending numbers until shift is held again. .... 


I had gotten fairly far along in developing the attached TagIncrement.lsp with its version of a TAG command, before the Shift-to-not-increment solution came along [I wasn't aware of that possibility either], so I've taken it to a point, and thought I'd post it for the other aspects of it.  That Shift-key aspect could probably be incorporated into it, and I'll try that out soon.  Currently, it uses R as an option for Repeating the integer part of the tag, as in my earlier suggestion.

 

It does a variety of things in different ways from the OP's original, including:

1.  using one sub-routine to get the text content for both the Prefix and the Suffix;

2.  handling the offering of defaults differently;

3.  using empty strings for the Prefix/Suffix if they are not wanted, rather than nil, so that it can simply string them together regardless, in one (entmake) operation, rather than building the text content in multiple different ways depending on whether there is a Prefix and/or a Suffix.

 

It also omits dealing with CMDECHO and OSMODE, which are not needed when the Text is made using (entmake) rather than (command).

 

And a little juicy enhancement -- it shows you in the location-point prompt what it's going to use for the Text you put there.

 

EDIT:  A question -- Would there ever be a need to increment downward?  That is, should a negative increment value be allowed?

 

I also have in mind to re-structure it so that it reports the settings when you call it up, and goes right to asking for points or options to change any of the settings individually, so you don't have to step through accepting most defaults, and so that you can change any of them on the fly.

Kent Cooper, AIA
Message 12 of 32
ScottMason
in reply to: Gary_J_Orr

Thank you, i have also given credit to him as a solution. Number padding would be good for -01 through -09 but not really needed otherwise. Also i dont have much of a need for a suffix either. Thank you, 

Scott

Message 13 of 32
Gary_J_Orr
in reply to: ScottMason

Scott (and your original author if he/she is interested)... as a "learning tool" I did a bit of tweaking (not a complete rebuild, although if interested we can continue step by step until you have a better understanding of how to get from point A to point B as well as a solution that you can easily understand and perhaps be able to further modify as time goes on).

 

So, you have the first installment, the shift-key option... next, we'll address the actual "heavy lifting" portion of the code. Here is your original code with the areas that could be vastly improved for functionality commented out with the replacements included (I hope that I can get this "spoiler" thing to work properly with embedded code... this is my first stab at using it):

 

Spoiler
(defun c:TAG (/ p n ni pref suff nns ntx ntxx oecho osn ds th txt)
  (setq	oecho (getvar "cmdecho")
	osn   (getvar "osmode")
  )
  (if (= 0 (getvar "dimscale"))(setq ds 1.0)(setq ds (getvar "dimscale")))
  (setq th (getvar "dimtxt"))
  (setq txt (* th ds))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)
  
  (if nn
    (setq nn (fix nn))
    (setq nn 1)
  )
  (if (= nn 0)(setq nn 1))
  (princ "\n Increment numbers by < ")
  (princ nn)
  (princ " >? : ")
  (setq ni (getint))
  (if (= ni nil)
    (setq ni nn)
    (setq nn ni)
  )

  (if np
    (setq np (fix np))
    (setq np nn)
  )
  (princ "\n Start or continue with number < ")
  (princ np)
  (princ " >? : ")
  (setq n (getint))
  (if (= n nil)
    (setq n np)
    (setq np n)
  )
  ;this can be done "on the fly" so no variable is needed.
;;;  (setq nns (itoa n))

  (princ "\n Prefix text < ")
  (princ pre)
  (princ " >? or <.> for none: ")
  (setq pref (getstring t))
  (if (= pref ".")
    (progn
      (setq pre nil)
      (setq pref nil)
    )
    (progn
      (if (= pref "")
	(setq pref pre)
	(setq pre pref)
      )
      ;this can be done "on the fly" so no variable is needed.
;;;      (if pref
;;;	  (setq ntx (strcat pref nns))
;;;      )
    )
  )

  (princ "\n Suffix text < ")
  (princ suf)
  (princ " >? or <.> for none: ")
  (setq suff (getstring t))
  (if (= suff ".")
    (progn
      (setq suf nil)
      (setq suff nil)
    )
    (progn
      (if (= suff "")
	(setq suff suf)
	(setq suf suff)
      )
      ;this can be done "on the fly" so no variable is needed.
;;;      (if suff
;;;	(if pref
;;;	  (setq ntxx (strcat pref nns suff))
;;;	  (setq ntxx (strcat nns suff))
;;;	)
;;;      )
    )
  )
  
  (setq p (getpoint "\n Insert: "))
  ;here you are changing your stored echo variable to the newly set value
  ;so why store it in the first place if you're overwriting it?
;;;  (setq oecho (getvar "cmdecho"))

  (while p
    ;there is no need to create 3 seperate variables
    ;for the string combinations and then build the text entity
    ;based on which value exists
;;;    (if	suff
;;;      ;(command "text" "j" "mc" p "" "" ntxx)
;;;      (entmake (list (cons 0 "TEXT")
;;;		     (cons 10 p)
;;;		     (cons 11 p)
;;;		     (cons 1 ntxx)	; actual text
;;;		     (cons 7 (getvar "TEXTSTYLE"))
;;;		     (cons 40 txt)
;;;		     (cons 72 4)
;;;	       )
;;;      )
;;;      (if pref
;;;	;(command "text" "j" "mc" p "" "" ntx)
;;;	(entmake (list (cons 0 "TEXT")	
;;;		    (cons 10 p)	
;;;		    (cons 11 p)	
;;;		    (cons 1 ntx); actual text
;;;		    (cons 7 (getvar "TEXTSTYLE"))
;;;		    (cons 40 txt)
;;;		    (cons 72 4)
;;;	      )
;;;     )
;;;	;(command "text" "j" "mc" p "" "" n)
;;;	(entmake (list (cons 0 "TEXT")	
;;;		    (cons 10 p)	
;;;		    (cons 11 p)	
;;;		    (cons 1 n); actual text
;;;		    (cons 7 (getvar "TEXTSTYLE"))
;;;		    (cons 40 txt)
;;;		    (cons 72 4)
;;;	      )
;;;     )
;;;      )
;;;    )
    
    ;when you can build the string on the fly
    ;and use a condition stmt to cover the prefix/suffix options
    (setq String
	   (cond
	     ;if prefix and suffix:
	     ((and pref suff) (strcat pref (itoa n) suff))
	     ;if prefix only:
	     (pref (strcat pref (itoa n)))
	     ;if suffix only:
	     (suff (strcat (itoa n) suff))
	     ;if neither prefix nor suffix:
	     (T (itoa n))
	     );cond
	  );setq
    (entmake (list (cons 0 "TEXT")
		   (cons 10 p)
		   (cons 11 p)
		   (cons 1 String)	; actual text
		   (cons 7 (getvar "TEXTSTYLE"))
		   (cons 40 txt)
		   (cons 72 4)
		   )
	     );entmake
    

    (setq p (getpoint "\n Next number location: "))
    (if (not (acet-sys-shift-down))
      (setq n (+ ni n))
      )
    ;we no longer need this variable here
;;;    (setq nns (itoa n))
    ;we only need to save this variable once at the end of the routine
;;;    (setq np  n)

    ;since we are now building our string on the fly using cond stmts
    ;we no longer need to keep repeating this for the other method
;;;    (if	suff
;;;      (if pref
;;;	(setq ntxx (strcat pref nns suff))
;;;	(setq ntxx (strcat nns suff))
;;;      )
;;;    )
;;;    (if	pref
;;;      (if suff
;;;	(setq ntxx (strcat pref nns suff))
;;;	(setq ntx (strcat pref nns))
;;;      )
;;;    )
  )
  ;save our last number for next run
  (setq np  n)
  ;reset our stored variables
  (setvar "cmdecho" oecho)
  (setvar "osmode" 63)
  (princ)
)

 

 

 

Here is the function after the modifications [Edit and with the "PadTo" option thrown in for good measure]:

 

Spoiler
(defun c:TAG (/ p n ni pref suff nns PadTo string oecho osn ds th txt)
  ;set variables
  (setq	oecho (getvar "cmdecho")
	osn   (getvar "osmode")
  )
  (if (= 0 (getvar "dimscale"))(setq ds 1.0)(setq ds (getvar "dimscale")))
  (setq th (getvar "dimtxt"))
  (setq txt (* th ds))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)

  ;get the increment value
  (if nn
    (setq nn (fix nn))
    (setq nn 1)
  )
  (if (= nn 0) (setq nn 1))
  (princ "\n Increment numbers by < ")
  (princ nn)
  (princ " >? : ")
  (setq ni (getint))
  (if (= ni nil)
    (setq ni nn)
    (setq nn ni)
  )

  ;get the starting number
  (if np
    (setq np (fix np))
    (setq np nn)
  )
  (princ "\n Start or continue with number < ")
  (princ np)
  (princ " >? : ")
  (setq n (getint))
  (if (= n nil)
    (setq n np)
    (setq np n)
  )

  ;option for number padding
  (if Tag_Save_Pad
    (setq Tag_Save_Pad (fix Tag_Save_Pad))
  )
  (princ "\n Pad Number to < ")
  (princ Tag_Save_Pad)
  (princ " >? 1 or less for no padding: ")
  (setq PadTo (getint))
  (if (= PadTo nil)
    (setq PadTo Tag_Save_Pad);keep previous val: if it's nil, keep it nil
    (if (< PadTo 2)
      (progn
	(setq PadTo nil)
	(setq Tag_Save_Pad nil)
	)
      (setq Tag_Save_Pad PadTo)
      );if padding is irrelevant
  );if PadTo

  ;option for prefix
  (princ "\n Prefix text < ")
  (princ pre)
  (princ " >? or <.> for none: ")
  (setq pref (getstring t))
  (if (= pref ".")
    (progn
      (setq pre nil)
      (setq pref nil)
    )
    (if (= pref "")
      (setq pref pre)
      (setq pre pref)
      )
  )
  
  ;option for Suffix
  (princ "\n Suffix text < ")
  (princ suf)
  (princ " >? or <.> for none: ")
  (setq suff (getstring t))
  (if (= suff ".")
    (progn
      (setq suf nil)
      (setq suff nil)
    )
    (progn
      (if (= suff "")
	(setq suff suf)
	(setq suf suff)
      )
    )
  )

  ;start the work
  (setq p (getpoint "\n Insert: "))
  (while p
    ;convert our number to a string at the beginning of the loop to avoid
    ;having to do it before the loop and again after number incrementing
    (setq nns (itoa n))
    (if PadTo
      (while (< (strlen nns) PadTo)
	(setq nns (strcat "0" nns))
	);While
      );if PadTo
    ;build our string
    (setq String
	   (cond
	     ((and pref suff) (strcat pref nns suff))
	     (pref (strcat pref nns))
	     (suff (strcat nns suff))
	     (T nns)
	     );cond
	  );setq
    ;create the text entity
    (entmake (list (cons 0 "TEXT")
		   (cons 10 p)
		   (cons 11 p)
                   (cons 1 String) ; actual text
   (cons 7 (getvar "TEXTSTYLE"))
(cons 40 txt) (cons 72 4) ) );entmake (setq p (getpoint "\n Next number location: ")) (if (not (acet-sys-shift-down)) (setq n (+ ni n)) );if );while ;save our last number for next run (setq np n) ;reset our stored variables (setvar "cmdecho" oecho) (setvar "osmode" 63) (princ) );defun C:Tag (princ "\n Type > TAG < to insert text with ascending integers.")

 

 

The next step would be to address the storage and collection of stored variables if you wish to continue as a learning exercise.

-Gary

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 14 of 32
Gary_J_Orr
in reply to: Kent1Cooper

A couple of quick comments Kent...
1) Dimscale will be 0 if an annotative dimension style is current so the option should always be considered.
2) while osmode may be irrelevant to the entmake command, it can still cause a problem with getting the point (depending on options and settings) so keeping it in as a general practice for novices doesn't hurt

Just a couple of thoughts for you.

Some cool little tricks in your code though.
-Gary
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 15 of 32
ScottMason
in reply to: Kent1Cooper

KENT, thank you for your contribution. For some reason, I dont know if it is based on my settings, I could not see the "text preview" feature you spoke about. I do prefer the shift down for repeat opposed to inputting "r" for each repeated number, but thank you for taking the time to offer a suggestion. 

Message 16 of 32
Kent1Cooper
in reply to: ScottMason


@Anonymous wrote:

.... I could not see the "text preview" feature you spoke about. .... 


It's not a preview out in the drawing, but is in the prompt where it's asking for a location for the next Tag, showing you what it's going to say.  If you don't see it there, I'd have to think about why that might be -- it doesn't seem possible for it to be because of any settings, but I'll try it when I can on a newer version than I have here.

Kent Cooper, AIA
Message 17 of 32
Kent1Cooper
in reply to: Gary_J_Orr


@Anonymous wrote:
....
2) while osmode may be irrelevant to the entmake command, it can still cause a problem with getting the point (depending on options and settings) so keeping it in as a general practice for novices doesn't hurt
....

I think when I would use something like this, I would sometimes [maybe even as often as not] want Osnap on specifically for getting the point.  So I wouldn't want the routine always turning it off, but would control it for myself, either beforehand [e.g. to set it to Center, which I don't usually have on, to more quickly place Tags centered in Circles or Ellipses] or with F3 [to use the modes I normally have on, or not, as I choose].  But anyone can set it up for their own typical M.O.

Kent Cooper, AIA
Message 18 of 32
Gary_J_Orr
in reply to: Kent1Cooper

All well and true... you and I might, they might even consider doing so once they understand a bit more... but your statement of:
__________________-

It also omits dealing with CMDECHO and OSMODE, which are not needed when the Text is made using (entmake) rather than (command).
__________________

is the reason that I made the comment... telling them that OSMODE doesn't matter because they are using Entmake can be misleading since that has little to do with obtaining the point (and getpoint DOES respect osnap settings...

I wasn't bashing on you, simply pointing out that your comment could very well cause the OP problems if they followed such advice and suddenly had their text jumping around to undesired locations.
-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 19 of 32
Gary_J_Orr
in reply to: Gary_J_Orr

and here you will find an option to your initial collection of variables.

 

when you run the routine it will print your current settings/options to the command line and the first "getpoint" prompt will offer you the option to go in and change any or all of the options prior to picking that first point by hitting Enter (and/or the spacebar and/or right-clicking depending on your settings), but if everything is set as you want it you simply start picking your points to continue where you left off.

 

There are other ways to do this, but they get rather complex and hard to understand (such as possibly including an option to select an existing text tag and continue with whatever number, prefix, and suffix that it has).

 

(defun c:TAG (/ PrintVals oecho osn ds th txt InsPt NumbStr)
  (defun PrintVals ()
    (princ "\nCurrent Values: ")
    (princ "\tPrefix = ") (princ Tag_Pref)
    (princ "\tNumber = ") (princ Tag_Numb)
    (princ "\tIncrement = ") (princ Tag_Incr)
    (princ "\tPadding = ") (princ Tag_PadTo)
    (princ "\tSuffix = ") (princ Tag_Suff)
    (princ "\n")
    )
  
  ;set Acad variables
  (setq	oecho (getvar "cmdecho")
	osn   (getvar "osmode")
	)
  (if (= 0 (getvar "dimscale"))(setq ds 1.0)(setq ds (getvar "dimscale")))
  (setq th (getvar "dimtxt"))
  (setq txt (* th ds))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)

  ;set defaults and/or ensure existence of required variables in the drawing session
  ;since these will be global variables help ensure they are specific to this function 
  ;by adding the function name to them to help ensure that some other function
  ;doesn't use the same variables and set unusable values to them
  (if (not Tag_Numb) (setq Tag_Numb 1))
  (if (not Tag_Incr) (setq Tag_Incr 1))
  
  (PrintVals)
  (while (not (setq InsPt (getpoint "\nPick Insertion point or \<Enter\> to change Current values: ")))
    (setq ModVal T)
    (while ModVal
      (PrintVals)
      (initget "Prefix Number Increment padTo Suffix")
      (setq ModVal (getkword "Value to Change: \[Prefix\/Number\/Increment\/padTo\/Suffix\]"))
      (cond
	((= ModVal "Prefix") (setq Tag_Pref (getstring T "Enter New Prefix Value: \<Enter\> for none: ")))
	((= ModVal "Number")
	 (progn
	   (initget 1)
	   (setq Tag_Numb (getint (strcat "Enter Starting Number: ")))
	   ));Number cond
	((= ModVal "Increment")
	 (progn
	   (initget 3)
	   (setq Tag_Incr (getint (strcat "Enter Increment Value: ")))
	   ));Increment Cond
	((= ModVal "padTo")
	 (progn
	   (setq Tag_PadTo (getint (strcat "Enter desired length of number string: ")))
	   (if Tag_PadTo (if (< Tag_PadTo 2) (setq Tag_PadTo nil)))
	   ));PadTo cond
	((= ModVal "Suffix") (setq Tag_Suff (getstring T "Enter New Suffix Value: \<Enter\> for none: ")))
	);cond stmt
      );while ModVal option
    );while not InsPt

  (while InsPt
    ;convert our number to a string at the beginning of the loop to avoid
    ;having to do it before the loop and again after number incrementing
    (setq NumbStr (itoa Tag_Numb))
    (if Tag_PadTo
      (while (< (strlen NumbStr) Tag_PadTo)
	(setq NumbStr (strcat "0" NumbStr))
	);While
      );if PadTo
    ;build our string
    (setq NumbStr
	   (cond
	     ((and Tag_Pref Tag_Suff) (strcat Tag_Pref NumbStr Tag_Suff))
	     (Tag_Pref (strcat Tag_Pref NumbStr))
	     (Tag_Suff (strcat NumbStr Tag_Suff))
	     (T NumbStr)
	     );cond
	  );setq
    ;create the text entity
    (entmake (list (cons 0 "TEXT")
		   (cons 10 InsPt)
		   (cons 11 InsPt)
		   (cons 1 NumbStr)	; actual text
		   (cons 7 (getvar "TEXTSTYLE"))
		   (cons 40 txt)
		   (cons 72 4)
		   )
	     );entmake
    (setq InsPt (getpoint "\n Next number location: "))
    (if (not (acet-sys-shift-down))
      (setq Tag_Numb (+ Tag_Incr Tag_Numb))
      );if
  );while
  
  ;reset our variables
  (setvar "cmdecho" oecho)
  (setvar "osmode" osn)
  (princ)
);defun C:Tag

(princ "\n Type > TAG <  to insert text with ascending integers.")

 

Happy Lisping

-Gary

 

 

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 20 of 32
ScottMason
in reply to: Gary_J_Orr

the final lisp is working well but it will not reset my "osmode" after the command. i can manually reset it or input the desired value in "osmode" from the command line but when i run the lisp it will then reset it to 0 for the command and not return it to the desired value once the command is exited

i need it to return the values on exit, not necessarily on command completion as this is a "running" command and is run until i need to exit and move on. 

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

Post to forums  

Autodesk Design & Make Report

”Boost