Jump to content

What is the problem with this lisp and how to correct it?


Recommended Posts

Posted (edited)

AutoCAD keeps giving me "malformed list on input" error. Thanks in advance.

 

(defun c:PlaceBlock (/ blkname pt ss x y dist layers selLayer selBlock blkList)
  (setq blkList '("SELECT BLOCK" "DIN_A3" "DIN_A4" "DIN_A5" "DIN_A6" "DIN_A7")) ; current bloks
  (setq layers (append '("SELECT LAYER") (mapcar 'cdr (vl-sort (acad_active_document_layers) 'string<)))) ; current layers
  (setq selBlock "SELECT BLOCK")
  (setq selLayer "SELECT LAYER")

  (setq blkname (cadr (assoc (if (setq selBlock (cond ((findfile (strcat (getvar "dwgprefix") "blocks\\" (strcat selBlock ".dwg"))) selBlock) (t (get_string "\nEnter block name: "))))(if (setq selBlock (cond ((findfile (strcat (getvar "dwgprefix") "blocks\\" (strcat selBlock ".dwg"))) selBlock) (t (get_string "\nEnter block name: ")))) blkList)))
  (setq selLayer (cdr (assoc (get_tile "layerList") layers)))

  (setq ss (ssget "_C" (getpoint "\nSelect insertion point: ")))
  (setq x (getreal "\nEnter x distance between blocks: "))
  (setq y (getreal "\nEnter y distance between blocks: "))
  (setq dist (getint "\nEnter number of blocks to place: "))

  (if (and (/= blkname nil) (/= selLayer nil))
    (progn
      (command "_.undo" "_begin")
      (repeat dist
        (command "_insert" blkname ss "" "" "" x y "" (strcat "LAYER" selLayer))
        (setq pt (trans (list x y 0) 0 1 ss))
        (setq ss (ssadd pt ss))
      )
      (command "_.undo" "_end")
    )
  )
  (princ)
)

(defun acad_active_document_layers ()
  (mapcar 'cdr (tblsearch "LAYER" (tblobjname "LAYER" "ACAD_DOCUMENT")))
)

(defun get_tile (tile)
  (cdr (assoc tile (acet-ui-dialog-show
    "LISP Place Block"
    '((layerList ("Layer:" . "SELECT LAYER"))
      (blockList ("Block:" . "SELECT BLOCK"))
    )
    '((ok-button . true) (cancel-button . true) (title . "Place Block"))
  ))))

(command "_.LISP" "c:PlaceBlock")


 

Edited by SLW210
Code Tags!!
Posted (edited)

I don't know will it work or not, but I've changed it - little more obvious... Malformed error occur if you don't have brackets open/closed at right places... Please use code tags next time you post a code...

 

(defun c:PlaceBlock ( / blkname pt ss x y dist layers selLayer selBlock blkList )

  (setq blkList '("SELECT BLOCK" "DIN_A3" "DIN_A4" "DIN_A5" "DIN_A6" "DIN_A7")) ; current bloks
  (setq layers (append '("SELECT LAYER") (vl-sort (acad_active_document_layers) '<))) ; current layers
  (setq selBlock "SELECT BLOCK")
  (setq selLayer "SELECT LAYER")

  (setq blkname
    (car
      (member
        (setq selBlock (cond ((findfile (strcat (getvar "dwgprefix") "blocks\\" (strcat selBlock ".dwg"))) selBlock) (t (getstring "\nEnter block name: "))))
        blkList
      )
    )
  )
  (setq selLayer (cdr (assoc (get_tile "layerList") layers)))

  (prompt "\nPick block to make diagonal array...")
  (setq ss (ssget "+._:E:S" (list (cons 0 "INSERT"))))
  (setq x (getreal "\nEnter x distance between blocks: "))
  (setq y (getreal "\nEnter y distance between blocks: "))
  (setq dist (getint "\nEnter number of blocks to place: "))
  (setq pt (cdr (assoc 10 (entget (ssname ss 0)))))

  (if (and blkname selLayer)
    (progn
      (command "_.undo" "_begin")
      (repeat dist
        (command "_.insert" blkname ss "" "_non" pt "" "" (strcat "LAYER" selLayer))
        (setq pt (mapcar '+ (list x y 0) pt))
      )
      (command "_.undo" "_end")
    )
  )
  (princ)
)

(defun acad_active_document_layers ( / layname laynames )
  (while (tblnext "LAYER" (not layname))
    (setq laynames (cons layname laynames))
  )
  laynames
)

(defun get_tile (tile)
  (cdr (assoc tile (acet-ui-dialog-show
    "LISP Place Block"
    '((layerList ("Layer:" . "SELECT LAYER"))
      (blockList ("Block:" . "SELECT BLOCK"))
    )
    '((ok-button . true) (cancel-button . true) (title . "Place Block"))
  )))
)

 

 

This is for rectangular array (if it works)...

 

(defun c:PlaceBlock ( / blkname pt ss x y dist layers selLayer selBlock blkList )

  (setq blkList '("SELECT BLOCK" "DIN_A3" "DIN_A4" "DIN_A5" "DIN_A6" "DIN_A7")) ; current bloks
  (setq layers (append '("SELECT LAYER") (vl-sort (acad_active_document_layers) '<))) ; current layers
  (setq selBlock "SELECT BLOCK")
  (setq selLayer "SELECT LAYER")

  (setq blkname
    (car
      (member
        (setq selBlock (cond ((findfile (strcat (getvar "dwgprefix") "blocks\\" (strcat selBlock ".dwg"))) selBlock) (t (getstring "\nEnter block name: "))))
        blkList
      )
    )
  )
  (setq selLayer (cdr (assoc (get_tile "layerList") layers)))

  (prompt "\nPick block to make rectangular array...")
  (setq ss (ssget "+._:E:S" (list (cons 0 "INSERT"))))
  (setq x (getreal "\nEnter x distance between blocks: "))
  (setq y (getreal "\nEnter y distance between blocks: "))
  (setq dist (getint "\nEnter number of blocks to place: "))
  (setq pt (cdr (assoc 10 (entget (ssname ss 0)))))

  (if (and blkname selLayer)
    (progn
      (command "_.undo" "_begin")
      (repeat dist
        (repeat dist
          (command "_.insert" blkname ss "" "_non" pt "" "" (strcat "LAYER" selLayer))
          (setq pt (mapcar '+ (list x 0 0) pt))
        )
        (setq pt (mapcar '+ (list (- (* dist x)) y 0) pt))
      )
      (command "_.undo" "_end")
    )
  )
  (princ)
)

(defun acad_active_document_layers ( / layname laynames )
  (while (tblnext "LAYER" (not layname))
    (setq laynames (cons layname laynames))
  )
  laynames
)

(defun get_tile (tile)
  (cdr (assoc tile (acet-ui-dialog-show
    "LISP Place Block"
    '((layerList ("Layer:" . "SELECT LAYER"))
      (blockList ("Block:" . "SELECT BLOCK"))
    )
    '((ok-button . true) (cancel-button . true) (title . "Place Block"))
  )))
)

 

Edited by marko_ribar
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...