Results 1 to 4 of 4

Thread: Lisp to modify macro of a shortcut key or dynamic macro

  1. #1
    Member
    Join Date
    2020-02
    Posts
    3
    Login to Give a bone
    0

    Default Lisp to modify macro of a shortcut key or dynamic macro

    Hello!

    I wonder if it is possible to edit a shortcut keys macro with LISP. I Googled a lot without success. Maybe it is only possible with .NET.

    The situation is the following:
    In my company we set up a shortcut key for panning up and down by a specific value. (Ctrl+↑, Ctrl+↓) // ID_PanDown: ^C^C-pan 0,0 0,50000 // // ID_PanUp: ^C^C-pan 0,0 0,-50000 //
    This is very useful when working with multi-level plans, so you can jump between levels and check things.

    The problem is, every time you open another project, it is very likely that the distance between levels is different. For example: 30000, 50000, 75000, 100000, 200000
    Quite a bit time consuming to bring up the CUI to edit both values. Creating a shortcut key for every distance is not an option.

    My plan is:

    A LISP routine, you can call it with eg. "CP". The routine asks for a value, that is stored in eg. "USERR1".
    USERR1 value then passed forward to change the macro of both shortcut keys.

    As I am writing these lines I found that I can pause the macro for user input (not a good option), or I can make the macro dynamic by adding a variable in the macro.

    USERR1=50000
    USERR2=-50000
    ^C^C-pan 0,0 0,_getvar;userr1;
    ^C^C-pan 0,0 0,_getvar;userr2;

    This is not working, of course, because I am a macro and LISP noobie.

    Any help would be appreciated.
    Thank you!

  2. #2
    Member
    Join Date
    2020-02
    Posts
    3
    Login to Give a bone
    0

    Default Re: Lisp to modify macro of a shortcut key or dynamic macro

    Well, I didn't give up and finally figured it out.

    Macro is:
    Pan DOWN: ^C^C-pan 0,0 0,$M=$(getvar,userr1)
    Pan UP: ^C^C-pan 0,0 0,$M=$(getvar,userr2)

    LISP is:
    Code:
    (defun c:PD ( / d1 d2) 		;define variables
    
    (setq d1 (getreal "\nDistance between levels : ")) ;get user input
    (initget 2)                     ;0 is not allowed
    (setvar "USERR1" d1) ; set USERR1 value to input value
    (setvar "USERR2" (- d1)) ; set USERR2 value to negated input value
     
    (princ)
    
     )
    Macro could be "smarter" if I could check userr1 value. If it is 0, then call the LISP automatically.

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    555
    Login to Give a bone
    0

    Default Re: Lisp to modify macro of a shortcut key or dynamic macro

    You can make a reactor that looks at the error that has occured so if you type U5000 it will pan 5000 up. I made these as quicky functions for fillet and circle F123 does a fillet of 123 C100 does a circle with radius 100 type any number following the character "key". It is advanced coding and I had to get some help developing it.

    Here is some sample code you can make the 4 options U L R D if you get stuck just ask here. Not sure if only 2 needed U and R with -value being an option would need to test.

    Code:
    ; Enter the filet radius as part of a command line entry f100, offset O234, circle c123-45, P123 for pline width
    ; note - is used for decimal point
    ; original code and methology by Alan H
    ; assistance and code that worked by Lee-Mac
    ; OCT 2015
     
    (   (lambda nil
            (vl-load-com)
            (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
                (if (= "fillet-reactor" (vlr-data obj))
                    (vlr-remove obj)
                )
            )
            (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
        )
    )
    
    (defun plwid ( / width oldwidth)
    (setq width (distof (substr com 2) 2))
                (setq oldwidth (getvar 'plinewid))
                (if (<= 0.0 width)
                  (progn
    	      (setvar 'plinewid width )
                  (vla-sendcommand fillet-reactor-acdoc "_.pline ")
                  (setvar 'plinewid oldwidth)
                  )
                ) 
    )
    (defun filletrad ( / rad)
    (setq rad (distof (substr com 2) 2))
                (if (<= 0.0 rad)
                  (progn        
                  (setvar 'filletrad rad)
                  (vla-sendcommand fillet-reactor-acdoc "_.fillet ")
                  )
                  ) 
    )
    (defun makecirc ( / rad)
    (setq rad (distof (substr com 2) 2))
                (if (<= 0.0 rad)
                (progn        
                (setvar 'circlerad rad)
                (vla-sendcommand fillet-reactor-acdoc "_.Circle ")
                )
                )
    )
    (defun offdist ( / dist)
    (setq dist (distof (substr com 2) 2))
                (if (<= 0.0 dist)
                (progn        
                (setvar 'offsetdist dist)
                (vla-sendcommand fillet-reactor-acdoc "_.Offset  ")
                )
                )
    )
    
    (defun fillet-reactor-callback ( obj com )
    (setq com (vl-string-translate "-" "." (strcase (car com))))
        (cond   
            (   (and
                (wcmatch com "~*[~F.0-9]*")
                (wcmatch com "F*")
                (wcmatch com "~F*F*")
                (wcmatch com "~*.*.*")
                ) ; and
                (filletrad) 
             ) 
    
             (  (and
                (wcmatch com "~*[~C.0-9]*")
                (wcmatch com "C*")
                (wcmatch com "~C*C*")
                (wcmatch com "~*.*.*")
                ) ;and
                (makecirc) 
             )
    
             (  (and
                (wcmatch com "~*[~O.0-9]*")
                (wcmatch com "O*")
                (wcmatch com "~O*O*")
                (wcmatch com "~*.*.*")
                ) ; and
                (offdist) 
             )
    
             (  (and
                (wcmatch com "~*[~P.0-9]*")
                (wcmatch com "P*")
                (wcmatch com "~P*P*")
                (wcmatch com "~*.*.*")
                ) ; and
                (plwid) 
             )
    
        ) ; master cond
    ) ; defun
    
    (princ)
     
    (or fillet-reactor-acdoc
        (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
    )
    (princ)
    
    ; next Point or option keyword required.
    Code:
    ^c^c-pan 0,0 (list 0 (getvar 'userr1))

  4. #4
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: Lisp to modify macro of a shortcut key or dynamic macro

    If the distance between levels is proportionate to the view height macros using the VIEWSIZE (System Variable) may work for all your drawings. http://help.autodesk.com/view/ACD/20...5-C15CB3C4268C
    How is the spacing of the levels in a project determined?
    Can the spacing be determined from the drawing name, annotation scale, plot style, or the name of a parent folder?

    If you could attach or post a link to a stripped down drawing with a rectangle or other object showing extent of each of a few levels with each level saved as a view I'll take a shot at posting something using VIEWSIZE that may work.

Similar Threads

  1. Modify Floors > Modify Sub Elements
    By diesellam in forum Revit Architecture - General
    Replies: 3
    Last Post: 2010-02-23, 01:53 PM
  2. Assign a shortcut key to a toolbar macro
    By claus in forum AutoCAD Customization
    Replies: 3
    Last Post: 2007-05-14, 11:40 AM
  3. Replies: 7
    Last Post: 2007-02-05, 01:11 PM
  4. Replies: 6
    Last Post: 2006-04-03, 07:19 AM
  5. Hot key/shortcut key for Polar, Osnap & Otrack
    By son.do in forum AutoCAD Customization
    Replies: 5
    Last Post: 2005-01-26, 06:30 PM

Tags for this Thread

Posting Permissions

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