change block scale

Why does this only change the scale of 1 block in the selection set?

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "BIOA1_v*,LNO_BHPB_A1,NW_BHPB*"))))
(setq sc (getreal "\nSpecify scale [1/2/5/10/15/20/25]:"))
(if ss
(progn
(setq blk (vlax-ename->vla-object (ssname ss 0)))
(vlax-put-property blk 'XEffectiveScaleFactor sc)
(vlax-put-property blk 'YEffectiveScaleFactor sc)
(vlax-put-property blk 'ZEffectiveScaleFactor sc)
)
)

Comments

  • (ssname ss 0) returns the first block in the selection set. You'd have to repeat that line and the three Put lines for (ssname ss 1) in order to set the scale of the second block in the set, and for (ssname ss 2) to set the scale of the third block, etc.

    Since you don't know how many blocks are in the selection set, you should use a variable instead of the 0, 1, 2, etc., and use the (while) or (foreach) function to step through the selection set and set the scale for each block. Use (sslength) to get the number of blocks in the set and set up a counting variable to step through the selection set that many times.
  • Thanks Anthony, I will look into this

    (ssname ss 0) returns the first block in the selection set. You'd have to repeat that line and the three Put lines for (ssname ss 1) in order to set the scale of the second block in the set, and for (ssname ss 2) to set the scale of the third block, etc.

    Since you don't know how many blocks are in the selection set, you should use a variable instead of the 0, 1, 2, etc., and use the (while) or (foreach) function to step through the selection set and set the scale for each block. Use (sslength) to get the number of blocks in the set and set up a counting variable to step through the selection set that many times.

  • Anthony Apostolaros
    edited January 2023
    If you want to assign a different scale to each block, the numeric data input has to be part of the loop too. It should come after getting the name of the next block, but before assigning any scale factors to it. I assume you want that, because if you wanted them all the same scale the user could do that for the whole selection set at once via the Properties panel.
  • My $0.05

    (setq ss (ssget "_X" '((0 . "INSERT") (2 . "BIOA1_v*,LNO_BHPB_A1,NW_BHPB*"))))
    (setq sc (getreal "\nSpecify scale [1/2/5/10/15/20/25]:"))
    (if ss
    (repeat (setq x (sslength ss))
    (setq blk (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
    (vlax-put-property blk 'XEffectiveScaleFactor sc)
    (vlax-put-property blk 'YEffectiveScaleFactor sc)
    (vlax-put-property blk 'ZEffectiveScaleFactor sc)
    )
    )
  • Thanks Alan,

    this works perfectly and I was struggling to get my head around it.
    ALANH said:

    My $0.05

    (setq ss (ssget "_X" '((0 . "INSERT") (2 . "BIOA1_v*,LNO_BHPB_A1,NW_BHPB*"))))
    (setq sc (getreal "\nSpecify scale [1/2/5/10/15/20/25]:"))
    (if ss
    (repeat (setq x (sslength ss))
    (setq blk (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
    (vlax-put-property blk 'XEffectiveScaleFactor sc)
    (vlax-put-property blk 'YEffectiveScaleFactor sc)
    (vlax-put-property blk 'ZEffectiveScaleFactor sc)
    )
    )

  • ALANH
    edited January 2023
    This is what I would use if your confused now this will confuse more, its done with like 2 lines of code as the multi radio button lisp is designed to run in any code.

    The calling code. Replace the setq sc line with these 2. You must save multi radio buttons.lsp into a support directory so it can be found or add correct directory to the load command.

    (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
    (setq sc (atoi (ah:butts 1 "V" '("Choose a scale" "1" "2" "5" "10" "15" "20" "25"))))


  • This is my complete code, I am currently using "PromptMenu" to achieve something similar.
    Would the lisp version you propose be a better option?


    (defun c:SCALE-TB (/ blk sc ss x)
    (setvar 'cmdecho 0)
    (setvar 'PromptMenu 1)
    (setq ss (ssget "_X" '((0 . "INSERT") (2 . "BIOA1_v*,LNO_BHPB*,NW_BHPB*"))))
    (setq sc (getreal "\nSpecify scale [1/2/5/10/15/20/25]:"))
    (if ss
    (repeat (setq x (sslength ss))
    (setq blk (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
    (vlax-put-property blk 'XEffectiveScaleFactor sc)
    (vlax-put-property blk 'YEffectiveScaleFactor sc)
    (vlax-put-property blk 'ZEffectiveScaleFactor sc)
    )
    )
    (command "Z" "E")
    (setvar 'PromptMenu 0)
    (setvar 'cmdecho 1)
    (princ)
    )
  • ALANH
    edited February 2023
    I can enter scale -2.57 with getreal so its unlimited in its input, you can use "Initget" to restrict the input to your range only similar to what your doing now, the multi code only allows input of preset values you can add a button if you want "Other" then could ask for a non standard value.
  • Thanks for the help Alan, I have used your multi radio button lisp.
  • ALANH
    edited February 2023
    Glad to help there is multi getvals and multi toggles, as well as some radio buttons 2 columns etc.

    Just ask if you want them.