User Defined Program

Discussion in 'AutoCAD' started by miketalbott, Mar 23, 2005.

  1. miketalbott

    miketalbott Guest

    I have been working on a layer utility for our whole office to use which switches quickly between different layer configurations (i.e. we stack our floor plans and I have it set up that the keyboard command "1" shows the first floor, "2" shows the second, etc.) I am adding dialog functionality to the program and would like to give users the ability to create there own layer state shortcuts.

    My questions is, How can I have my program create a second program using and user supplied variable as the name of the function and ultimately the command that they would type.

    Ex: (defun c:{insert here user supplied name from dialog} (/)...
     
    miketalbott, Mar 23, 2005
    #1
  2. miketalbott

    ECCAD Guest

    Are you trying to 'write' a Lisp file..to be loaded later ?
    If so, why not (setq out (strcat "(defun c:" user_var " ( / )"))
    where, 'user_var' is just a string from Dialog , then, write-line out out-file..
    Bob
     
    ECCAD, Mar 23, 2005
    #2
  3. miketalbott

    miketalbott Guest

    thanks for the quick response

    hmm... I think write-line would work but it seems like a work around. Yes, I could have my program write the new program to a new file then load the file at the end of the original progragm but I was hoping there was a a way to do something similar with a strcat call but I wouldn't have to outsource it to a separate file.
     
    miketalbott, Mar 23, 2005
    #3
  4. miketalbott

    ECCAD Guest

    I think you 'do' have to outsource it. Since it lives in Lisp,
    (ascii text file), you can 'load' it, but you cannot (on the fly),
    'define' it..if you know what I mean.
    You could always 'dos-delete' it once loaded, if that is
    where you are going..
    Bob
     
    ECCAD, Mar 23, 2005
    #4
  5. miketalbott

    Tom Smith Guest

    I do something similar to automatically generate functions for inserting blocks.

    I have a library utility for inserting a block with an optional rotation prompt, which has the syntax (insc <blockname> <scalefactor> <r-prompt>) for example (insc "door" 1 t). Then I have a macro-writing function as follows:

    (defun writemacro (blknam rotation / macroname)
    (setq macroname (strcat "c:" blknam))
    (eval (read (strcat
    "(defun "
    macroname
    "()(insc \""
    blknam
    "\" 1 "
    (if rotation
    "t"
    "nil")
    "))"))))

    (Note that this assumes a unit insertion scale.) For example, if called by (writemacro "door" t) it will create a function of the form (defun c: door () (insc "door" 1 t)).

    I use this to automatically generate large numbers of macros, whereby you can insert a block by typing its name. You can build a list of filenames in a folder, for instance, and apply the macro-writing function on all the names.
     
    Tom Smith, Mar 23, 2005
    #5
  6. miketalbott

    miketalbott Guest

    sweet. thanks.
     
    miketalbott, Mar 23, 2005
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.