Select Dynamic block and change its visibility state using LISP

Select Dynamic block and change its visibility state using LISP

asleafty
Participant Participant
654 Views
5 Replies
Message 1 of 6

Select Dynamic block and change its visibility state using LISP

asleafty
Participant
Participant

I am trying to select a specific dynamic block in Layout space and change its visibility state using LISP. Something that I'm doing isn't working because it just states the block is not in layout space, however it clearly is. Basically I need to be able to print the cover sheet for plans twice, once with the standard energy code selections, and a second time with solar energy credit selections. 

 

Block name: WSEC ENERGY SELECTIONS - 2021 - MV4

Visibility Parameter name: ENERGY CREDITS

Visibility State (to change to): SOLAR INSTALLATION

 

By default the visibility state is typically set to MV4, I want to switch this to SOLAR INSTALLATION so I can print the sheet, then I'll add code to switch it back after printing later. 

 

Code sample:

(defun c:c2solar ( / blkname visstate ss i ent obj props propname )
  (vl-load-com)

  (setq blkname "WSEC ENERGY SELECTIONS - 2021 - MV4")
  (setq visstate "SOLAR INSTALLATION")

  ;; Select all inserts of the block in paper space (layout space)
  (setq ss (ssget "_X"
            (list
              '(0 . "INSERT")
              (cons 2 blkname)
              (cons 410 "A0.0 Right - Cover")
            )
          )
  )

  (if ss
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (ssname ss i))
        (setq obj (vlax-ename->vla-object ent))

        ;; Get dynamic block properties
        (if (vlax-property-available-p obj 'EffectiveName)
          (progn
            (setq props (vlax-invoke obj 'GetDynamicBlockProperties))
            (foreach prop props
              (setq propname (strcase (vla-get-PropertyName prop)))
              (if (wcmatch propname "ENERGY CREDITS")
                (vla-put-Value prop visstate)
              )
            )
          )
        )
        (setq i (1+ i))
      )
      (princ (strcat "\nAll matching blocks updated to visibility: " visstate))
    )
    (princ "\nBlock not found in layout space.")
  )
  (princ)
)

 

 

Any assistance to get this functioning would be much appreciated. 

0 Likes
Accepted solutions (1)
655 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Maybe just change

 

(cons 2 blkname)

to 

(cons 2 (strcat "`*U*," blkname))

0 Likes
Message 3 of 6

asleafty
Participant
Participant

That's all it needed! Thank you for you speedy assistance, I was at the end of my rope 🙂

0 Likes
Message 4 of 6

rspearYL2SX
Contributor
Contributor

I'm after something similar but I don't want it tied to a specific layout... I'd like it to do it in all layouts.

In addition to block name, parameter name and desired visibility state, I replaced:  (cons 410 "A0.0 Right - Cover")

 

with: (setq ctab (getvar "ctab"))
(foreach obj (layoutlist)
(setvar "ctab" obj)

 

which has worked in the past for me but it's not finding the layout.

 

Any suggestions?

0 Likes
Message 5 of 6

rspearYL2SX
Contributor
Contributor

nevermind, I got it working. 🙂

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

This does what your asking for and displays the visibility in a dcl to choose. You need to save a lisp file of Lee-mac dynamic block functions. I saved as "Lee-mac Dynamic block get-put.lsp" https://www.lee-mac.com/dynamicblockfunctions.html.

 

Save the "Multi radio buttons.lsp in a support path" as its a Library function to make a radio button dcl on the fly.

 

 

 

 

 

0 Likes