How does tblsearch and member actually work.

How does tblsearch and member actually work.

emilio24DRY
Enthusiast Enthusiast
2,165 Views
22 Replies
Message 1 of 23

How does tblsearch and member actually work.

emilio24DRY
Enthusiast
Enthusiast

I have the code below that works, but I am not completely sure why it works. For example, line 6, the tblsearch command returns what exactly (I have looked here, but it is not enough information for my understanding). Within the condition statement between lines 5 and 8 how is that telling the code that the layer exists.

 

I have the same question about the member command in line 64. What exactly is happening with the code? Again, I have checked that it wo...

 

Is there a more extensive description of how tblsearch and member work with all the arguments that can be passed through it?

 

Thanks!

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ECR:deleteLayer ( LAYER / )
;; CHECKS IF LAYER EXISTS BEFORE DELETING LAYER
	;; ADD TEXT TO ADD IF IT DOESN'T EXIST (CONDITION ELSE?)
	(cond
		((tblsearch "layer" LAYER)
			(command "-laydel" "name" LAYER "" "yes")  
		);LAYER EXISTS
		(t
			(princ (strcat "\n-\n" LAYER " does not exist to be deleted\n-\n"))
		);ELSE
	);COND
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ECR:setCurrentLayer ( LAYER / )
;; SET CURRENT LAYER
	;; ADD SOME ERROR CHECKING TO CHECK IF THE LAYER EXISTS
	;; ADD TEXT TO ADD IF IT DOESN'T EXIST
	(cond
		((tblsearch "layer" LAYER)
			(command "-layer" "set" LAYER "")
		); LAYER EXISTS
		(t
			(command "-layer" "set" "1-DUMP" "")
			(princ (strcat "\n-\n" LAYER " does not exist to be set to current (setCurrentLayer). Layer ''1-DUMP'' Set to current\n-\n"))
		);ELSE
	);COND
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ECR:thawLayer ( LAYER / )
;; SET CURRENT LAYER
	;; ADD SOME ERROR CHECKING TO CHECK IF THE LAYER EXISTS
	;; ADD TEXT TO ADD IF IT DOESN'T EXIST
	(cond
		((tblsearch "layer" LAYER)
			(command "-layer" "THAW" LAYER "")
		);LAYER EXISTS
		(t
			(princ (strcat "\n-\n" LAYER " does not exist to be thawed (thawLayer).\n-\n"))
		);ELSE
	);cond
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ECR:setTab ( TAB / )
;; CHANGE TABS AND DO ZOOM EXTENTS ON THAT TAB
	(cond
		((member TAB (layoutlist))
			(setvar "ctab" TAB)
			(command "zoom" "extents")
		);LAYOUT NAME EXISTS
		(t
			(princ (strcat "\n-\n" TAB " does not exist to be set (setTab).\n-\n"))
		);ELSE
	);COND
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ECR:deleteTab ( TAB / )
;; DELETES TAB BUT FIRST CHECK IF THE TAB EXISTS BEFORE TRYING TO DELETE
	(cond
		((member TAB (layoutlist))
			(command "-layout" "delete" TAB)
		);LAYOUT NAME EXISTS
		(t
			(princ (strcat "\n-\n" TAB " does not exist to be deleted (deleteTab).\n-\n"))
		);ELSE
	);COND
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ECR:renameTab ( OLD_TAB NEW_TAB / )
;; RENAME TAB BUT FIRST CHECK IF THE TAB EXISTS BEFORE TRYING TO RENAME
	(cond
		((member OLD_TAB (layoutlist))
			(command "-layout" "Rename" OLD_TAB NEW_TAB)
		);LAYOUT NAME EXISTS
		(t
			(princ (strcat "\n-\n" OLD_TAB " does not exist to be renamed (renameTab).\n-\n"))
		);ELSE
	);COND
(princ)
)

 

0 Likes
2,166 Views
22 Replies
Replies (22)
Message 21 of 23

Kent1Cooper
Consultant
Consultant

@dbroad wrote:

My solution was to (...(setvar "clayer" "0")(command "laydel")...)  I never need to worry about being on a layer I want to delete. ....


[... then the only remaining possible problem would be if Layer "0" is frozen, so it can't be made current.]

 

I've been playing with this, and I almost have something that also:

1)  forbids trying to do it to Layer "0" or an Xref-dependent Layer;

2)  if the desired Layer is either current or locked, asks whether you want to delete it anyway;

3)  if you do, and it's locked, unlocks it;

3)  if you do, and it's current, finds a non-frozen non-Xref-dependent Layer to make current instead, starting by trying Layer "0" but continuing to look if that's frozen, rather than thawing it, in case you have some good reason to want it to remain frozen.

 

It's not all working quite right yet, but soon [I hope]....

Kent Cooper, AIA
0 Likes
Message 22 of 23

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
.... if Layer "0" is frozen, so it can't be made current.]  I've been playing with this...It's not all working quite right yet, but soon [I hope]....

I figured out the part that wasn't there yet. See the attached DeleteLayer.lsp with its function of the same name [note that it's a function to take a Layer name argument, not a command].  Read the comments at the top, and within the code.  [I also chose to not let it make "Defpoints" current if the one to be deleted is current, because it's a bad idea to draw things on that Layer, so I wouldn't want to be left in it by this.]

Kent Cooper, AIA
Message 23 of 23

dbroad
Mentor
Mentor

@Kent1Cooper Nice.  IMO, anyone who leaves layer 0 or layer defpoints frozen doesn't understand how to use AutoCAD. That would be in important factor in whether to keep an employee.

Architect, Registered NC, VA, SC, & GA.
0 Likes