CHANGE BLOCK VISIBILITY STATE IN MULTIPLE DRAWINGS

CHANGE BLOCK VISIBILITY STATE IN MULTIPLE DRAWINGS

henry
Participant Participant
3,900 Views
16 Replies
Message 1 of 17

CHANGE BLOCK VISIBILITY STATE IN MULTIPLE DRAWINGS

henry
Participant
Participant

I am trying to change the visibility state of a dynamic block on multiple drawings without opening the drawing. I have a bat file that executes accoreconsole, I have a script that successfully runs the lisp routine to change the state in an open drawing but I can't figure out how to run the lisp in the script using the accoreconsole to change the visibility state without opening the drawing. The dynamic block name is "drawing status stamp", the lisp routine name is "changevis_permit.lsp", the script name is "CHANGEVIS_PERMIT.SCR". I am relatively new to using accoreconsole,  bats,scripts and lisp so please keep any explanation simple. I realize that using accoreeconsole may not be the correct approach but it is the only way I know to execute a command on drawings without opening them.

 

Thank you!

0 Likes
Accepted solutions (1)
3,901 Views
16 Replies
Replies (16)
Message 2 of 17

pbejse
Mentor
Mentor

@henry wrote:

I am trying to change the visibility state of a dynamic block on multiple drawings without opening the drawing. ....  I realize that using accoreeconsole may not be the correct approach but it is the only way I know to execute a command on drawings without opening them.


An alternative is ODBX , look here --> ObjectDBX Wrapper 

Its a pity we cant see how your lisp rouitne  works, because there are restrictions for ODBX, you alone can resolve it.

 

Modify your "changevis_permit.lsp" to match this format.

(defun changevis_permit ( doc )
            (the thing on your lisp routine)
        )
(LM:ODBX 'changevis_permit nil t)

HTH

 

0 Likes
Message 3 of 17

henry
Participant
Participant

Thank you for your response and I am sorry I did not provide enough information. Being the novice that I am, I have no idea how to apply your response. Here is the code used to change the visibilty state in the current lisp. All credit for this lisp goes to Lee Mac. I have no idea what 99 % of this means but I figured out what I needed to change in it to make it work within a single drawing file. Now I want it (or something similar) to work on a directory of drawings without opening them. Thanks again.

 

(defun c:changevis_PERMIT ( / blk idx obj sel vis )
(setq blk "drawing status stamp" ;; Block Name
vis "Permit" ;; New Visibility State
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) '(410 . "~Model"))))
(repeat (setq idx (sslength sel))
(if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(LM:SetVisibilityState obj vis)
)
)
)
(princ)
)
;; Block Name - Lee Mac
;; Returns the true (effective) name of a supplied block reference
(defun LM:blockname ( obj )
(if (vlax-property-available-p obj 'effectivename)
(defun LM:blockname ( obj ) (vla-get-effectivename obj))
(defun LM:blockname ( obj ) (vla-get-name obj))
)
(LM:blockname obj)
)
;; Set Dynamic Block Visibility State - Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; blk - [vla] VLA Dynamic Block Reference object
;; val - [str] Visibility State Parameter value
;; Returns: [str] New value of Visibility Parameter, else nil
(defun LM:SetVisibilityState ( blk val / vis )
(if
(and
(setq vis (LM:getvisibilityparametername blk))
(member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)))
)
(LM:setdynpropvalue blk vis val)
)
)
;; Set Dynamic Block Property Value - Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil
(defun LM:setdynpropvalue ( blk prp val )
(setq prp (strcase prp))
(vl-some
'(lambda ( x )
(if (= prp (strcase (vla-get-propertyname x)))
(progn
(vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
(cond (val) (t))
)
)
)
(vlax-invoke blk 'getdynamicblockproperties)
)
)
;; Get Dynamic Block Property Allowed Values - Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions
(defun LM:getdynpropallowedvalues ( blk prp )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues)))
(vlax-invoke blk 'getdynamicblockproperties)
)
)
;; Get Visibility Parameter Name - Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil
(defun LM:getvisibilityparametername ( blk / vis )
(if
(and
(vlax-property-available-p blk 'effectivename)
(setq blk
(vla-item
(vla-get-blocks (vla-get-document blk))
(vla-get-effectivename blk)
)
)
(= :vlax-true (vla-get-isdynamicblock blk))
(= :vlax-true (vla-get-hasextensiondictionary blk))
(setq vis
(vl-some
'(lambda ( pair )
(if
(and
(= 360 (car pair))
(= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
)
(cdr pair)
)
)
(dictsearch
(vlax-vla-object->ename (vla-getextensiondictionary blk))
"ACAD_ENHANCEDBLOCK"
)
)
)
)
(cdr (assoc 301 (entget vis)))
)
)
(vl-load-com) (princ)

0 Likes
Message 4 of 17

pbejse
Mentor
Mentor

@henry wrote:

Thank you for your response and I am sorry I did not provide enough information. Being the novice that I am, I have no idea how to apply your response. Here is the code used to change the visibilty state in the current lisp. All credit for this lisp goes to Lee Mac. 


 

No worries, we'll take care of it, One issue though, I need to know the name of the parameter for visibility on the dynamic block, by defuault its "VISIBILITY1", theres a bit on the code LM:getvisibilityparametername that is not allowed: 

 

* No ent* methods (entmod, entupd etc)

 

or you can share your "DRAWING STATUS STAMP" block so i can have a look see.

Once you provide that information, I can post the modified  c:changevis_PERMIT for you to use.

 

0 Likes
Message 5 of 17

henry
Participant
Participant

Thanks again. I have attached the "drawing status stamp" block. I sure appreciate your help and skills.

0 Likes
Message 6 of 17

pbejse
Mentor
Mentor
Accepted solution

@henry wrote:

Thanks again. I have attached the "drawing status stamp" block. I sure appreciate your help and skills.


 

Here you go [ at command prompt you will be prompted to select the folder ]

Command: Changevis_Permitodbx

 

browse me.png

(("C:\\AutoDeskForum\\TestFile1.dwg" . ) ("C:\\AutoDeskForum\\TestFile2.dwg" . ))

 

Refer to attached file: changevis_PERMIT_ODBX.lsp

Kudos to Lee Mac

HTH

 

 

 

 

Message 7 of 17

henry
Participant
Participant

That is awesome! Thank you so much! You and Lee Mac!

0 Likes
Message 8 of 17

pbejse
Mentor
Mentor

@henry wrote:

That is awesome! Thank you so much! You and Lee Mac!


 

Glad it helps, you are welcome. 😊

0 Likes
Message 9 of 17

swankster
Enthusiast
Enthusiast

What text would I change in this lisp to make it work for a different block with different visibility states.

0 Likes
Message 10 of 17

aedwards26LR2
Observer
Observer

I am looking for a lisp routine that will allow a change of visibility state for a block in multiple drawings. I was thrilled to find this in the forum thinking I had my answer.  However, I opened a new drawing brought in the dynamic block that the previous user (Henry) provided in this thread, and then I ran the lisp routine that was provided on this thread and I get no response in Civil3D. I'm wondering why this doesn't work as it appears it have worked for the original user.  Is there any way to make this lisp work? It's exactly what I am looking for!

0 Likes
Message 11 of 17

pbejse
Mentor
Mentor

@aedwards26LR2 wrote:

....  However, I opened a new drawing brought in the dynamic block that the previous user (Henry) provided in this thread, and then I ran the lisp routi...


Only thing i can think of is when you inserted the block for testing, you place the block "Model" space Yes?

The program targets block NOT on model space @aedwards26LR2

 

You can change this line

(vlax-for item (vla-get-layouts Doc)
  (if (/= (vla-get-name item) "Model")
    	(vlax-for obj (vla-get-block item)
		(if
                      (and
                        (vlax-write-enabled-p obj)
			(eq (vla-get-objectname obj) "AcDbBlockReference" ) 
			(eq (strcase (LM:blockname obj)) (Strcase  blk))
                        )
                      (LM:SetVisibilityState obj vis)
                     )
              	)
      )
    )

to this

(vlax-for obj (Vla-get-modelspace doc)
	(if
              (and
                (vlax-write-enabled-p obj)
		(eq (vla-get-objectname obj) "AcDbBlockReference" ) 
		(eq (strcase (LM:blockname obj)) (Strcase  blk))
                )
              (LM:SetVisibilityState obj vis)
             )
)

IF you want it to work for ALL tabs

(vlax-for item (vla-get-layouts Doc)
    	(vlax-for obj (vla-get-block item)
		(if
                      (and
                        (vlax-write-enabled-p obj)
			(eq (vla-get-objectname obj) "AcDbBlockReference" ) 
			(eq (strcase (LM:blockname obj)) (Strcase  blk))
                        )
                      (LM:SetVisibilityState obj vis)
                     )
              	)
      )

HTH

 

0 Likes
Message 12 of 17

swankster
Enthusiast
Enthusiast

@pbejse 

 

If my block name is Status Stamp-Dynamic and the visibility state I want to change to is AS BUILT, what would I change (including the lisp name)? Seems the word "Permit" from the original lisp is hard to follow through.

0 Likes
Message 13 of 17

pbejse
Mentor
Mentor

@swankster wrote:

If my block name is Status Stamp-Dynamic and the visibility state I want to change to is AS BUILT, what would I change (including the lisp name)? Seems the word "Permit" from the original lisp is hard to follow through.


Are you intending to use the program in a similar way as the OP? 

What is the visibility parameter name of your block? is it "Visibility" ? if not you also need to change that in the program.

This

(setq vis "Visibility")

to

(setq vis "YourVisibilityParameterName")

Or you can use the ommited LM:getvisibilityparametername sub  here <----

and replace this:

(defun LM:SetVisibilityState  (blk val / vis)
      (if
            (and
                  ;(setq vis (LM:getvisibilityparametername blk))	;;
                  
                  ;;							;;
                  		(setq vis "Visibility")	;<		;;
                  ;;							;;
                  (member
                        (strcase val)
                        (mapcar 'strcase
                                (LM:getdynpropallowedvalues blk vis)))
                  )
                 (LM:setdynpropvalue blk vis val)
                 )
      )

with this

(defun LM:SetVisibilityState  (blk val / vis)
      (if
            (and
                  (setq vis (LM:getvisibilityparametername blk))	
                  (member
                        (strcase val)
                        (mapcar 'strcase
                                (LM:getdynpropallowedvalues blk vis)))
                  )
                 (LM:setdynpropvalue blk vis val)
                 )
      )

Block name and visibility state

(setq blk "drawing status stamp"	;; Block Name
    	vis "Permit"	        	;; New Visibility State
    		)

to

(setq blk "Status Stamp-Dynamic"	;; Block Name
    	vis "AS BUILT"	        	;; New Visibility State
    		)

Also, in reference from the previous posts. be mindful of the stamps location wehter its on model space or paper space.

 

HTH

Message 14 of 17

aedwards26LR2
Observer
Observer

@pbejse Thank You! It worked when block was inserted into paper space.  Greatly appreciate your help with this!

0 Likes
Message 15 of 17

pbejse
Mentor
Mentor

@aedwards26LR2 wrote:

@pbejse Thank You! It worked when block was inserted into paper space.  Greatly appreciate your help with this!


Glad it works for you.  You are welcome @aedwards26LR2 

 

Holler if you need more help

 

 

0 Likes
Message 16 of 17

swankster
Enthusiast
Enthusiast

@pbejseThanks, that did the trick. It was just the visibility name that was throwing me off.

0 Likes
Message 17 of 17

DanMar01
Community Visitor
Community Visitor

Hi @pbejse,

I was hoping you could please help me with the scenario that I have. I have tried to modify to suit but have been unsuccessful. I will need to change multiple drawings so this code would be great if it works for the below arrangement. 
Details below:

The block name is: PTA_Stamp_Dynamic

And the new Visibility is called: ISSUED FOR CONSTRUCTION

I have attached the CAD file for you to review.

Your assistance is appreciated.

Thank you.

0 Likes