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

Lisp to name current layout tab from attributes and then some

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
swankster
1322 Views, 7 Replies

Lisp to name current layout tab from attributes and then some

I am looking for a lisp that when executed, would rename the current layout tab to "DRAWINGNAME Rev REVISIONNUMBER" where DRAWINGNAME & REVISIONNUMBER are attributes pulled from the standard titleblock and Rev is just text.

 

Anybody seen anything that may work or have some partial code I may be able to combine to get what I'm looking for?

7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: swankster


@swankster wrote:

I am looking for a lisp that when executed, would rename the current layout tab to "DRAWINGNAME Rev REVISIONNUMBER" where DRAWINGNAME & REVISIONNUMBER are attributes pulled from the standard titleblock and Rev is just text.

 

Anybody seen anything that may work or have some partial code I may be able to combine to get what I'm looking for?


As a "demo",

change the "standard titleblock name" to the corret name

 

(defun c:demo ( / a aclyt attlst b hnd ss)
  (setq	aclyt (vla-get-activelayout
		(vla-get-activedocument (vlax-get-acad-object))
	      )
  )
  (if (and (/= "Model" (vla-get-Name aclyt))
	   (setq ss (ssget "_X"
			   (list '(0 . "INSERT") )
				 '(2 . "standard titleblock name");; change it to the corret name
				 '(66 . 1)
				 (cons 410 (getvar 'CTAB))
			   )
		    )
	   )
      )
    (progn
      (setq hnd	   (ssname ss 0)
	    obj	   (vlax-ename->vla-object hnd)
	    attlst (vlax-invoke obj 'GetAttributes)
      )
      (foreach att attlst
	(cond ((= (vla-get-TagString att) "DRAWINGNAME")
	       (setq a (vla-get-TextString att))
	      )
	      ((= (vla-get-TagString att) "REVISIONNUMBER")
	       (setq b (vla-get-TextString att))
	      )
	)
	(if (and a
		 b
	    )
	  (vla-put-name aclyt (strcat a " Rev " b))
	)
      )
    )
  )
  (princ)
)

 

hope that helps

Henrique

EESignature

Message 3 of 8
swankster
in reply to: hmsilva

Thanks, getting an issue though:

 

too few arguments: (IF (AND (/= "Model" (vla-get-Name ACLYT)) (SETQ SS (SSGET "_X" (LIST (QUOTE (0 . "INSERT"))) (QUOTE (2 .

 

I tried messing with it but I am a total noob with lisp. I imagine the "model" thing is some kind of fail-safe if the command is used inside modelspace...

Message 4 of 8
hmsilva
in reply to: swankster


swankster wrote:

 I imagine the "model" thing is some kind of fail-safe if the command is used inside modelspace...


Yes, it is.

 

Change only the '(2 . "standard titleblock name") to your titleblock name, and add

 

(defun c:demo ( / a aclyt attlst b hnd ss)
  (vl-load-com)
  (setq aclyt (vla-get-activelayout

 

Or post your full code...

 

Henrique

EESignature

Message 5 of 8
swankster
in reply to: hmsilva

 Something still isn't right. I have updated the lisp with the correct info as shown.

 

(defun c:demo ( / a aclyt attlst b hnd ss)
  (setq	aclyt (vla-get-activelayout
		(vla-get-activedocument (vlax-get-acad-object))
	      )
  )
  (if (and (/= "Model" (vla-get-Name aclyt))
	   (setq ss (ssget "_X"
			   (list '(0 . "INSERT") )
				 '(2 . "dwg info and location for wind xref border");; change it to the corret name
				 '(66 . 1)
				 (cons 410 (getvar 'CTAB))
			   )
		    )
	   )
      )
    (progn
      (setq hnd	   (ssname ss 0)
	    obj	   (vlax-ename->vla-object hnd)
	    attlst (vlax-invoke obj 'GetAttributes)
      )
      (foreach att attlst
	(cond ((= (vla-get-TagString att) "DWGNAME")
	       (setq a (vla-get-TextString att))
	      )
	      ((= (vla-get-TagString att) "REVNO.")
	       (setq b (vla-get-TextString att))
	      )
	)
	(if (and a
		 b
	    )
	  (vla-put-name aclyt (strcat a " Rev " b))
	)
      )
    )
  )
  (princ)
)

 was getting that same error while loading the lisp but then started getting a syntax error.

Message 6 of 8
hmsilva
in reply to: swankster

Sorry, my bad....

Had an extra bracket...

 

(defun c:demo (/ a aclyt attlst b hnd obj ss)
  (vl-load-com)
  (setq	aclyt (vla-get-activelayout
		(vla-get-activedocument (vlax-get-acad-object))
	      )
  )
  (if (and (/= "Model" (vla-get-Name aclyt))
	   (setq ss (ssget "_X"
			   (list '(0 . "INSERT")
				 '(2 . "dwg info and location for wind xref border")
				 '(66 . 1)
				 (cons 410 (getvar 'CTAB))
			   )
		    )
	   )
      )
    (progn
      (setq hnd	   (ssname ss 0)
	    obj	   (vlax-ename->vla-object hnd)
	    attlst (vlax-invoke obj 'GetAttributes)
      )
      (foreach att attlst
	(cond ((= (vla-get-TagString att) "DWGNAME")
	       (setq a (vla-get-TextString att))
	      )
	      ((= (vla-get-TagString att) "REVNO.");; the TAG have a dot?
	       (setq b (vla-get-TextString att))
	      )
	)
	(if (and a
		 b
	    )
	  (vla-put-name aclyt (strcat a " Rev " b))
	)
      )
    )
  )
  (princ)
)

 

EDIT: the above code has been fixed and should work as expected.

 

Henrique

 

EESignature

Message 7 of 8
swankster
in reply to: hmsilva

Very nice man, very nice. Thank you very much!

Message 8 of 8
hmsilva
in reply to: swankster

You're welcome, swankster
Glad I could help

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost