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

Lisp Program to change layers (Small problem)

2 REPLIES 2
Reply
Message 1 of 3
canuck7783
245 Views, 2 Replies

Lisp Program to change layers (Small problem)

I had the lisp below running on autocad 2002 with no problems.  I put it on a machine that is running Autocad 2014 and I have one small problem.  When I was on autocad 2002 I could select an object line and then run my lisp program by clicking "WW" and it would change to the correct layer "PART".  On the autocad 2014 machine, it won't let me do it.  I have to run the lisp program first (clicking "WW" first), it then asks me to select the object layer you want to change and then it changes to the correct layer.  I already messed around with the "Pickfirst" option and that isn't it.  Is there something wrong with my coding that I'm not seeing.  Maybe there is a better way to write the program to do what I want.  I am up for suggestions.

 

Thank you

 

Lisp Program Below

 

; ---------------------------PART LISP--------------------------
;       CHANGES A SELECTED OBJECTS LAYER TO LAYER "PART"
; ----------------------------------------------------------------
(Defun C:WW (/ SS CNT LAY)

(setvar "cmdecho" 0)
(if (not (tblsearch "LAYER" "object"))
(command "Layer" "N" "PART" "C" "red" "PART" "LT" "continuous" "PART" "" ""))

  (if (not (setq SS (ssget "i")))
    (progn
      (prompt "\nSelect objects to be CHANGED to layer PART: ")
      (setq SS (ssget))
    )
  )

  (if SS
      (command "_.change" SS "" "_p" "_la" "PART" "")
      (if (= (sslength SS) 1)
        (prompt (strcat "\nOne object changed to layer "PART"))
        (prompt (strcat "\n" (itoa (sslength SS)) "objects changed to layer "PART")
      )
    )
  )

(setvar "cmdecho" 1)
  (princ)
)

2 REPLIES 2
Message 2 of 3
Ajilal.Vijayan
in reply to: canuck7783

Hi,

The below changes(in Bold) to the code works on 2014.

 

; ---------------------------PART LISP--------------------------
;       CHANGES A SELECTED OBJECTS LAYER TO LAYER "PART"
; ----------------------------------------------------------------
(Defun C:WW (/ SS CNT LAY slctn)
(setq slctn nil);flag to set the active selection
(setvar "cmdecho" 0)
(if (not (tblsearch "LAYER" "PART"))
(command "Layer" "N" "PART" "C" "red" "PART" "LT" "continuous" "PART" "" ""))

  (if (not (setq SS (ssget "i")))
    (progn
	(print "No Selection")
      (prompt "\nSelect objects to be CHANGED to layer PART: ")
      (setq SS (ssget))
    )
	(setq slctn T);Trun the flag ON as there is a PICKFIRST selection found
  )

  
  (if slctn ;if PICKFIRST selection found
  (progn
      (command "_.change" "_p" "_la" "PART" "")
      (if (= (sslength SS) 1)
        (prompt (strcat "\nOne object changed to layer PART"))
        (prompt (strcat "\n" (itoa (sslength SS)) " objects changed to layer PART"))
    )
	);progn
	(command "_.change" SS "" "_p" "_la" "PART" "");no PICKFIRST selection
  )

(setvar "cmdecho" 1)
  (princ)
)

 

Message 3 of 3
canuck7783
in reply to: Ajilal.Vijayan

Thank you, that works perfectly!!!

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

Post to forums  

”Boost