declaring variable

declaring variable

vishshreevT578L
Advocate Advocate
1,725 Views
22 Replies
Message 1 of 23

declaring variable

vishshreevT578L
Advocate
Advocate

(defun CopyLayerColor2 (ent1 ent2 / elist1 elist2 lay1 col1)
(setq elist1 (entget ent1)
elist2 (entget ent2)
lay1 (cdr (assoc 8 elist1))
)
(setq elist2 (subst (cons 8 lay1) (assoc 8 elist2) elist2))
(if (assoc 62 elist1)
(progn
(setq col1 (cdr (assoc 62 elist1)))
(if (assoc 62 elist2)
(setq elist2 (cons (cons 62 col1) elist2))
(setq elist2 (subst (cons 62 col1) (assoc 62 elist2) elist2))
)
)
)
(entmod elist2)
)

 

Is this code correct.

my question is about declaring variable which i am making bold. (defun CopyLayerColor2 (ent1 ent2 / elist1 elist2 lay1 col1) 

Shreev
0 Likes
Accepted solutions (1)
1,726 Views
22 Replies
Replies (22)
Message 21 of 23

john.uhden
Mentor
Mentor
;; No need for if...
(defun C:CopyLayerColor2 ( / en1 en2)
  (and
    (setq en1 (car (entsel "\nSelect the object to copy layer from: ")))
    (setq en2 (car (entsel "\nSelect the object to copy layer to: ")))
    (CopyLayerColor2 en1 en2)
  )
  (princ)
)

John F. Uhden

0 Likes
Message 22 of 23

vishshreevT578L
Advocate
Advocate

Great way used to make me understand, Thank you very much sir

Shreev
0 Likes
Message 23 of 23

john.uhden
Mentor
Mentor
(defun ARGTEST (arg1 arg2 / ccc)
  ;; Note that the input arguments, arg1 and arg1, are local as well as ccc and retval,
  ;; meaning that they will have no value outside the function.
  ;;
  ;; Another way of reporting the argument staus is via the cond function [condition]
  (setq ccc "Constant string")
  (cond
    ((and (/= (type arg1) 'STR)(/= (type arg2) 'STR))
      (prompt "\nbad arguments: neither arg1 nor arg2 is a string.")
    )
    ((/= (type arg1) 'STR)
      (prompt "\nbad argument: arg1 is not a string.")
    )
    ((/= (type arg2) 'STR)
      (prompt "\nbad argument: arg2 is not a string.")
    )
    (1 ;; or T, both of which are non nil
      (strcat "\n" ccc ", " arg1 ", " arg2)
    )
  )
  ;; There is no need to set the retval variable
  ;; since the value will be returned by the function.
)

By the way, when when replying with code, do NOT use the "Quick Reply" button.

Use the "Reply" button where you will see a ribbon menu and and icon to "Insert Code"

That way your indentation will be preserved as mine is above.

John F. Uhden

0 Likes