Results 1 to 6 of 6

Thread: Run LISP routine across multiple layout tabs

  1. #1
    Member
    Join Date
    2017-11
    Posts
    5
    Login to Give a bone
    0

    Default Run LISP routine across multiple layout tabs

    Hello all,
    I have a LISP routine called BKVZ which changes the visibility state of all dynamic blocks to the visibility state that is a field reference to an attribute of another block. I have several blocks set up on different layout tabs, not using viewports, because I do not like the clutter in my model space in order to do other drawing task. Just my work flow and makes my life easier. The problem that I am having is that I have to go to each sheet and run the BKVZ routine to get the blocks on that sheet to change to the desired visibility state. What I am looking for is a way to type in my BKVZ command and ALL of the blocks on all of the pages do what they are supposed to do instead of me having to go to each sheet and type in the command. Any ideas on how to make that happen? Much appreciated.

    Thank you

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: Run LISP routine across multiple layout tabs

    It could probably be modified, where's the code?

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    555
    Login to Give a bone
    0

    Default Re: Run LISP routine across multiple layout tabs

    here is some hints

    Code:
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for lay (vla-get-Layouts doc)
      (setq plotabs (cons (vla-get-name lay) plotabs))
    )
    
    (setq bname "DA1DRTXT")
    (repeat (length plotabs)
      (setq tabname (nth x plotabs))
      (if (/= tabname "Model")
        (progn
          (setvar "ctab" tabname)
    ..... do your thing to blocks
    )

  4. #4
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Run LISP routine across multiple layout tabs

    Quote Originally Posted by jessye1977 View Post
    Hello all,
    I have a LISP routine called BKVZ which changes the visibility state of all dynamic blocks to the visibility state that is a field reference to an attribute of another block.

    Thank you
    Code:
    (defun c:demo ( / ss e ev bn SourceCollection TargetCollection)
    (setq func '(list (cdr (assoc 410 (entget e))) ev))
    	  (if
    	    (setq ss (ssget "_X" '((0 . "INSERT")(2 . "ANOTHER_BLOCK_AS_SOURCE,DYNAMIC_BLOCK,`*U*")(410 . "~Model"))))
    	    	(progn
    		  (repeat (setq i (sslength ss))
    		    	(setq e (ssname ss (Setq i (1- i))) ent (entget e))
    		    
    	;;;	"ev" because later the routine needs vl method for Dynamic blocks		;;;
    		    
    		    	(setq bn (strcase (vla-get-EffectiveName
    					(setq ev (vlax-ename->vla-object e)))))
    
    	;;;											;;;
    		    
    		    	(if (eq bn "ANOTHER_BLOCK_AS_SOURCE")
    		    		(setq SourceCollection (cons (Eval func) SourceCollection))
    		    		(setq TargetCollection (cons (Eval func) TargetCollection))
    			  				)
    		    	)
    		  (while (setq source (car SourceCollection))	         
    		    		(if (setq FoundThePair (assoc (car source) TargetCollection))
    					  (princ (strcat "\n<<< Do your thing with the pair found in layout \""
    							 	(car source) "\" >>>"))
    				  )
    				  (setq SourceCollection (cdr SourceCollection))
    		    )
    		  )
    	    )
    	  (princ)
    	)

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Run LISP routine across multiple layout tabs

    I thought I would play around and build a general set of functions to manipulate dynamic blocks from selection sets.

    I prefer to use lists of vla-objects instead of selection sets (so I switch back and forth)

    I have my own way of doing things... but just because I do it different than you doesn't mean I do not appreciate your contribution.

    We all have different priorities... etc...

    Enjoy...

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2018 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Any use by unauthorized person or business is strictly prohibited.
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;* C:DynamicTest
    ;* Command line Function to test dynamics properties function 
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    ;
    ;  Function List		Argument1	Argument2 	Arguement3
    
    ;* DynamicsProperties	        
    ;* Function to change dynamic properties
    
    ;* (DynamicPropertiesPut objSelection strWCProperty Value)
    ;* Function to put a dynamic block property value given block instance object, wildcard propertyname and Value
    
    ;* (DynamicPropertyPut (objSelection strWCProperty Value)
    ;* Function to put a dynamic block property value given Dynamic Property object and wildcard propertyname and Value
    
    ;* (ListToSelectionSet lstObjects)
    ;* Function to convert a list of objects to a selection set of entities.
    
    ;* (SelectionSetToList ssSelections)
    ;* Function to convert a entity based selection set to a list.
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line Function to test dynamics properties function 
    ;___________________________________________________________________________________________________________|
    
    (defun C:DynamicTest (/ entSelection lstSelection objSelection ssSelections strWCBlockName strWCProperty Value)
    
     (if (and (setq lstSelection   (entsel "\nSelect Dynamic Block: "))
              (setq entSelection   (car lstSelection))
              (setq objSelection   (vlax-ename->vla-object entSelection))
              (wcmatch (vla-get-objectname objSelection) "AcDbBlockReference,AcDbMInsertBlock")
              (setq strWCBlockName (vla-get-effectivename objSelection))
              (vlax-property-available-p objSelection "IsDynamicBlock")
              (setq strWCProperty  (getstring "\nEnter Wild Card Property Name: ")) 
              (progn (initget 128) T)
              (setq Value          (getdist "\nEnter Value: "))
              (setq ssSelections   (ssget (list (cons 0 "insert"))))
              (setq ssSelections   (DynamicBlockInstances ssSelections strWCBlockName))
         )
      (DynamicsProperties ssSelections strWCProperty Value)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to filter a selection set of dynamic blocks and return blocks matching effective name
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicBlockInstances (ssSelections strWCEffectiveName / lstObjects lstObjects2)
     (if (setq lstObjects (SelectionSetTolist ssSelections))
      (foreach objSelection lstObjects
       (and (vlax-property-available-p objSelection "IsDynamicBlock")
            (= (vlax-get objSelection "IsDynamicBlock") -1)
            (wcmatch (strcase (vla-get-effectivename objSelection))
                     (strcase strWCEffectiveName)
            )
            (setq lstObjects2 (cons objSelection lstObjects2))
       )
      )
     )
     (if lstObjects2 
      (ListToSelectionSet (reverse lstObjects2))
     )
    )
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to change the specified properties of a selection set of dynamic blocks
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicsProperties (ssSelections strWCProperty Value / lstSelections)
     (if (setq lstSelections (SelectionSetToList ssSelections))
      (mapcar '(lambda (X)(DynamicPropertiesPut X strWCProperty Value)) lstSelections)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to put a dynamic block property value given block instance object, wildcard propertyname and Value
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicPropertiesPut (objDynamicBlock 
                                 strWCProperty 
                                 Value 
                                 / 
                                 objDynamic
                                 strProperty
                                )  
     (and
      (Vlax-Property-Available-P objDynamicBlock "IsDynamicBlock")   
      (= (vlax-get objDynamicBlock "IsDynamicBlock") -1)
      (apply 'or
       (mapcar '(lambda (X)(DynamicPropertyPut X strWCProperty Value))
                (vlax-invoke objDynamicBlock "GetDynamicBlockProperties")
       )
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to put a dynamic block property value given Dynamic Property object and wildcard propertyname and Value
    ; Returns T for success and nil for failure
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicPropertyPut (objDynamicProperty
                               strWCProperty
                               Value
                               /
                               intVariantType
                               strProperty
                               varOldValue
                              )
     (and 
      (Vlax-Property-Available-P objDynamicProperty "AllowedValues")
      (setq strProperty (vla-get-propertyname objDynamicProperty))
      (/= strProperty "Origin"); <- Redundant Origin Property Removed
      (wcmatch (strcase strProperty)(strcase strWCProperty))
      (or (not (setq lstAllowedValues (vlax-get objDynamicProperty "AllowedValues")))
          (member Value lstAllowedValues)
      )
      (setq varOldValue    (vlax-get-property objDynamicProperty "Value"))
      (setq intVariantType (vlax-variant-type varOldValue))
      (errortrap (quote    (vlax-put-property objDynamicProperty 
                                             "Value" 
                                             (vlax-make-variant Value 
                                              intVariantType)))
      )
      (equal (vlax-get-property objDynamicProperty "Value")
             (vlax-make-variant Value intVariantType)
      )
     )
    )
    
    
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to convert a list of objects to a selection set of entities.
    ;___________________________________________________________________________________________________________
    
    (defun ListToSelectionSet (lstObjects / entSelection objSelection ssSelections )
     (foreach objSelection lstObjects
      (if (setq entSelection (vlax-vla-object->ename objSelection))
       (if ssSelections        
        (setq ssSelections (ssadd entSelection ssSelections))
        (setq ssSelections (ssadd entSelection))
       )
      )
     )
     ssSelections
    )
    
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to convert a entity based selection set to a list.
    ;___________________________________________________________________________________________________________
    
    (defun SelectionSetToList (ssSelections / entSelection intCount lstObjects objSelection )
     (repeat (setq intCount (sslength ssSelections))
      (setq intCount     (1- intCount))
      (setq entSelection (ssname ssSelections intCount))
      (setq objSelection (vlax-ename->vla-object entSelection))
      (setq lstObjects   (cons objSelection lstObjects))
     )
     (reverse lstObjects)
    )
    
    
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

  6. #6
    Member
    Join Date
    2017-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Run LISP routine across multiple layout tabs

    Sorry for the delay in response... I got pulled away on another project...here is that code you were asking about. it's a compilation of different routines, mostly from the god of LISP, Mr. Lee Mac, with a dash of other people's help, and a smidgen of my own. so it's probably a nightmare to look at, as i'm sure it could be cleaned up and streamlined. i would like to add something to it that will do a regenall and run this routine every time i switch layout tabs... anywho... hope it doesn't give you a migraine or drive you to drinking!

    Code:
    (defun C:BKVZ  (/ ss elst bent aent aentlst aval blklst) ; Define the function, localize the variables
      (vl-load-com) ; Load the Visual LISP console (allows vl-... commands)
      (if ; If there exists a selection set such that:
        (setq ss (ssget "X" ; "X" meaning search entire database for entities with:
                (list (cons 0 "INSERT") ; type: INSERT (Blocks, XRefs)
                  (cons 66 1) ; Attributed
                  (if (getvar "CTAB") ; If there is a variable "CTAB" (newer releases - determines Model Space/Paper Space
                    (cons 410 (getvar "CTAB")) ; Then filter by the CTAB variable
                    (cons 67 (- 1 (getvar "TILEMODE"))) ; Otherwise use TILEMODE variable to filter.
                    ) ; end if
                  ) ; end list [Filter List]
                ) ; end Selection set aquirement [ssget]
          ) ; end Variable Setting [Selection set stored in variable "ss"]
         (progn ; Wrap the following code for use in the IF statement:
           (setq elst ; Store the following list of entity names to variable "eLst"
              (vl-remove-if
            'listp ; Remove from the list if the item is a List
            (mapcar    'cadr ; Produce a list of entity names (and possible coord values) from
                (ssnamex ss) ; Information provided by "ssnamex" about the Selection Set
                ) ; end Mapcar
            ) ; end vl-remove-if
             ) ; end variable setting
           (foreach    e  elst ; For Each item (e) in the eLst (entity name list):
         (setq bent (cdr (assoc 5 (entget e))) ; Retrieve the Block Name [store to "bEnt"] **** 5 = block handle
               aent (entnext e) ; Retrieve the Attribute Entity Name [Store to aEnt]
               ) ; end Variable setting
         (while    (= "ATTRIB" (cdr (assoc 0 (setq aentlst (entget aent))))) ; While the Entity Type is "ATTRIB"[ute]
           (if (= (cdr (assoc 2 aentlst)) "AFVIZ") ; If the ATTRIBute name is "AFVIZ"
    	 
    ;;;CHANGE "AFVIZ" TO YOUR ATTRIBUTE NAME. NAME ALL OF THE ATTRIBUTES THAT REFERENCE THE EXCEL
    ;;;SPREADSHEET OR WHATEVER YOU ARE REFERENCING, THE SAME THING. SO THAT THE ROUTINE ONLY LOOKS AT
    ;;;THE NAME OF THE VISIBILITY PARAMETER THAT YOU WANT TO CHANGE.
    
    	 
             (progn ; wrap the following for use with the IF
               (setq aval   (cdr (assoc 1 aentlst)) ; Store the ATTRIBute value [to aVal]
                 blklst (cons (cons bent aval) ; Create an Associative list (dotted pair) of Block Name and Att. Value.
                      blklst) ; Connect this to the main list
                 ) ; End Variable Setting
               ) ; end Progn (code wrapper)
             ) ; end IF
           (setq aent (entnext aent)) ; Move onto next Attribute in Block
           ) ; End While
         ) ; End Foreach
           ) ; End Progn
         (princ "\n<!> No Attributed Blocks Found <!>") ; If No Selection Set, then No Attributed Blocks Found in Drawing.
         ) ; End IF
     ;(PROMPT (vl-princ-to-string blkLst)) ; Convert the Associative List to a String and Alert it in a Dialog Box to view result.
      (foreach item     blklst  ; ***** added function here and replaced 'block-record' with 'item' BlkLst should have form ((handle1 . attribute) (handle2 . attribute) ...) but only if ssget can find them!
        (if    (setq blk (handent (car item)))
          (lm:setvisibilitystate (vlax-ename->vla-object blk) (cdr item))
          (princ "\nBlock handle not found")))
      (princ) ; Exit Cleanly - [Suppress last function return]
      ) ; End Function
        (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)))))
            (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)
    )
    
    ;; 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 Dynamic Block Property Value  -  Lee Mac
    ;; Returns the value of a Dynamic Block property (if present)
    ;; blk - [vla] VLA Dynamic Block Reference object
    ;; prp - [str] Dynamic Block property name (case-insensitive)
    
    (defun LM:getdynpropvalue ( blk prp )
        (setq prp (strcase prp))
        (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
            (vlax-invoke blk 'getdynamicblockproperties)
        )
    )
    ;;
    ;; Get Dynamic Block Properties  -  Lee Mac
    ;; Returns an association list of Dynamic Block properties & values.
    ;; blk - [vla] VLA Dynamic Block Reference object
    ;; Returns: [lst] Association list of ((<prop> . <value>) ... )
    
    (defun LM:getdynprops ( blk )
        (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
            (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)))
        )
    )
    ;;
    ;; Get Dynamic Block Visibility State  -  Lee Mac
    ;; Returns the value of the Visibility Parameter of a Dynamic Block (if present)
    ;; blk - [vla] VLA Dynamic Block Reference object
    ;; Returns: [str] Value of Visibility Parameter, else nil
    
    (defun LM:getvisibilitystate ( blk )
        (LM:getdynpropvalue blk (LM:getvisibilityparametername blk))
    )
    ;;
    ;; 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)
        )
    )
    ;;
    ;; Set Dynamic Block Properties  -  Lee Mac
    ;; Modifies values of Dynamic Block properties using a supplied association list.
    ;; blk - [vla] VLA Dynamic Block Reference object
    ;; lst - [lst] Association list of ((<Property> . <Value>) ... )
    ;; Returns: nil
    
    (defun LM:setdynprops ( blk lst / itm )
        (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst))
        (foreach x (vlax-invoke blk 'getdynamicblockproperties)
            (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
                (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x))))
            )
        )
    )
    ;;;;;;;
    ;; 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)
        )
    )
    ;;;;
    
    (PRINC)

Similar Threads

  1. View multiple layout tabs
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2015-10-08, 03:58 PM
  2. Replies: 7
    Last Post: 2013-11-26, 08:39 PM
  3. Rename Layout tabs on multiple .dwg
    By Dave Lewis in forum AutoCAD General
    Replies: 3
    Last Post: 2008-03-19, 07:40 PM
  4. LISP routine to create PLT files from Layout tabs
    By Matt Mercer in forum AutoLISP
    Replies: 3
    Last Post: 2007-01-25, 02:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •