Need help for lisp code

Need help for lisp code

avinash00002002
Collaborator Collaborator
386 Views
3 Replies
Message 1 of 4

Need help for lisp code

avinash00002002
Collaborator
Collaborator

Hi!

I have a need of lisp for

1. Select single object and get chnage its layer (works good)

2. Pre-selected items also change its layer (need help)

3. select with Crossing and Window (works good)

 

Thanks,

Avinash

 
 
 
Code:
(defun c:CaF ( / fl p1 p3 ls hi ss )
  (setq OldClay (getvar "Clayer"))
(setq flag (tblsearch "LAYER" "F"))
(if flag (setvar "CLAYER" "F") (command "_.layer" "make" "F"     "c" "7"   ""  "LW" "0.20"  ""))
 
(princ "\nSelect Objects to Change Layer F: ")

(while (and (not fl) (= 3 (car (setq p1 (grread nil 12 2)))))

(if (setq ss (ssget (setq p1 (cadr p1))))

(command "_.chprop"    ss      ""        "LA"
         "F"   "c"     "Bylayer" "Lt"      "Bylayer"
         ""
        )

(progn

(princ "\nSpecify Opposite Corner: ")

(while (= 5 (car (setq p3 (grread t 13 0))))

(redraw)

(setq p3 (cadr p3))

(setq ls

(list

p1

(list (car p3) (cadr p1) (caddr p1))

p3

(list (car p1) (cadr p3) (caddr p1))

)

)

(setq hi (if (< (car p1) (car p3)) 0 1))

(mapcar '(lambda ( a b ) (grdraw a b -1 hi)) ls (append (cdr ls) (list p1)))

)

(if (listp (setq p3 (cadr p3)))

(if (setq ss (ssget (if (< (car p1) (car p3)) "_W" "_C") p1 p3))

(command "_.chprop"    ss      ""        "LA"
         "F"   "c"     "Bylayer" "Lt"      "Bylayer"
         ""
        )

)

(setq fl t)

)

(redraw) (princ "\nSelect Objects to Change to Layer F: ")

)

)

)
(setvar "Clayer" OldClay)
(redraw) (princ)

) ;CaF
0 Likes
387 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

Simpler shorter better.

 

(defun c:caf ( / *error* l s)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if l (setvar 'clayer l))
    (princ))
  
(setq s (ssget "I")) (setq l (getvar 'clayer)) (command "_.-layer" "_t" "F" "_make" "F" "c" 7 "" "LW" 0.20 "" "") (while (setq s (ssget "_:S")) (command "_.chprop" s "" "LA" "F" "c" "Bylayer" "Lt" "Bylayer" "")) (*error* "end") )

 

0 Likes
Message 3 of 4

komondormrex
Mentor
Mentor

hey there,

check the following

 

 

 

(defun c:CaF (/ OldClay flag fl p1 p3 ls hi ss pre_ss)
	(setq OldClay (getvar "Clayer"))
	(setq flag (tblsearch "LAYER" "F"))
	(if flag
		(setvar "CLAYER" "F")
		(command "_.layer" "_make" "F" "_c" "7" "" "_LW" "0.20" "")
	)
	(princ "\nSelect Objects to Change Layer F: ")
	(setq pre_ss (cadr (setq pre_ss (ssgetfirst))))
	(while (and (not fl)
				(if (null pre_ss)
						(= 3 (car (setq p1 (grread nil 12 2))))
						t
				)
		   ) 
			(cond
				(
					pre_ss
						(command "_.chprop" pre_ss "" "LA" "F" "_c" "Bylayer" "_Lt" "Bylayer" "")
				)
				(
					(setq ss (ssget (setq p1 (cadr p1))))
						(command "_.chprop" ss "" "LA" "F" "_c" "Bylayer" "_Lt" "Bylayer" "")
				)
				(
					t
						(princ "\nSpecify Opposite Corner: ")
						(while (= 5 (car (setq p3 (grread t 13 0))))
							(redraw)
							(setq p3 (cadr p3)
								  ls (list p1
									 	  (list (car p3) (cadr p1) (caddr p1))
									 	  p3
									 	  (list (car p1) (cadr p3) (caddr p1))
									 )

								  hi (if (< (car p1) (car p3)) (getvar 'windowareacolor) (getvar 'crossingareacolor))
							)
							(mapcar '(lambda (a b) (grdraw a b hi 1)) ls (append (cdr ls) (list p1)))
						)
						(if (listp (setq p3 (cadr p3)))
							(if (setq ss (ssget (if (< (car p1) (car p3)) "_W" "_C") p1 p3))
								(command "_.chprop" ss "" "_LA" "F" "_c" "Bylayer" "_Lt" "Bylayer" "")
							)
							(setq fl t)
						)
						(redraw)
						(princ "\nSelect Objects to Change to Layer F: ")
				)
			)
			(if pre_ss (setq pre_ss nil))
	)
	(setvar "Clayer" OldClay)
	(redraw)
	(princ)
)

 

 

updated_2

 

Message 4 of 4

Kent1Cooper
Consultant
Consultant

It seems to me that it is not necessary to have the "F" Layer current.  You are only putting/moving existing objects on that Layer, never drawing anything on it.  So if you don't make it current, you don't need to save and reset the Layer that's current when you start.  Just use the New option instead of the Make option.  The extra code it takes to give it the Layer name in assigning color and lineweight, instead of just giving it "" Enter for the current Layer, is far less than what you save by not making it current.

 

(command "_.layer" "_new" "F" "_color" 7 "F" "_lweight" 0.2 "F" "")

 

[The numerical entries don't need to be in the form of text strings, and that trailing 0 on 0.20 did nothing at all for you.]

 

In the selection, is this the idea?

A.  If there's a pre-selection, the properties of the pre-selection just get changed without further User input;

B.  If there isn't, you are asked to select, in which case:

    1.  If you pick on an object, its properties get changed immediately, without your needing to indicate completion of selection [as with Enter/space], or

    2.  If you pick in empty space, it goes into window/crossing selection mode, and as soon as you give it the other corner, it changes what was found, again without indicating completion.

And in all cases, it continues, asking again?  Which means with a pre-selection, those things are changed and it still asks again [at which time of course it can be only by inside-the-command selection, and pre-selection is possible only as the first pass]?

Kent Cooper, AIA
0 Likes