Check if layout tab exists before running commands

Check if layout tab exists before running commands

emilio24DRY
Enthusiast Enthusiast
438 Views
5 Replies
Message 1 of 6

Check if layout tab exists before running commands

emilio24DRY
Enthusiast
Enthusiast

I have the following code:

(defun ECR:setTab ( TAB / )
;; !!IMPORTANT!! TAB NAMES ARE CASE SENSITIVE OR ELSE IT DOESN'T WORK
;; CHANGE TABS AND DO ZOOM EXTENTS ON THAT TAB
	(cond
		((member TAB (layoutlist))
			(setvar "ctab" TAB)
			(command "zoom" "extents")
		);LAYOUT EXISTS
		(t
			(princ (strcat "\n-\n" TAB " does not exist to be set (setTab). Note that this function is case sensitive.\n-\n"))
		);ELSE
	);COND
(princ)
)

Do I have to change it to the following code to allow "Model" to pass through it since (member "Model" (layoutlist)) returns nil. Why is this happening? Does layoutlist only check for tabs other than Model?

(defun ECR:setTab2 ( TAB / )
;; !!IMPORTANT!! TAB NAMES ARE CASE SENSITIVE OR ELSE IT DOESN'T WORK
;; CHANGE TABS AND DO ZOOM EXTENTS ON THAT TAB
	(cond
		((or (member TAB (layoutlist)) (eq TAB "Model"))
			(setvar "ctab" TAB)
			(command "zoom" "extents")
		);LAYOUT EXISTS
		(t
			(princ (strcat "\n-\n" TAB " does not exist to be set (setTab). Note that this function is case sensitive.\n-\n"))
		);ELSE
	);COND
(princ)
)

or is there another way that allows "Model" to pass through?

 

Thanks!

0 Likes
Accepted solutions (1)
439 Views
5 Replies
Replies (5)
Message 2 of 6

marko_ribar
Advisor
Advisor

Practically you answered your question yourself... Now mark your answer as a solution...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@emilio24DRY wrote:

....

Do I have to change it to the following code to allow "Model" to pass through it since (member "Model" (layoutlist)) returns nil. Why is this happening? Does layoutlist only check for tabs other than Model?

....
;; !!IMPORTANT!! TAB NAMES ARE CASE SENSITIVE OR ELSE IT DOESN'T WORK
....
		((or (member TAB (layoutlist)) (eq TAB "Model"))
....

....


Yes, "Model" is not a Layout -- those are a function of Paper Space.  One could say it's misleading that the CTAB System Variable "works with" a space that is not actually a "tab" in Paper Space, as named Layouts that it also works with are, but it is a tab along the bottom edge of the drawing.

 

By the way, you can make it not case-sensitive if you like:

 

....
  ((or (member (strcase TAB) (mapcar 'strcase (layoutlist))) (eq (strcase TAB) "MODEL"))
....
Kent Cooper, AIA
0 Likes
Message 4 of 6

emilio24DRY
Enthusiast
Enthusiast

@Kent1Cooper 

Thanks! I will add strcase to not make it case sensitive. How does the following code work?

(mapcar 'strcase (layoutlist))

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@emilio24DRY wrote:

.... How does the following code work?

(mapcar 'strcase (layoutlist))


First thing to try:  Read about it in the AutoLisp Reference.

Kent Cooper, AIA
0 Likes
Message 6 of 6

marko_ribar
Advisor
Advisor

(strcase) may not always be a solution especially if you are working with non English alphabet... Check (xstrcase) function that accepts only single argument - string and always turns string to uppercase letters... But also I don't know for which range it works... Chinese characters don't have lower/upper cases - they have only signs which are always uppercases... Also, you have 2 versions of *.lsp files that must be preloaded to work (it should work well for both AutoCAD and BricsCAD) - it's called "lstrcase.lsp" and it has 1118 pairs of upper/lower signs that cover all that is available from letters in Windows... "lstrcase.lsp" with it's function "lstrcase" accepts string and argument t/nil - "t" is for lowering and "nil" is for uppering letters... Here is the link for dedicated topic on theswamp.org, but you must be logged to download file(s)...

https://www.theswamp.org/index.php?topic=55041.msg621655#msg621655 

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes