run script file through lisp routine

Discussion in 'AutoCAD' started by jhendershot, Jun 29, 2004.

  1. jhendershot

    jhendershot Guest

    new to this so bear with me.

    i wrote a script file to automate creating new layers with specific color and line types. what i want to do is to get it mapped to a key, say 'SB', so i don't' have to type in 'scr' then find the file to run it. iam sure there is an easy way to do this with a lisp routine. or if there is another way that would be more beneficial iam open to suggestions.

    thanks.
     
    jhendershot, Jun 29, 2004
    #1
  2. jhendershot

    ECCAD Guest

    (defun C:SB ()
    (if (findfile "C:/path/yourscript.scr")
    (command "_script" "C:/path/yourscript.scr")
    ); end if
    ); end function

    Should do it.

    Bob
     
    ECCAD, Jun 29, 2004
    #2
  3. jhendershot

    David Bethel Guest

    (defun c:sb ()
    (command "_.SCRIPT" "my_script")
    (prin1))

    Just don't try and run any Autolisp calls after the (command) call.

    -David
     
    David Bethel, Jun 29, 2004
    #3
  4. jhendershot

    Tom Smith Guest

    Alternatively you could rewrite the script as lisp, and accomplish the same
    thing with one file instead of two:

    (defun c:sb()
    (command "layer" "make" "mylayer" "color" "red" "")
    ;etc
    ;etc
    )

    This could go in your acad(doc).lsp and wouldn't require the separate
    script. Whatever is in your script file should be adaptable to the (command)
    functions without much trouble.
     
    Tom Smith, Jun 29, 2004
    #4
  5. jhendershot

    C Witt Guest

    do you one better..
    (defun c:sb ()
    (setq myLayers
    (list
    (list "pl" "red" "Continuous")
    (list "contours" "9" "hidden")
    (list "el" "red" "Continuous")
    (list "ant" "magenta" "Continuous")
    (list "steel" "cyan" "Continuous")
    (list "eq" "123" "Continuous")
    (list "ha" "9" "Continuous")
    (list "grid" "9" "Continuous")
    (list "tray" "blue" "Continuous")
    (list "gnd" "72" "Continuous")
    (list "power" "140" "Continuous")
    (list "bolts" "yellow" "Continuous")
    (list "fence" "cyan" "Continuous")
    (list "vp" "white" "Continuous")
    (list "tree" "green" "Continuous")
    (list "text" "yellow" "Continuous")
    )
    )
    (foreach laydata myLayers
    (command "_layer" "_make" (car laydata) "_color" (cadr laydata) (car
    laydata) "_lt" (caddr laydata) (car laydata) "")
    )
    )
     
    C Witt, Jun 29, 2004
    #5
  6. jhendershot

    Tom Smith Guest

    do you one better.

    I know better ways to do this. By preference, I personally wouldn't use the
    command function at all. For one thing, unless this is wrapped in an undo
    group, it will have the same undo problem that you described in another
    thread: every single layer command will have to be undone separately. 16 U's
    for one function!

    There are any number of ways the same thing could be accomplished. The
    simplest is probably be to use the built-in layer states mechanism. My own
    menu macro imports and restores a predefined layer state from an external
    file.

    But the post asked for suggestions on running a script, and made it plain
    that the poster was "new to this." So my suggestion was to rewrite the
    script as a lisp, which wouldn't require two files to do one thing. If there
    is already a working script, it is probably something of the form:

    layer make <name> color <number> etc

    which would be easy even for a non-programmer to adapt to

    (command "layer" "make" "<name>" "color" "<number>" etc)

    I was trying to keep it simple, not illustrate my mastery.

    IMHO this thread has already gone into way too much confusing and
    unnecessary detail with all that findfile business on the scripting
    approach. David Bethel's the only one who got it right. The poster is in a
    known environment and doesn't have any need to test "if" a script can be
    found where it's supposed to be -- what's it going to do, walk away?? Since
    the script is known to be on the search path, all the lisp needs to say is
    (command "script" "sbuxsetup").
     
    Tom Smith, Jun 29, 2004
    #6
  7. jhendershot

    C Witt Guest

    just posted the one we use, thought it would work better. wasn't trying
    to "illustrate my mastery".. i'm a novice at best ;)
     
    C Witt, Jun 29, 2004
    #7
  8. jhendershot

    Tom Smith Guest

    just posted the one we use

    An even simpler approach is to insert a block which contains all the
    standard layers. It can be an empty drawing but with the layers defined. The
    only complication is that this won't redefine any exiting layers in the
    present drawing which conflict with the standard. But if you know you're
    stating with a new blank drawing, it will work. However....

    Backing up still further, the simplest solution of all is to start drawings
    from a template which already contains the proper layers. Lately I've seen
    several people's methods for making "new" layers, and I continue to be
    baffled by this approach. Why should the same task need to be redone in
    every single drawing, when the drawing could just as easily be created with
    this work already done? That's the whole idea of templates.

    The only reason we've needed a layer-fixing routine is to restore the normal
    settings in a file that has been messed with or damaged somehow -- for
    instance, prematurely purged of layers that are needed later. It's not
    something that happens very often. Our solution is to import and restore a
    layer state from an external las file, which was exported from one of our
    template drawings. This didn't require any programming, and uses nothing but
    built-in Acad mechanisms.
     
    Tom Smith, Jun 29, 2004
    #8
  9. jhendershot

    ECCAD Guest

    It is entirely possible that the 'scripname' in question (could) reside in more than (1) place. It is 'good' to check explicitly, rather than 'assume'.
    <Rant/>

    Bob
     
    ECCAD, Jun 29, 2004
    #9
  10. jhendershot

    Walt Engle Guest

    Why run a script when you can do this with acad.lsp? Acad.lsp loads automatically, allowing you to pre-set styles, fonts, text heights and colors, layers with linetypes and colors, any variable that you want which is not a default and even setup whether you want mechanical or architectural settings.
    Acad.lsp loads each time you start autocad, open an existing dwg or start a new dwg. It simplifies so much of your work and you can go back and change anything it pre-sets. Want one?
     
    Walt Engle, Jun 29, 2004
    #10
  11. jhendershot

    Tom Smith Guest

    It is entirely possible that the 'scripname' in question (could) reside in
    more than (1) place

    Anything is possible. The findfile function itself could have been redefined
    so that it doesn't work as "assumed." (defun findfile (filename) nil). What
    then?

    Having an ostensibly company-standard file floating around in various guises
    or multiple places unexpectedly is a separate standards and file-management
    issue, in my view. I don't see how this could work or why it would be
    permitted. This isn't a "user preference" deal. Where the correct file is
    located should be knowable. At least it ought to be knowable that there's
    only one by that name on the search path. There shouldn't be any uncertainty
    about which conflicting setup script might "possibly" be found and run when
    you start to set up a drawing to company standards.

    IMHO, assuming this is no more risky than assuming that findfile will work.
    At some point you have to "assume" something other than chaos in order to
    get anything done.

    One of the advantages of having a known support file search path is that you
    can avoid hard-coding file paths in your programs. This creates a
    maintenance nightmare. If you really want to go looking for the file, I
    think it's preferable to do something like this:

    (if (setq fullpath (findfile "sbuxsetup.scr"))
    (command "script" fullpath))

    This lets the lisp fill in the actual path where the script resides. You can
    move the script to a different drive and this will still work, as long as
    the new location is on the search path. I prefer to never use any hard-coded
    paths in lisps or menus.
     
    Tom Smith, Jun 29, 2004
    #11
  12. jhendershot

    ECCAD Guest

    Walt,
    Just a thought. If the poster (always) needed a particular layer convention, he could do it with either inserting a drawing with layers defined, or using a template, or even loading a lisp function during start-up. But, if the poster needs a way to 'map' the layers into a customer's requirements, then the script (or loading a particular lisp) is the way to go.

    Bob
     
    ECCAD, Jun 29, 2004
    #12
  13. jhendershot

    Tom Smith Guest

    Just a thought. If the poster (always) needed a particular layer
    convention, he could do it with either inserting a drawing with layers
    defined, or using a template, or even loading a lisp function during
    start-up. But, if the poster needs a way to 'map' the layers into a
    customer's requirements, then the script (or loading a particular lisp) is
    the way to go.

    In an earlier post I described the first two as easier (insert a block) and
    easiest (use a template). Running anything on startup that makes big changes
    in the drawing setup without the user's intent is not something I would do.

    For differing layer requirements, the layer state feature in recent versions
    ought to replace a lot of the custom programs that people used to have to
    write. That's what we use in the uncommon situations where we need to fix a
    messed-up drawing.
     
    Tom Smith, Jun 29, 2004
    #13
  14. jhendershot

    jhendershot Guest

    the thing is we have multiple corporate clients that have their own standards, different for each one. this way allows us to load each one with just a command. also most of the time the drawings we get from the corporate office aren't drawn to their own standards, so opening an existing drawing we can just type a command and have all the correct standards inserted to change things to. plus this allows for us to purge the drawing and then insert all the layers back into the drawing without much hassle of messing with template files or importing another block with all the info.
     
    jhendershot, Jun 29, 2004
    #14
  15. jhendershot

    Walt Engle Guest

    Not necessarily. Acad.lsp can be changed to fit the circumstances much easier than changing a script file and it's a whole lot cleaner and quicker.
     
    Walt Engle, Jun 29, 2004
    #15
  16. jhendershot

    Tom Smith Guest

    Not necessarily. Acad.lsp can be changed to fit the circumstances much
    easier than changing a script file and it's a whole lot cleaner and quicker.

    Cleaner and quicker than that, and requiring no programming:

    Identify one properly set up drawing. In the Layer Manager, save that state
    and export it to an las file, probably named by client. Open a bad file,
    import the appropriate las file and restore it. It takes longer to write
    this than it does to do it.

    There can be multiplelayer state files for each of his corporate clients.
    When corporate's files don't meet their own standards, they can be fixed by
    importing the correct layer state. This amounts to the same thing as the
    script mechanism, but doesn't require any typing or debugging to maintain,
    since it uses a built-in Acad feature rather than a hand-customized file.
     
    Tom Smith, Jun 29, 2004
    #16
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.