Lisp in MNS menu file

Discussion in 'AutoCAD' started by devon, Jan 10, 2005.

  1. devon

    devon Guest

    Hi,

    I am trying to get an "if" statement working in my mns file but not having too much luck.

    Basiclly, i am inserting a symbol (block) from a location on the server and I want the "if" statement to go "if no exist, then insert same named block from this other location"

    Here is the code I am currently using...
    Which get's the block from the expansion of the "libpref"
    eg. p:/tools/cad/"

    [symbols(dttitle,Detail title)]^C^C(stdins (strcat libpref "lib/stdsym/dttitle"))

    Any help would be most appreciated.

    Regards,
    Devon
     
    devon, Jan 10, 2005
    #1
  2. devon

    Tom Smith Guest

    Basiclly, i am inserting a symbol (block) from a location on the server
    and I want the "if" statement to go "if no exist, then insert same named
    block from this other location"
    Here is the code I am currently using...
    Which get's the block from the expansion of the "libpref"
    eg. p:/tools/cad/"
    [symbols(dttitle,Detail title)]^C^C(stdins (strcat libpref
    "lib/stdsym/dttitle"))

    Personally, I wouldn't do any more inline lisp in the menu than what you
    already have. Menus can quickly get cluttered up with a lot of repetitive
    lisp, which can become a maintenance issue. For instance, you may want this
    same kind of block insertion behavior for other kinds of blocks in other
    menu items. I'd move the lisp to an MNL file of the same name.

    I'm not really clear on your question, but maybe you want something like
    this (untested):

    (defun altins (blockname 1stlocation 2ndlocation / filename)
    (and
    (setq filename
    (cond
    ((findfile (strcat 1stlocation blockname ".dwg")))
    ((findfile (strcat 2ndlocation blockname ".dwg")))
    )
    )
    (stdins filename)
    )
    )

    Then in the menu you'd call it like:

    [symbols(dttitle,Detail title)]^C^C(altins "dttitle" (strcat libpref
    "lib/stdsym/") fallbackfolder);

    Assuming that fallbackfolder is defined in a manner similar to libpref. I
    wonder about the extra folder branches after libpref -- do standard symbols
    ever get inserted from anywhere besides the stdsym folder? If not, another
    variable would save some repetitive coding, such as:

    [symbols(dttitle,Detail title)]^C^C(altins "dttitle" standardfolder
    fallbackfolder);

    Or perhaps this whole alternate folder scenario could go into the stdins
    routine.
     
    Tom Smith, Jan 10, 2005
    #2
  3. devon

    ECCAD Guest

    Change:
    [symbols(dttitle,Detail title)]^C^C(stdins (strcat libpref "lib/stdsym/dttitle"))
    to:
    [symbols(dttitle,Detail title)]^C^C(if (findfile (strcat libpref "lib/stdsym/dttitle.dwg"))(stdins (strcat libpref "lib/stdsym/dttitle"))(stdins (strcat libpref "lib/stdsym/other_one")))

    ----------- remove the line-feeds, make it one long line.

    Bob
     
    ECCAD, Jan 10, 2005
    #3
  4. devon

    devon Guest

    Hi,

    Thankd for the reply.

    I am afraid this is not working correctly.

    [symbols(dttitle,Detail title)]^C^C(if (findfile "dttitle")(stdins (strcat projpref (nth project_val projnm_sym) "/drawings/standards/ProjSym/dttitle"))(stdins (strcat libpref "lib/stdsym/dttitle")))

    (strcat projpref (nth project_val projnm_sym) "/drawings/standards/ProjSym/dttitle")) is the path to the project directory where "DTTitle" should be.

    If not the look here...
    (stdins (strcat libpref "lib/stdsym/dttitle")))

    So Where am I going wrong?

    Thanks
    Devon
     
    devon, Jan 11, 2005
    #4
  5. Hi Devon,

    Copy your code into the VLIDE and step through it there. That way you will
    be able to identify where your code is working or not working. Once it is
    working you can put it in a Menu.mnl file as a defun and call it from there
    wit the MNS file, or copy it back to the MNS file.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Jan 11, 2005
    #5
  6. devon

    Tom Smith Guest

    Thanks Laurie. I neglected to mention the most obvious point about having a big glob of lisp in a menu item. Besides contributing to clutter and making menu maintainenance more difficult, it deprives you of the basic debugging tools that would be useful in getting the thing to work in the first place.
     
    Tom Smith, Jan 11, 2005
    #6
  7. devon

    devon Guest

    Thanks to all of you for the assistance.

    I have come up with a short term solution from your input and will implement the mnl solution over the coming weeks as time permits.

    this was my final outcome...

    (if (findfile (strcat projpref (nth project_val projnm_sym) "/drawings/standards/ProjSym/dttitle.dwg"))(stdins (strcat projpref (nth project_val projnm_sym) "/drawings/standards/ProjSym/dttitle"))(stdins (strcat libpref "lib/stdsym/dttitle")))

    Regards,
    Devon
     
    devon, Jan 11, 2005
    #7
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.