Block Insert lisp help

Discussion in 'AutoCAD' started by Jonk, Aug 16, 2004.

  1. Jonk

    Jonk Guest

    I have a small routine that inserts a specified block on a certain layer. What I need help with is inserting the block on the current layer or layer 0 if the specified layer does not exist. Here is the code that I am using. Please Help Thanks.

    (Defun C:blkins ( )
    (Setq Echo (Getvar"Cmdecho"))
    (Setvar"Cmdecho" 0)
    (Princ"\n- blockname -")
    (command "clayer" "layername")
    (Princ"\n -Layer layername")
    (Command "-Insert" "blockname" Pause (Getvar"Dimscale") "")
    (Setvar"Cmdecho" Echo)
    (Princ))
     
    Jonk, Aug 16, 2004
    #1
  2. Jonk

    T.Willey Guest

    (defun c:blkins (/ ocmd olay)
    (setq ocmd (getvar "cmdecho"))
    (setq olay (getvar "clayer"))
    (setvar "cmdecho" 0)
    (princ "\n-Block name-")
    (if (tblsearch "layer" "layername"); <- insert your layer name here
    (progn
    (command "_.layer" "m" "layername" "") <- insert your layer name
    (command "_.insert" "blockname" pause (getvar "dimscale") "") <- insert block name here
    )
    (progn
    (setvar "clayer" "0")
    (command "_.insert" "blockname" pause (getvar "dimscale") "") <- insert block name here
    )
    )
    (setvar "clayer" olay)
    (setvar "cmdecho" ocmd)
    (princ)
    )

    Try this.
    Tim
     
    T.Willey, Aug 16, 2004
    #2
  3. Jonk

    Jonk Guest

    Thanks for the response. This does not work for me. What I need is when the block is inserted it puts it on my layer first. It will only put the block on layer 0 if my layer is not found. The code you sent puts the block on layer 0 only. Thanks
     
    Jonk, Aug 16, 2004
    #3
  4. Jonk

    T.Willey Guest

    What is the layer you want the block on? and what is the block name? Did you type in your layer name in the spots where I told you to because that should work, but if you give me the other info then I can test it out here.

    Tim
     
    T.Willey, Aug 17, 2004
    #4
  5. Jonk

    Jonk Guest

    Thanks for the response. The block name is pwr01 and
    the layer it goes on is rjpwrcon. I put that info where it was stated, but the block ended up on layer 0. I only want it on layer 0 if layer rjpwrcon is not in the drawing. Thanks
     
    Jonk, Aug 17, 2004
    #5
  6. Jonk

    ECCAD Guest

    Try this modification to Tim's.

    ;The block name is pwr01 and
    ;the layer it goes on is rjpwrcon.
    (setq blockname "pwr01" layername "rjpwrcon")
    (blkins blockname layername)


    (defun blkins ( blockname layername / ocmd olay)
    (setq ocmd (getvar "cmdecho"))
    (setq olay (getvar "clayer"))
    (setvar "cmdecho" 0)
    (if (tblsearch "layer" layername)
    (progn
    (command "_.layer" "s" layername "")
    (command "_.insert" blockname pause (getvar "dimscale") "")
    );progn
    (progn
    (command "_.layer" "s" "0" "")
    (command "_.insert" blockname pause (getvar "dimscale") "")
    );progn
    );if
    (setvar "clayer" olay)
    (setvar "cmdecho" ocmd)
    (princ)
    )

    Bob
     
    ECCAD, Aug 17, 2004
    #6
  7. Jonk

    Jim Claypool Guest

    Or (blkins "pwr01" "rjpwrcon")
     
    Jim Claypool, Aug 17, 2004
    #7
  8. Jonk

    Jonk Guest

    I am getting too few arguments error with that code ?
    Thanks anyway
     
    Jonk, Aug 17, 2004
    #8
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.