Author Topic: Creating a Layerstate Reactor  (Read 4961 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Creating a Layerstate Reactor
« on: February 21, 2018, 07:10:01 AM »
I'm trying to create a Layerstate reactor to run a layerstate-restore whenever a unique ctab is made current.
And, I am way over my head here...The function PM-LSR will run the restore process.

Please help me get started.

Code: [Select]
(defun PM-LSR (/ layerstatenam)
  (setvar "tilemode" 0)
  (cond
    ((= (getvar "ctab") "A1-0 SITE")(setq layerstatenam "SITE"))
    ((= (getvar "ctab") "A1-1 DRIVE-THRU")(setq layerstatenam "DRIVE-THRU"))
    ((= (getvar "ctab") "A2-0 PHOTO")(setq layerstatenam "PHOTO-FLOOR"))
    ((= (getvar "ctab") "A3-0 FLOOR")(setq layerstatenam "FP"))
    ((= (getvar "ctab") "A3-1 CEILING")(setq layerstatenam "CEILING"))
    ((= (getvar "ctab") "A4-0 EXT ELEVS")(setq layerstatenam "ELEVATIONS"))
    ((= (getvar "ctab") "K2-0 KITCHEN")(setq layerstatenam "KITCHEN"))   
  )   
  (layerstate-restore "ALL-ON" nil 255)
  (layerstate-restore layerstatenam nil 255)
  (command "regenall")
  (princ (strcat "\n* Restoring Layer States from: " layerstatenam)) 
  (princ))



(defun Layerstate:Start ()
  (or *LS-Reactor*
      (setq *LS-Reactor*
             (vlr-command-reactor
               nil
               '(
                 (:vlr-commandcancelled . LS-Reactor:CommandEnded)
                 (:vlr-commandended . LS-Reactor:CommandEnded)
                 (:vlr-commandfailed . LS-Reactor:CommandEnded)
                 (:vlr-commandwillstart . LS-Reactor:CommandWillStart)
                )
             )
      )
  )

(defun LS-Reactor:CommandEnded ()
    ?
)

(defun LS-Reactor:CommandWillStart ()
  ?
)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Creating a Layerstate Reactor
« Reply #1 on: February 21, 2018, 10:41:56 AM »
Got my hands full but years ago this was a subject in several threads.
This is only one of them:  https://www.theswamp.org/index.php?topic=3388.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Creating a Layerstate Reactor
« Reply #2 on: February 21, 2018, 10:54:54 AM »
Maybe this will work:

Code: [Select]
(defun LSon nil
  (and (LSrtr t) (alert "\nLayer states reactor is activated, type \"LSoff\" to turn it off."))
)
(defun LSoff nil
  (and (LSrtr nil) (alert "\nLayer states reactor is disabled, type \"LSon\" to turn it on."))
)

(defun LSrtr ( flg )
  (foreach rtr (cdar (vlr-reactors :VLR-SysVar-reactor)) (if (= "LSrtr" (vlr-data rtr)) (vlr-remove rtr)) )
  (if flg (vlr-SysVar-Reactor "LSrtr" '((:VLR-sysVarChanged . CB:LSrtr)))) t
)

(defun CB:LSrtr ( rtr args )
  (and (equal '("TILEMODE" T) args)
    (setq args
      (cdr
        (assoc
          (getvar 'ctab)
          '(
            ("A1-0 SITE"       . "SITE")
            ("A1-1 DRIVE-THRU" . "DRIVE-THRU")
            ("A2-0 PHOTO"      . "PHOTO-FLOOR")
            ("A3-0 FLOOR"      . "FP")
            ("A3-1 CEILING"    . "CEILING")
            ("A4-0 EXT ELEVS"  . "ELEVATIONS")
            ("K2-0 KITCHEN"    . "KITCHEN")
          )
        )
      )
    )
    (vl-catch-all-error-p (setq rtr (vl-catch-all-apply 'eval '((progn (layerstate-restore "ALL-ON" nil 255) (layerstate-restore args nil 255))))))
    (alert (strcat "\nError occured: \n" (vl-catch-all-error-message rtr)))
  )
  (princ)
)
(vl-load-com) (princ)
« Last Edit: February 21, 2018, 11:15:38 AM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Creating a Layerstate Reactor
« Reply #3 on: February 21, 2018, 01:46:23 PM »
I would suggest:
Code - Auto/Visual Lisp: [Select]
  1. (defun layerstate-callback ( rtr arg / las )
  2.     (if
  3.         (setq las
  4.             (cdr
  5.                 (assoc (strcase (car arg))
  6.                    '(
  7.                         ("A1-0 SITE"       . "SITE")
  8.                         ("A1-1 DRIVE-THRU" . "DRIVE-THRU")
  9.                         ("A2-0 PHOTO"      . "PHOTO-FLOOR")
  10.                         ("A3-0 FLOOR"      . "FP")
  11.                         ("A3-1 CEILING"    . "CEILING")
  12.                         ("A4-0 EXT ELEVS"  . "ELEVATIONS")
  13.                         ("K2-0 KITCHEN"    . "KITCHEN")
  14.                     )
  15.                 )
  16.             )
  17.         )
  18.         (progn
  19.             (layerstate-restore "ALL-ON" nil 255)
  20.             (layerstate-restore las      nil 255)
  21.             (vla-regen (layerstate-doc) acallviewports)
  22.         )
  23.     )
  24.     (princ)
  25. )
  26.  
  27. (   (lambda ( )
  28.         (vl-load-com)
  29.             (if (= "layerstate-reactor" (vlr-data rtr))
  30.                 (vlr-remove rtr)
  31.             )
  32.         )
  33.             (vlr-miscellaneous-reactor "layerstate-reactor" '((:vlr-layoutswitched . layerstate-callback)))
  34.             'active-document-only
  35.         )
  36.         (eval (list 'defun 'layerstate-doc nil (vla-get-activedocument (vlax-get-acad-object))))
  37.         (princ)
  38.     )
  39. )
« Last Edit: February 22, 2018, 01:11:32 PM by Lee Mac »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Creating a Layerstate Reactor
« Reply #4 on: February 21, 2018, 02:09:40 PM »
BTW the subfunctions in CAB's code are handy, as they provide alternative for the layerstate-restore (which is a floating sand <EXRXSUBR>).
Impressive work CAB, (considering its from 2004).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Creating a Layerstate Reactor
« Reply #5 on: February 21, 2018, 02:40:00 PM »
BTW the subfunctions in CAB's code are handy, as they provide alternative for the layerstate-restore (which is a floating sand <EXRXSUBR>).
Impressive work CAB, (considering its from 2004).

*blink-blink* ...How about just: "...<snip>... Impressive work, CAB.".
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Creating a Layerstate Reactor
« Reply #6 on: February 21, 2018, 03:00:51 PM »
*blink-blink* ...How about just: "...<snip>... Impressive work, CAB.".

His code looks solid, the 'impressive' is because he wrote it 14 years ago.
Now one can find examples/references/similar codes anywhere...

Didn't mean to sound "its a nice code but its old" :sad:
Hope now its clear what I ment.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Creating a Layerstate Reactor
« Reply #7 on: February 21, 2018, 03:59:00 PM »
Ah, well okay, that's "situation normal" for TheSwamp. You've heard the saying: "We all stand on the shoulders of giants." Well, here be where they roam--or, in some cases, were but you'll know they were here by their foot prints-. This place has taught quite a few giants.

Take for example a recent event (which I know you've been around long enough to witness):
1. How many other forums do you know of that fixed up an old code syntax highlighter mod--made it theirs--and created a custom help file (put in a huge effort to make the code you post that much more presentable and just plain awesome-er). That was fourth time we've fixed that code highlighter mod thing gone to extra effort for our members.

EDIT:
And, you should also just accept CABs code is solid (be shocked when it's not).
« Last Edit: February 21, 2018, 04:03:42 PM by John Kaul (Se7en) »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #8 on: February 21, 2018, 04:05:09 PM »
Thanks guys

My head hurts...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Creating a Layerstate Reactor
« Reply #9 on: February 21, 2018, 05:07:04 PM »
Ah, well okay, that's "situation normal" for TheSwamp. You've heard the saying: "We all stand on the shoulders of giants." Well, here be where they roam--or, in some cases, were but you'll know they were here by their foot prints-. This place has taught quite a few giants.

This forum is full of members, that are giants -
Literally when you have a problem with your code, there are so many guys that could help you so you could not list their nicknames without forgetting someone.
Even you can't include in there the members you never knew exist and how skilled they are.
So the feeling is like playing poker - you don't know who what cards will reveal.

And the special thing I find about it (theswamp) is the type of threads - they help you to develop in knowledge.
See, in the other forums the people just ask for a complete routine that does bla-bla-bla and bla.
Someone helps out (usually a giant from theswamp) and thats it - if you are a start lisper you could learn something from that suggestion (if you want to)
But if you are rather experienced, then theres a small chance to find something new for you.
While here:
  • problems are being solved
  • (sub)functions being shared
  • unknown bugs are being discussed

And, you should also just accept CABs code is solid (be shocked when it's not).

I guess we all like to revise someone else's suggestions (whatever the reason - learn/doubt/check), and point out if there are any possible problems (so we'll all know).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #10 on: February 22, 2018, 09:33:23 AM »
@Lee

Is there a wall using you routine to run a regenall? This is what is missing to show the effects of the layerstate restore.
I have tried the different settings in "layout regen" in options, and without success.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Creating a Layerstate Reactor
« Reply #11 on: February 22, 2018, 01:12:29 PM »
Is there a wall way using your routine to run a regenall? This is what is missing to show the effects of the layerstate restore.

I have updated my earlier code.  :-)

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #12 on: February 22, 2018, 03:12:47 PM »
WOW, THANK YOU SIR!!!

It works like a charm...I've never played around much with layer states. Doing work for a new client, and the use a lot of layer states.
I tied to use a command in your routine...duh, of course it did not work.

Gary

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Creating a Layerstate Reactor
« Reply #13 on: February 22, 2018, 04:28:49 PM »
You're welcome Gary, glad it helps.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #14 on: February 22, 2018, 04:32:57 PM »
I add:
(vla-zoomextents (vlax-get-acad-object))

Now it will do everthing in my wish list.

Thanks again
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #15 on: February 22, 2018, 07:04:40 PM »
OOPS

In BricsCAD I get this message:

Error: bad argument type <NIL> ; expected ENTITYNAME at [layerstate-restore]
; LISP execution error : inside <LAYERSTATE-CALLBACK> at [VLR-Miscellaneous-Reactor:vlr-layoutSwitched]
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Creating a Layerstate Reactor
« Reply #16 on: February 23, 2018, 07:55:28 AM »
OOPS

In BricsCAD I get this message:

Error: bad argument type <NIL> ; expected ENTITYNAME at [layerstate-restore]
; LISP execution error : inside <LAYERSTATE-CALLBACK> at [VLR-Miscellaneous-Reactor:vlr-layoutSwitched]

This is due to BricsCAD's implementation of the layerstate-restore function - evidently the viewport argument is not considered optional in BricsCAD.

This will require a support request to BricsCAD to resolve.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Creating a Layerstate Reactor
« Reply #17 on: February 23, 2018, 08:38:21 AM »
... In the interim: use the BricsCAD vl-layerstates-restore function.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #18 on: February 23, 2018, 11:44:42 AM »
Thanks

I posted this error to the BricsCAD forum.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #19 on: April 15, 2018, 11:13:59 AM »
Will the following work?

(setq program (substr (getvar "acadver") 6 (- (strlen (getvar "acadver")) 1)))
(cond
             ((= program "BricsCAD")(vl-layerstates-restore (getvar "ctab") 6 NIL 0))
             ((/= program "BricsCAD")(layerstate-restore las      nil 255)))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Creating a Layerstate Reactor
« Reply #20 on: April 15, 2018, 05:38:28 PM »
Made some other changes...it now works.

(setq program (substr (getvar "acadver") 6 (- (strlen (getvar "acadver")) 1))) 
(if (= (getvar "program") "BRICSCAD")
              (vl-layerstates-restore (getvar "ctab") 6 NIL 0)
              (layerstate-restore las      nil 255)
            ) 
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Creating a Layerstate Reactor
« Reply #21 on: April 16, 2018, 09:54:07 AM »
Gary,

You could also do something like this:
Code - Auto/Visual Lisp: [Select]
  1. (if vl-layerstates-restore
  2.   (vl-layerstates-restore (getvar "ctab") 6 nil 0)
  3.   (layerstate-restore las nil 255)
  4. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC