Need help with this one last thing....
when this code is ran in a dwg with dynamic blocks that has attributes it puts out a list of dotted pairs in the format (block handle . attribute value) Here is the output for my particular dwg. after running the code.
((1153D . FULL PEN-6-HOLE) (1154E . EQ. WELD) (1216E . NO HOLE) (12DD5 . VERT-STRAIGHT(>/= 10.75 O.D.)) (1FD4A . SC1) (201C5 . EQ. WELD))
Code:
(defun StVz (/ 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"]
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"
(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.
(princ) ; Exit Cleanly - [Suppress last function return]
) ; End Function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I want to combine the above code with THIS code to set the dynamic block, that's listed by its handle, the first element of the pairs, to the visibility state that is the attribute value, the second element of the pairs, the vis state is a field that references an Excel worksheet entry. In the following code towards the top, there is a setq blk function with that says "WELD DETAIL" I would like the first element of each pair to be put into this place. and for the setq vis function "EQUAL WELD" I would like the second element of the list to be here, as this tells the following code what to change the visibility to. Both of these codes work independently, but the second one has to have the values put into them at the top to tell it WHICH block and WHICH visibility state to apply it to. I would like these two codes to run in tandem without any user input, and applicable to ALL dynamic blocks within the dwg. SSSOOOOooooo..... my question is.... how do I get that to happen?
Code:
(defun BkVz ()
(setq blk "WELD DETAIL" ;; Block Name
vis "EQUAL WELD" ;; New Visibility State
)
(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)
)
;; 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)
THANK YOU TO ANYONE THAT CAN OR TRIES TO HELP OR OFFERS SUGGESTIONS!!