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
4513 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 21 of 32
Gary_J_Orr
in reply to: ScottMason

It's turning my snaps off, then turning them back on on this end (speaking about the "final version" that I posted)...
Try this... just in case some other function is using the same variable to store the osmode variable and not resetting it... change the 3 references to osn (in the original gathering of variables, in the resetting of values, and in the command definition where it clears the variable) to something more complex like OldOSM or some such... save it, reload it, verify your osmode settings, then run it...
does it now change the setting back to what it was before running it?
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 22 of 32
ScottMason
in reply to: Gary_J_Orr

it appears to have worked changing "osn" to "OLDosm, thank you.
Side note- where can i go online to find resources to learn to write lisp code?
Message 23 of 32
Gary_J_Orr
in reply to: ScottMason

Glad it's working for you... hopefully a few less keyboard strokes along the way.
As far as the "...resources to learn..." : I couldn't even begin to tell you, I learned by reading help files, reading DG solutions that were close to what I needed and a lot of... "Just do it and see what happens..."

-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 24 of 32
ScottMason
in reply to: Gary_J_Orr

I was basically wanting a resource to learn the basic structure of coding. i.e. What does "defun" do and mean? What is princ? And things such as that.
Message 25 of 32
pbejse
in reply to: ScottMason


@Anonymous wrote:
I was basically wanting a resource to learn the basic structure of coding. i.e. What does "defun" do and mean? What is princ? And things such as that.

This is where I started ---> AFRALISP 

Message 26 of 32
Kent1Cooper
in reply to: ScottMason


@Anonymous wrote:
I was basically wanting a resource to learn the basic structure of coding. i.e. What does "defun" do and mean? What is princ? And things such as that.

There are many threads here asking for such resources -- do a Search for terms like tutorials, books, websites, references, etc.  And those functions and most others [curiously, not all functions available] are described in Help, with what arguments they take, the returned values, etc.  In newer versions, you can type a function name into Help just as you can a command name; in older versions, there's an AutoLISP Reference that describes them, that you can navigate to through the Help window.

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

update: the routine is working well and helping out. What do i need to add to the code to have it "print" the "string" that it will create when i click, i have tried the little bit that i know but havent gotten it right. Thank you, i would like it to be where it asks for user input for label location.
Message 28 of 32
Gary_J_Orr
in reply to: ScottMason

sorry,

Due to the "post processing" required by the "shift key" option:

(acet-sys-shift-down)

It isn't possible to truly achieve what you want (at least not as far as I could imagine right now).

 

Otherwise it wouldn't be much of a rewrite to include the value in the prompt (or print it to the cmd line)... it would just require repeating the actual string constructor, once before the first point is selected and again at the end of each loop (right now the string constructor exists at the beginning of each loop).

 

But, again, since you won't know what the value will be until AFTER you pick the point (since it depends on determining if the shift key was pressed DURING the point selection) there is no way to have it both ways...

Either you need the extra keystrokes proposed in some of the other responses for the "repeat number" option and enable processing of the string before the pickpoint prompt, or you can have the "shift pick" option without the prompt, but I currently see no way to achieve both.

 

That being said: It wouldn't take too much to "print" what the string would look like before the first point selection, just not repeatedly showing what the next value will look like.

 

-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 29 of 32
ScottMason
in reply to: Gary_J_Orr

alright, i can accept that for the increased functionality of the shift down i can do without the print out.
Message 30 of 32
Gary_J_Orr
in reply to: ScottMason

Well, since you were so nice about it (and I didn't have anything else to do anyway)...

 

Try the attached version...

 

-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 31 of 32
ScottMason
in reply to: Gary_J_Orr

Thank you again sir, this routine works well, as i understand that because of the post processing of the "shift" function it is not possible for the program to "guess" what the next number will be but it does display the number just labeled. this is as close to what i was seeking as can possible with this program. Thank you again for your time you have put into this routine.
Message 32 of 32
Gary_J_Orr
in reply to: ScottMason

Glad I could be of assistance.

Happy Drafting
-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)

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

Post to forums  

Autodesk Design & Make Report

”Boost