Results 1 to 5 of 5

Thread: Variable Reactors - some work, some don't

  1. #1
    I could stop if I wanted to
    Join Date
    2015-05
    Location
    West Des Moines
    Posts
    306
    Login to Give a bone
    0

    Default Variable Reactors - some work, some don't

    Hi All,

    I found a variable reactor line of code a very long time ago and was able to replicate it for other variables I cared about; filedia, savetime, dynmode, and pickfirst. However, over the years a few of them broke and now only filedia and savetime work to this day. I've finally gotten around to wanting to fix it because I'd like to be able to keep these in check, or be able to offer up other system variabels to other users more reliably if they have ones they'd like to monitor.

    Does anyone know why this stopped working/how it has to be updated? I'll be honest I'm not fluent in lisp; I somehow came across this, was able to identify the core features of the routine, and just changed it to other variables and went about my day.

    Thanks!

    Code:
    (vl-load-com)
    (setq VTFRXN (vlr-editor-reactor nil '((:VLR-sysVarChanged . VTF))))
    
    
    (defun VTF (CALL CALLBACK)
      (if (and(= (strcase (car CALLBACK)) (setq str "FILEDIA"))(not (eq (getvar str) 1)))
        (progn
          (setvar "FILEDIA" 1)
        )
      )
    )
    (setvar "filedia" 1)

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,409
    Login to Give a bone
    0

    Default Re: Variable Reactors - some work, some don't

    Do you know about the SYSVARMONITOR command? It lets you know when a variable you're watching changes and let's you reset it.
    C:> ED WORKING....


    LinkedIn

  3. #3
    I could stop if I wanted to
    Join Date
    2015-05
    Location
    West Des Moines
    Posts
    306
    Login to Give a bone
    0

    Default Re: Variable Reactors - some work, some don't

    I do, but as far as I'm aware you can't tell it to force the setting; it only alerts you if it changes, and that's better than nothing, but the variable reactor means they will literally never change so no user input is ever required. If you ask me the variable reactor is simply superior because of that. Just speaking from my own experience I've had this reactor for almost 10 years now and I have never dealt with Filedia. Depending on the user some are keenly aware of Filedia and groan whenever it happens, and others coming running to me saying, "I don't get, like, you know, one of those a window popups in my CAD anymore when I try to open a file. It...like wants me to type it out...?". Even if I showed them how to use the sysvarmonitor command they probably wouldn't even notice with the bubble notification.

    I suppose a simple setvar routine file could be set up so every time you load cad it updates them all, but my past experience was that sometimes the variables would change mid-session for one reason or another. This could be outdated experience though.

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,409
    Login to Give a bone
    0

    Default Re: Variable Reactors - some work, some don't

    If you're after a way to force a state, then you don't really need to check the current status, just set if to a default. AutoCAD comes with acadinfo.lsp. It has a function called vars2scr. It writes variable settings to a script file, but it's written in lisp. You can use this as a pattern for setting sysvars or just write your own acaddoc.lsp with (setvar) functions. acaddoc.lsp runs when you open a dwg. I have a ribbon button that runs vars2scr. Note that there is a space at the end. Each user can save their own preferred settings.

    Code:
    ^C^C(if (null vars2scr)(load "acadinfo"));vars2scr
    C:> ED WORKING....


    LinkedIn

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Variable Reactors - some work, some don't

    This code filters the name of the system variable for "USER*" but can easily be changed to monitor any variable or variables.

    Download attached file and load:

    P=


    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2024 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;* (SystemVariableWillChangeCallBack rxnCall lstCallback)
    ;* Callback Function for system variable will change that prints to the command line
    
    ;* (SystemVariableChangedCallBack rxnCall lstCallback)
    ;* Callback Function for system variable changed that prints the change to the command line
    
    ;* (SystemVariableValue strVariableName)
    ;* Function to get a system variable using an activeX methods
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Callback Function for system variable will change that prints to the command line
    ;___________________________________________________________________________________________________________|
    
    (defun SystemVariableWillChangeCallBack (rxnCall lstCallback / strSystemVariable)
     (if (and (setq strVariableName (car lstCallback))
              (wcmatch strVariableName "*USER*")
         )
      (progn
       (if (= (substr strVariableName 1 1) "*")
        (setq strVariableName (substr strVariableName 2))
       )
       (princ  (strcat strVariableName " To Change"))
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Callback Function for system variable changed that prints the change to the command line
    ;___________________________________________________________________________________________________________|
    
    (defun SystemVariableChangedCallBack (rxnCall lstCallback / strSystemVariable Value)
     (if (and (setq strVariableName (car lstCallback))
              (cadr lstCallback)
              (wcmatch strVariableName "*USER*")
         )
      (progn
       (if (= (substr strVariableName 1 1) "*")
        (setq strVariableName (substr strVariableName 2))
       )
       (setq  Value (SystemVariableValue strVariableName))
       (princ  (strcat "\n" strVariableName " Changed to "))
       (if (= (type Value) 'STR)
        (princ (strcat "\"" (vl-princ-to-string Value) "\""))
        (princ (vl-princ-to-string Value))    
       )
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get a system variable using an activeX methods
    ;___________________________________________________________________________________________________________|
    
    (defun SystemVariableValue (strVariableName)
     (vlax-invoke 
      (vla-get-activedocument
       (vlax-get-acad-object)
      )
      "getvariable"
      strVariableName
     )
    )
    
    (vl-load-com)
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Reactor Initialization Functions
    ;___________________________________________________________________________________________________________|
     
    (if (not rxnSystemVariableWillChange)
     (setq rxnSystemVariableWillChange  (vlr-sysvar-reactor nil '((:vlr-sysvarwillchange . SystemVariableWillChangeCallBack))))
    )
    (if (not rxnSystemVariableChanged)
     (setq rxnSystemVariableChanged     (vlr-sysvar-reactor nil '((:vlr-sysvarchanged    . SystemVariableChangedCallBack))))
    )
    
    (princ "!")
    Attached Files Attached Files
    AutomateCAD

Similar Threads

  1. need some help with reactors
    By darren_lambett in forum AutoLISP
    Replies: 1
    Last Post: 2009-04-20, 12:31 PM
  2. Variable height/variable count family (studs in a sloped wall)
    By DoTheBIM in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2006-06-15, 02:48 PM
  3. Sloping Joists: Some do and some don't!
    By mikemck in forum Revit Architecture - General
    Replies: 2
    Last Post: 2005-10-14, 12:13 AM
  4. Reactors don't work in first loaded dwg...
    By dhurd in forum AutoLISP
    Replies: 0
    Last Post: 2005-01-27, 08:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •