Jump to content

Issue with LISP to change XYZ scale of specific block


K Baden

Recommended Posts

Good morning!

 

I am trying to get this code to work, but keep getting errors. I basically want something that will grab all blocks named ELEVATION MARKER and change the X, Y, and Z scaled to "1". Anyone have any idea why this isn't working?

 

(defun c:chgscl (/ factr ent)

(setq factr 1.0)

(IF
(setq ss (ssget "_X" '((0 . "INSERT") (2 . "ELEVATION MARKER")))
      (setq ent (entget (ssname ss 0)))
      (setq ent (subst (cons 41 factr) (assoc 41 ent) ent)
            ent (subst (cons 42 factr) (assoc 42 ent) ent)
            ent (subst (cons 43 factr) (assoc 43 ent) ent)
      )
   (entmod ent)
)
)
)

Link to comment
Share on other sites

The if function will only accept three arguments: a test argument, a 'then' argument, and optionally, and 'else' argument.

 

Since you wish to evaluated multiple expressions as part of the 'then' argument, you will need to evaluate such expressions using a progn expression which may then be supplied as a single argument to the if function.

 

However, note that even with the syntax corrected, your code will only operate on the first block reference in the selection - to operate on all block references, you will need to iterate over the selection set, perhaps using one of the methods I have described here.

Link to comment
Share on other sites

Thank you for the advice!!

In an attempt to utilize the "while" method, This is what I came up with. It is loading properly, but returning nil and not making any changes. I'm not sure what i've got wrong here.

(defun c:chgscl (/ ss factr ent)

(setq factr 1.0)
(while
 (setq ss (ssget "_X" '((0 . "INSERT") (2 . "ELEVATION MARKER"))))
      (setq ent (subst (cons 41 factr) (assoc 41 ent) ent)
            ent (subst (cons 42 factr) (assoc 42 ent) ent)
            ent (subst (cons 43 factr) (assoc 43 ent) ent)
 )
   (entmod ent)
)
)

 

Should I perhaps also be using an IF with the PROGN statements along with the While?

Link to comment
Share on other sites

Should the "while" be moved to after the selection is made? perhaps that is the issue? I'm just not understanding why I get nil everytime i run the command, and it makes no changes.

 

EDIT

they are dynamic blocks. will that make a difference?

 

I am also trying to make this scale update in paper space, if that makes any difference

Edited by K Baden
Link to comment
Share on other sites

Oops, wait: you will of course have to iterate over the selection set.

(defun c:chgscl ( / ent factr idx ss)
 (setq factr 1.0)
 (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "ELEVATION MARKER"))))
   (repeat (setq idx (sslength ss))
     (setq
       ent (entget (ssname ss (setq idx (1- idx))))
       ent (subst (cons 41 factr) (assoc 41 ent) ent)
       ent (subst (cons 42 factr) (assoc 42 ent) ent)
       ent (subst (cons 43 factr) (assoc 43 ent) ent)
     )
     (entmod ent)
   )
 )
)

Link to comment
Share on other sites

That is definitely my bad! I saw a thread I hadn't seen previously after figuring it must be the fact that my blocks are dynamic, and posted there as well. My mistake!

Link to comment
Share on other sites

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