Results 1 to 3 of 3

Thread: Help to finish code to work

  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Help to finish code to work

    Hi everyone,

    I'm trying to write a code that will let the user select a new block and then the block that needs to be replaced. Ask if the user wants to replace all of the blocks that match the block to be replaced or only the blocks that are in a window selection and don't replace other blocks that are also in the same window.

    The code is not working and I'm getting
    ; error: malformed list on input
    Code:
    (defun c:blkreplace ()
      (setq oldblk (ssget "_X" '((0 . "INSERT"))))
      (if (not oldblk)
          (progn
            (princ "\nNo old block selected.")
            (exit)
          )
      )
    
      (setq newblk (ssget "_X" '((0 . "INSERT"))))
      (if (not newblk)
          (progn
            (princ "\nNo new block selected.")
            (exit)
          )
      )
    
      (setq sset (ssget))
      (setq entsel (sslength sset))
      (setq selblk (ssget "_X" '((0 . "INSERT"))))
      
      (setq allsel (strcase (getstring "\nChange all blocks in drawing? [Y/N] ")))
      
      (while (not (or (equal allsel "Y") (equal allsel "N")))
        (setq allsel (strcase (getstring "Invalid selection. Enter Y to change all blocks or N to select manually: ")))
      )
    
      (if (equal allsel "Y")
          (setq selblk (ssget "_X" '((0 . "INSERT"))))
        (progn
          (while (not selblk)
            (setq selblk (ssget "\nSelect blocks to replace: " '((0 . "INSERT"))))
          )
      )
    
      (setq cnt 0)
      
      (repeat entsel
        (setq entname (ssname sset (setq i (1- i))))
        (setq ent (entget entname))
        
        (dolist (elist ent)
          (when (eq (type elist) 'ENAME)
            (setq elist (entget (car elist)))
            (when (eq "INSERT" (cdr (assoc 0 elist)))
              (setq name (cdr (assoc 2 elist)))
              (if (or (equal allsel "Y") (member name (mapcar 'cdr (entget selblk))))
                  (if (equal name (cdr (assoc 2 oldblk)))
                      (progn
                        (setq pos (cdr (assoc 10 elist)))
                        (setq rot (cdr (assoc 50 elist)))
                        (setq scale (cdr (assoc 41 elist)))
                        (setq cnt (1+ cnt))
                        
                        (setq entnew (entmakex elist))
                        (command "_.change" entnew "" "" "" (cdr (assoc 2 newblk)) "" "" "" "")
                        (command "_.scale" entnew pos scale "")
                        (command "_.rotate" entnew pos rot "")
                      )
                    )
                )
              )
            )
          )
        )
      
      (if (= 0 cnt)
          (princ "\nNo matching blocks found in drawing.")
          (princ (strcat "\n" (itoa cnt) " block(s) replaced."))
      )
    
      (if (equal allsel "Y")
          (repeat (setq cnt (sslength (setq allblk (ssget "X" (list (cons 0 "INSERT"))))))
            (setq blkname (cdr (assoc 2 (entget (ssname allblk (setq cnt (- cnt 1)))))))
            (if (eq (vla-get-objectname (vlax-ename->vla-object blkname)) "AcDbBlockReference")
                (command "_-insert" blkname pause pause pause pause pause pause pause "")
            )
          )
      )
    )
    
    (defun c:blkreplace_ui ()
      (blkreplace)
      (princ)
    )
    
    (princ "\nBlock Replace utility loaded.")
    (princ)
    Thanks for the help.

    Cadd4la

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,100
    Login to Give a bone
    0

    Default Re: Help to finish code to work

    Check your if statements and make certain the correct number of closing parenthesis are placed where they belong. I sometimes forget to add an extra closing parenthesis when adding a progn function as one of the branches of the if statement.

    If using the VLIDE, you can start at the end of your code and find the corresponding open parenthesis using the Edit menu -> Parenthesis Matching -> Select Backward option.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Member
    Join Date
    2015-10
    Location
    Alhambra
    Posts
    27
    Login to Give a bone
    0

    Default Re: Help to finish code to work

    You cannot do this
    (ssget "\nSelect blocks to replace: " '((0 . "INSERT")))
    You can do this
    (princ "\nSelect blocks to replace: " )
    (ssget '((0 . "INSERT")))

Similar Threads

  1. Help needed to finish code
    By cadd4la in forum AutoLISP
    Replies: 4
    Last Post: 2013-06-24, 09:36 PM
  2. Finish Layer 4 and Finish Layer 5
    By petervanko in forum Revit Architecture - General
    Replies: 2
    Last Post: 2006-08-07, 06:04 PM
  3. Roof Finish Schedule/Finish Key
    By ford347 in forum Revit Architecture - General
    Replies: 10
    Last Post: 2005-11-14, 02:23 PM
  4. Finish 1[4] vs Finish 2 [5]
    By fangelo in forum Revit Architecture - General
    Replies: 6
    Last Post: 2005-11-13, 09:55 PM
  5. What is corner finish type and host finish type
    By sbrown in forum Revit Architecture - General
    Replies: 1
    Last Post: 2004-03-04, 09:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •