Jump to content

Cannot Get This Lisp To Work on All Blocks in a DWG


YZ

Recommended Posts

We are trying to write a lisp that will set all blocks in a dwg to an X, Y, and Z scale value of 1.

 

By my reckoning it should work. But it only applies the scale change to one block in the dwg - the latest one that was inserted.

 

Do I need to loop through the selection set? I assumed it would apply the change to all in the selection automatically.

 

Thanks for any help. See below for code, and see attached a sample dwg that shows one block only changing.

 

(defun c:SCB ()
 ;(setvar "qaflags" 1)
;below selects all blocks 
 (setq ALLBLOCKS (ssget "X" (LIST (cons 0 "INSERT"))))
 ;(command "select" allblocks))
 (if  
       (progn
       (setq blocks (ssname ALLBLOCKS 0))
               (entmod ; modifies the properties of the entity
                   (append ; combines the list
                       (entget blocks); indicates what entity to edit
                       (list ; create a list of properties to change
                           (cons 41 1)
                           (cons 42 1)
               (cons 43 1)
                       )
                   )
               )
                   (entupd blocks); updates the block
       )
       (prompt "\nNo blocks in drawing!")
  )
 (princ)
 ;(setvar "qaflags" 0)
)

 

16-027Hkjkl.dwg

Link to comment
Share on other sites

Try this

 

;below selects all blocks 
(setq ALLBLOCKS (ssget "X" (LIST (cons 0 "INSERT"))))
 ;(command "select" allblocks))
(if  
       (progn
       (repeat (setq x (sslength allblocks))) 
       (setq blocks (ssname ALLBLOCKS (setq x (- x 1))))
               (entmod ; modifies the properties of the entity
                   (append ; combines the list
                       (entget blocks); indicates what entity to edit
                       (list ; create a list of properties to change
                           (cons 41 1)
                           (cons 42 1)
                           (cons 43 1)
                       )
                   )
               )
               (entupd blocks); updates the block
       ) 
       ) ; repeat ?
       (prompt "\nNo blocks in drawing!")
  ) ; progn
 (princ)
 ;(setvar "qaflags" 0)
) ; if 

 

Its just me but I put ) ; if its so I can keep track of the closing pairs makes it easier to add to code like this.

Link to comment
Share on other sites

  • 1 month later...

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...