Results 1 to 4 of 4

Thread: Dynamic function definition

  1. #1
    Active Member
    Join Date
    2008-02
    Location
    Toronto, On
    Posts
    59
    Login to Give a bone
    0

    Default Dynamic function definition

    Hey all,

    I've been able to write a function that dynamically created variables and stored values.

    Code:
    (defun GetAndStoreVariables ( / );Get and set variable values for functional stuff
      (foreach Pair (SomeVariables)
        (set (read (car Pair)) (cdr Pair))
        );end foreach
      (princ)
      );end defun
    
    (defun SomeVariables ( / )
        (list (cons "Var1" 123)
              (cons "Var2" 456)
              (cons "FrameWid" 1200.0)
              (cons "StandardSpacing" 100.0)
              )
       );end defun
    Does anybody know if it's possible to dynamically define functions?
    I'm currently trying the following:

    Code:
    (setq Cnt 0)
    
    (while (< (setq Cnt (1+ Cnt)) 10)
       (defun (read (strcat "C:" (itoa Cnt))) ( / )
             (body of function......)
             );end defun
        );end while
    But I keep getting "Syntax Error".

    Any thoughts?

  2. #2
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Dynamic function definition

    Here's one I did looong ago...

    Code:
    ;fillet with set radius
    ;Alan J. Thompson
    (mapcar
      '(lambda (f r)
         (eval (list 'defun
             f
             nil
             (list 'setvar "filletrad" r)
             (list 'princ (strcat "\nFillet radius set to: " (rtos r)))
             (list 'command "_.fillet")
             '(princ)
           )
         )
       )
      '(c:FF    c:F1    c:F15    c:F2    c:F3    c:F4    c:F45    c:F5    c:F6    c:F7    c:F8    c:F9)
      '(0        1    1.5    2    3    4    4.5    5    6    7    8    9)
    )
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  3. #3
    Active Member
    Join Date
    2008-02
    Location
    Toronto, On
    Posts
    59
    Login to Give a bone
    0

    Default Re: Dynamic function definition

    Thanks for the kick-start Alanjt. I got it working!

    Code:
    (setq Cnt 0)
    (while (< (setq Cnt (1+ Cnt)) 10)
      (eval (list 'defun
                    (read (strcat "C:" (itoa Cnt)))
    		nil
    		(list 'SetLayer (read (strcat "LAY:Detl" (itoa Cnt))))
    		'(princ)
    		);end list
    	  );end eval
        );end while

  4. #4
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Dynamic function definition

    Quote Originally Posted by JaCAD View Post
    Thanks for the kick-start Alanjt. I got it working!

    Code:
    (setq Cnt 0)
    (while (< (setq Cnt (1+ Cnt)) 10)
      (eval (list 'defun
                    (read (strcat "C:" (itoa Cnt)))
            nil
            (list 'SetLayer (read (strcat "LAY:Detl" (itoa Cnt))))
            '(princ)
            );end list
          );end eval
        );end while
    Glad to hear. You're welcome.
    Civil 3D 2017 ~ Windohz 7
    Dropbox

Similar Threads

  1. error: no function definition: C:AMPSNAPMID
    By Darren Allen in forum AutoCAD Mechanical - General
    Replies: 3
    Last Post: 2012-07-10, 12:17 PM
  2. no function definition: LAYOUTLIST
    By bestplace2 in forum AutoLISP
    Replies: 9
    Last Post: 2010-06-29, 05:37 PM
  3. function definition: CV_XLATLSPPHRASE
    By Hammer.John.J in forum AutoLISP
    Replies: 3
    Last Post: 2010-02-09, 05:15 PM
  4. formula function in property set definition
    By sam_ctlim in forum AMEP General
    Replies: 4
    Last Post: 2009-03-05, 11:07 PM
  5. error: no function definition: AUTOLOAD
    By dalej_k in forum AutoLISP
    Replies: 4
    Last Post: 2004-08-11, 11:58 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
  •