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

layer state delete

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Hidden_Brain
1221 Views, 12 Replies

layer state delete

i have a small lisp and i would like for it to:

  1. when i invoke the plot command, it will first check if there is a layer state called "Temp"
  2. if "Temp" exists, then delete "Temp", then re-create "Temp", then switch layer state temporariliy to "Plot" to plot the file, and then switch back to the "Temp" layer state again
  3. basically, the "Plot" layer state will be set based on how the drawing(s) will plot. if a user makes changes here-n-there in the drawing, when the user wants to plot, the software will save current state as "Temp", plot using the "Plot" state, and switch back to "Temp" state at the end. all i am trying to achieve is to somehow over-write the "Temp" state. below is the LISP, any help is appreciated.

 

(command "undefine" "plot")

(defun c:plot ()
(if (layerstate-has "Temp")
(layerstate-delete “Temp”)
)


(command "Layer" "A" "S" "Temp" "" "" "")
(command "Layer" "A" "R" "plot" "" "" "")
(command ".plot" "Yes" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")
(command "Layer" "A" "R" "Temp" "" "" "")
(graphscr)
(princ)
)

12 REPLIES 12
Message 2 of 13
Hidden_Brain
in reply to: Hidden_Brain

sorry for the "accidental" smiley, it should be

(defun c "colon sign" plot ()

Message 3 of 13
Jeff_M
in reply to: Hidden_Brain


@youngPE wrote:

sorry for the "accidental" smiley, it should be

(defun c "colon sign" plot ()


If you use the Code tags you don't get the smiley's 🙂

code tag.png

 

 
(command "undefine" "plot")

(defun c:plot ()
(if (layerstate-has "Temp")
(layerstate-delete “Temp”)
)


(command "Layer" "A" "S" "Temp" "" "" "")
(command "Layer" "A" "R" "plot" "" "" "")
(command ".plot" "Yes" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")
(command "Layer" "A" "R" "Temp" "" "" "")
(graphscr)
(princ)
)

 

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 13
Hidden_Brain
in reply to: Jeff_M

thanks for the tip Jeff. any suggestions on how to make the code run?

Message 5 of 13
Jeff_M
in reply to: Hidden_Brain


@youngPE wrote:

thanks for the tip Jeff. any suggestions on how to make the code run?


I was working on that...this will delete the TEMP Layerstate if it exists:

(vl-load-com)
(setq lays (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(if (vla-get-hasextensiondictionary lays :vlax-true)
  (progn
    (setq exdict (vla-getextensiondictionary lays))
    (setq dict (vla-item exdict "ACAD_LAYERSTATES"))    
    (vlax-for xrec dict
      (if (eq (strcase (vla-get-name xrec)) "TEMP")
	(vla-delete xrec)
	)
      )

 

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 13
hmsilva
in reply to: Hidden_Brain

youngPE,
perhaps something like

 

(command "undefine" "plot")

(defun c:plot ()
(if (layerstate-has "Temp")
(layerstate-delete "Temp")
)


(command "-Layer" "A" "S" "Temp" "" "" "");; changed to commandline version
(command "-Layer" "A" "R" "plot" "" "" "");; changed to commandline version
(command "-plot" "Yes" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "");; changed to commandline version
(command "-Layer" "A" "R" "Temp" "" "" "");; changed to commandline version
(graphscr)
(princ)
)

 

should work well, I do not know if the number of enters in the plot command is correct or not, you have to test it.

 

Henrique

EESignature

Message 7 of 13
Hidden_Brain
in reply to: Jeff_M

Jeff,

i merged what you gave with what i had (added two extra parantheses at the end of yours), loads fine, but gives me an error as:

Command: plot
; error: Too many actual parameters

 

i must be doing something dumb here, but cannot figure out what. do you have any ideas? merged code is below:

 

 

(command "undefine" "plot")

(defun c:plot ()
(vl-load-com)
(setq lays (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(if (vla-get-hasextensiondictionary lays :vlax-true)
  (progn
    (setq exdict (vla-getextensiondictionary lays))
    (setq dict (vla-item exdict "ACAD_LAYERSTATES"))    
    (vlax-for xrec dict
      (if (eq (strcase (vla-get-name xrec)) "TEMP")
    (vla-delete xrec)
    )
      )
)
)

(command "Layer" "A" "S" "Temp" "" "" "")
(command "Layer" "A" "R" "plot" "" "" "")
(command ".plot" "Yes" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")
(command "Layer" "A" "R" "Temp" "" "" "")
(graphscr)
(princ)
)

Message 8 of 13
Hidden_Brain
in reply to: hmsilva

Henrique,

yours seem to work very well! i didnt expect that going to the command line version would make the difference, thanks!

Message 9 of 13
hmsilva
in reply to: Hidden_Brain

youngPE,
in my previous post, I forgot to redefine the plot command,

You should receive an error such as;
Command: PLOT Unknown command "PLOT".  Press F1 for help.

 

(command "undefine" "plot")

(defun c:plot ()
(if (layerstate-has "Temp")
(layerstate-delete "Temp")
)


(command "-Layer" "A" "S" "Temp" "" "" "");; changed to commandline version
(command "-Layer" "A" "R" "plot" "" "" "");; changed to commandline version
(command "_redefine" "plot");; restores the plot command
(command "-plot" "Yes" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "");; changed to commandline version
(command "-Layer" "A" "R" "Temp" "" "" "");; changed to commandline version
(graphscr)
(princ)
)

 Henrique

 

 

EESignature

Message 10 of 13
Kent1Cooper
in reply to: Hidden_Brain


@youngPE wrote:

sorry for the "accidental" smiley, it should be

(defun c "colon sign" plot ()


[Another way to avoid smileys:  see the instructions at the top of this thread.  But when you know you're using a colon-and-letter combination that triggers some smiley [see the list there], using a code window will prevent the smiley for others who aren't signed in, or for those who are but who don't have them turned off.  (There was a time when even a code window didn't prevent it, but that's no longer a problem.)]

Kent Cooper, AIA
Message 11 of 13
Jeff_M
in reply to: Hidden_Brain

Well, that'll teach me to visit the lisp forum once every few years...I didn't know that the layerstate-* functions existed.....I thought you were looking for a way to do what they do.... Smiley Embarassed

Jeff_M, also a frequent Swamper
EESignature
Message 12 of 13
Hidden_Brain
in reply to: Jeff_M

no worries Jeff, I have personally always learned something new from you every time you have replied to my questions. thanks again for sharing all the knowledge!

Message 13 of 13
Hidden_Brain
in reply to: Hidden_Brain

thanks again everyone for helping me out with this one!

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

Post to forums  

Autodesk Design & Make Report

”Boost