Loading Laydel in a lisp

Discussion in 'AutoCAD' started by dth, Dec 14, 2004.

  1. dth

    dth Guest

    I am trying to add a function to a "file cleaning" lisp for our firm. I
    wanted to use the Express Tools' Laydel to expedite the process. I have
    been having some trouble getting it to run - I keep getting the "unknown
    command" error. There has to be a way to get it to work .... has anyone
    figured this out?

    Here is what I have been trying:

    (if (tblsearch "LAYER" "_kti_control")
    (command "-layer" "t" "_kti_control" "u" "_kti_control" "ON"
    "_kti_control" ""))

    (autoload "Lydelmrg") <--------------------

    (Command "laydel" "t" "_kti_control" "" "y")
     
    dth, Dec 14, 2004
    #1
  2. try:
    (c:laydel)

    or

    (c:laymrg)

    I'm using autocad 2004 and there is no express tools command 'laydelmrg'
    this is a subroutine in the lisp (if I remember correctly)

    Casey
     
    Casey Roberts, Dec 14, 2004
    #2
  3. dth

    ECCAD Guest

    I'm not familiar with the program, but you could try:
    (laydel "t" "_kti_control" "" "y")
    or
    (C:laydel "t" "_kti_control" "" "y")

    Bob
     
    ECCAD, Dec 14, 2004
    #3
  4. dth

    dth Guest

    Thanks to both of you! ..... I think it is working well like this:

    (if (tblsearch "LAYER" "_kti_control")
    (command "-layer" "t" "_kti_control" "u" "_kti_control" "ON"
    "_kti_control" "")
    (c:laydel "t" "_kti_control" "" "y"))
     
    dth, Dec 14, 2004
    #4
  5. dth

    dth Guest

    Seems as though it's not cooperating here. I run the lsp and get "too many
    arguements"
    Here is the code:

    ;Cleans Drawing with purge and audit
    (defun c:cl()

    (setvar "cmdecho" 0)

    (setq $cla (getvar "clayer"))

    (setvar "clayer" "0")

    (if (tblsearch "LAYER" "_kti_control")
    (command "-layer" "t" "_kti_control" "u" "_kti_control" "ON"
    "_kti_control" "")
    (c:laydel "t" "_kti_control" "" "y"))

    (if (tblsearch "LAYER" "Ame_Frz")
    (command "-layer" "t" "Ame_Frz" "u" "Ame_Frz" "ON" "Ame_Frz" "")
    (c:laydel "t" "Ame_Frz" "" "y"))

    (command "audit" "y")
    (command "-purge" "a" "" "n")
    (command "-purge" "a" "" "n")
    (command "qsave")

    (setvar "clayer" $cla)
    (setvar "cmdecho" 1)
    (princ)
    )
     
    dth, Dec 14, 2004
    #5
  6. dth

    ECCAD Guest

    Here's your problem. The Lisp just keeps chugging along..
    After running the C:laydel function. It then feeds in the
    remaining lisp statements..as input to the laydel function..
    not good. What you need to do is to check the Cmdactive
    variable, and wait for the C:laydel function to exit, .. then
    continue. Search for Cmdactive in this news group..and
    apply (if > (getvar "cmdactive") 0......... in your program.

    Bob
     
    ECCAD, Dec 14, 2004
    #6
  7. dth

    Joshua Tapp Guest

    I wrote something similar back when I worked in an office that previously
    used Ketiv, which is where that layer comes from. Are you already deleting
    the hidden block (can't recall the name of it off the top of my head)? I
    remember I had to do a search to find which blocks in the drawing also had
    them, and then have it alert me as to which blocks I needed to clean.
     
    Joshua Tapp, Dec 15, 2004
    #7
  8. dth

    Joe Burke Guest

    If I understand what you're trying to do, there's a missing a progn call in both if
    functions.
    If the layer is found, thaw, unlock, etc. If it's not found, run laydel. Hmm... :)

    Joe Burke
     
    Joe Burke, Dec 15, 2004
    #8
  9. dth

    dth Guest

    Yeah, I saw that ... I changed it to:

    (if (tblsearch "LAYER" "_kti_control")
    (command "-layer" "t" "_kti_control" "u" "_kti_control" "ON" "_kti_control"
    ""))

    (if (tblsearch "LAYER" "_kti_control")
    (c:laydel "t" "_kti_control" "" "y"))

    Would I still need the PROGN function then? It says you can use progn to
    evaluate several expressions where only one expression is expected. I think
    only one is expected and, therefore is unnecessary.
     
    dth, Dec 15, 2004
    #9
  10. dth

    dth Guest

    In 2004, the audit exposes the hidden block and the purge kills it. Don't
    have to use something like Superpurge anymore. Actually the second purge
    command is seemingly unnecessary ... just a safety net.
     
    dth, Dec 15, 2004
    #10
  11. dth

    Joe Burke Guest

    Progn isn't needed given your example below. Just keep in mind, it's not as efficient
    as it would be using progn, because the same expression is evaluated twice.

    The difference speedwise would be meaningless. But the difference in terms of how you
    think about it has meaning, if code is more than a casual acquaintance.

    Joe Burke
     
    Joe Burke, Dec 16, 2004
    #11
  12. dth

    dth Guest

    Ok ... I'm lost, how should properly be written?

     
    dth, Dec 16, 2004
    #12
  13. dth

    Joe Burke Guest

    I would write it like this.

    (if (tblsearch "LAYER" "_kti_control")
    (progn
    (command "-layer" "t" "_kti_control" ...)
    (c:laydel "t" "_kti_control" "" "y")
    )
    )

    As you mentioned, progn is used to evaluate several expressions where only one is
    expected. It's often used with IF because only two expressions are allowed after test
    expression, then and else. In the case above, progn allows multiple then expressions.
    The optional else expression isn't used.

    If else was needed, it could also be nested in a progn, if multiple else expressions
    were needed.

    (if (test expression)
    (progn
    (then this)
    (and then this)
    )
    (progn
    (else this)
    (and else this)
    )
    )

    Hope that's clear.
    Joe Burke
     
    Joe Burke, Dec 17, 2004
    #13
  14. dth

    dth Guest

    Thanks for your help. As I get farther into writing stuff, I realize how
    little I know. I think I understand how the progn works now. It allows me
    to do several commands within the if/then. If I did not use it, I would
    have to do this:

    (if (test expression)
    (do this)

    (if (test expression)
    (do this)
    etc .....

    Earlier in the discussion, Bob was talking about the cmdactive in regards to
    a "too many arguments" error. I am trying to understand that too. Would it
    then be written like the example below or can you do an if within an if?

    (if > (getvar "cmdactive") 0
    (if (test expression)
    (progn
    (then this)
    (and then this)
    )
    )
    or in context:

    (if > (getvar "cmdactive") 0
    (if (tblsearch "LAYER" "_kti_control")
    (progn
    (command "-layer" "t" "_kti_control" ...)
    (c:laydel "t" "_kti_control" "" "y")
    )
    )
    )
     
    dth, Dec 17, 2004
    #14
  15. dth

    dth Guest

    Here is the code to date. I tried inserting the cmdactive based on what I
    have read here, but whe I run it, I get "too many arguements" and if I leave
    it out, I get "too few arguements" ... what do I need to do to get the
    right amount of arguements "-)?

    ;Cleans Drawing with purge and audit
    (defun c:cl($cla)

    (setvar "cmdecho" 0)

    (setq $cla (getvar "clayer"))

    (setvar "clayer" "0")

    (if (tblsearch "LAYER" "_kti_control")
    (progn
    (command "-layer" "t" "_kti_control" "u" "_kti_control" "ON"
    "_kti_control" "")
    (c:laydel "t" "_kti_control" "" "y")
    )
    )

    (if (tblsearch "LAYER" "Ame_Frz")
    (progn
    (command "-layer" "t" "Ame_Frz" "u" "Ame_Frz" "ON" "Ame_Frz" "")
    (c:laydel "t" "Ame_Frz" "" "y")
    )
    )

    (if (tblsearch "LAYER" "Ashade")
    (progn
    (command "-layer" "t" "Ashade" "u" "Ashade" "ON" "Ashade" "")
    (c:laydel "t" "Ashade" "" "y")
    )
    )

    (if> (getvar "cmdactive") 0
    (progn
    (command "audit" "y")
    (command "-purge" "a" "" "n")
    (command "-purge" "a" "" "n")
    (command "qsave")
    )
    )

    (setvar "clayer" $cla)
    (setvar "cmdecho" 1)
    (princ)
    )
     
    dth, Dec 17, 2004
    #15
  16. dth

    Joe Burke Guest

    I believe Bob was mistaken about "cmdactive" playing some role in the problem you are
    having with calling the Express Tools laydel command from within your routine.

    As far as I know, you can start the laydel command, but you can't pass arguments.
    You'll have to respond to the laydel prompts at the command line. Here's an example.

    (defun c:test ( )
    (c:laydel) ;respond to prompts
    (command "pline")
    (while (> (getvar "cmdactive") 0) (command pause))
    )

    Notice, the function waits for the laydel command to complete before the pline
    command starts. And it does so without using (getvar "cmdactive").

    I've included the pline command just to demonstrate how what Bob referred to is
    typically used. It allows the pline command to continue until the user ends the
    command.

    Joe Burke
     
    Joe Burke, Dec 18, 2004
    #16
  17. dth

    ECCAD Guest

    New problem:
    (if> (getvar "cmdactive") 0
    (progn
    ------ should be:
    (if> (getvar "cmdactive") 0)
    (progn
    ------- notice the closing ) on if statement.

    Bob
     
    ECCAD, Dec 19, 2004
    #17
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.