Author Topic: Script or Lisp for Layer States Manager  (Read 7442 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Script or Lisp for Layer States Manager
« on: May 30, 2013, 01:23:02 PM »
I am trying to create a script or lisp that will automatically open the layer states manager; select a layer state; activate it; then do a save as to X.dwg and overwrite it.

Any ideas?
Thank you
Civil3D 2020

BlackBox

  • King Gator
  • Posts: 3770
Re: Script or Lisp for Layer States Manager
« Reply #1 on: May 30, 2013, 02:01:47 PM »
You cannot modify the dialog via LISP... You can instead use the LayerState-* LispFunction Methods built-into the Visual LISP API however.
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5353
  • Standby for witty remark...
Re: Script or Lisp for Layer States Manager
« Reply #2 on: May 30, 2013, 02:01:56 PM »
You should look into the LAYERSTATE-RESTORE function.

EDIT: BBox beat me to it.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Script or Lisp for Layer States Manager
« Reply #3 on: May 30, 2013, 02:16:33 PM »
You should look into the LAYERSTATE-RESTORE function.

EDIT: BBox beat me to it... This round.

FTFY  :wink:



 :lol:
"How we think determines what we do, and what we do determines what we get."

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Script or Lisp for Layer States Manager
« Reply #4 on: May 30, 2013, 02:18:40 PM »
You cannot modify the dialog via LISP... You can instead use the LayerState-* LispFunction Methods built-into the Visual LISP API however.

Could I do the above in a Script form? (To me script is easier to understand), but how would you go about that?
Civil3D 2020

BlackBox

  • King Gator
  • Posts: 3770
Re: Script or Lisp for Layer States Manager
« Reply #5 on: May 30, 2013, 02:28:03 PM »
I am trying to create a script or lisp that will automatically open the layer states manager; select a layer state; activate it; then do a save as to X.dwg and overwrite it.

Could I do the above in a Script form? (To me script is easier to understand), but how would you go about that?



Here's a simple LISP, which can still be called from your Script, or at anytime of your choosing mid-session... Just be sure to replace "YourLayerStateName" here:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:FOO (/ layerstateName)
  3.   (if (layerstate-has (setq layerstateName "YourLayerStateName"))
  4.     (progn
  5.       (layerstate-restore layerstateName nil 3)
  6.       (vla-saveas
  7.         (strcat (getvar 'dwgprefix) (getvar 'dwgname))
  8.         acnative
  9.       )
  10.     )
  11.   )
  12.   (princ)
  13. )
  14.  
"How we think determines what we do, and what we do determines what we get."

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Script or Lisp for Layer States Manager
« Reply #6 on: May 30, 2013, 02:35:32 PM »
Thanks a bunch!!!!
Civil3D 2020

BlackBox

  • King Gator
  • Posts: 3770
Re: Script or Lisp for Layer States Manager
« Reply #7 on: May 30, 2013, 02:52:20 PM »
Thanks a bunch!!!!

Happy to help.  :-)
"How we think determines what we do, and what we do determines what we get."

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Script or Lisp for Layer States Manager
« Reply #8 on: May 30, 2013, 03:15:42 PM »
ok.... coming back at you! lol
I am having a hard time creating a lisp / or script to do a save as and overwrite a drawing.

I have your script which is great and works.

but I want to then save the layer state and overwrite a file with the same layer state name.
Civil3D 2020

BlackBox

  • King Gator
  • Posts: 3770
Re: Script or Lisp for Layer States Manager
« Reply #9 on: May 30, 2013, 03:19:01 PM »
... I want to then save the layer state and overwrite a file with the same layer state name.

There's no need to save the layer state as you've made no changes to it.

As for the latter, I'm not sure that I understand you fully... The file you're wanting to overwrite, it has a file name that matches the name of the layer state (+ .dwg)? What is the purpose of this file - why not export to .LAS (layer state file) instead?
"How we think determines what we do, and what we do determines what we get."

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Script or Lisp for Layer States Manager
« Reply #10 on: May 30, 2013, 03:24:34 PM »
What I am trying to do is have a Base.DWG,

First Save the Base.DWG

Then I want a layer state of 1 (Changes all my layers on and off)

Then save the current state (1) to a 1.DWG.

Civil3D 2020

BlackBox

  • King Gator
  • Posts: 3770
Re: Script or Lisp for Layer States Manager
« Reply #11 on: May 30, 2013, 03:29:50 PM »
If I am understanding you correctly:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:FOO (/ layerstateName acDoc path)
  3.   (if (and (layerstate-has (setq layerstateName "YourLayerStateName"))
  4.            (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
  5.            (setq path (getvar 'dwgprefix))
  6.       )
  7.     (progn
  8.       (vla-saveas acDoc (strcat path (getvar 'dwgname)) acnative)
  9.       (layerstate-restore layerstateName nil 1)
  10.       (vla-saveas
  11.         acDoc
  12.         (strcat path layerstateName ".dwg")
  13.         acnative
  14.       )
  15.     )
  16.   )
  17.   (princ)
  18. )
  19.  
"How we think determines what we do, and what we do determines what we get."

MSTG007

  • Gator
  • Posts: 2606
  • I can't remeber what I already asked! I need help!
Re: Script or Lisp for Layer States Manager
« Reply #12 on: May 30, 2013, 03:35:34 PM »
DING DING DING!!!!! :kewl: :kewl: :-D
Civil3D 2020