feargt Posted February 15, 2009 Posted February 15, 2009 Hi, I posted a thread a while back but got no response so will try again using the progress that I have made to date. I want to be able to access a custom property to get the value and then say if value = x then do Y etc. What it should do is change the visibility of the titleblock. The custom property will be " current Revision". I have found code that will allow me to change the visibility of my DB titleblock but I now need to access the sheet set property to control the visibility state. if you can assist me in anyway I would be very grateful thanks. below is the saple code that I got from another forum, not sure which, maybe somebody here recognises and can give due recognition. The code is for changing the visibility of a drawing stamp. I can modify this to change my titleblock but need the above modifications too. As I said any assistance at all would be much appreciated ;----------------------------------------------------------- DynamicProps ----- ; Function retrieve or set properties from a dynamic block ; (DynamicProps (car (entsel)) "Visibility" nil) get the visibility states from a dynamic block ; (DynamicProps (car (entsel)) "Visibility" "Construction") set the visibility from a dynamic block ; (DynamicProps (car (entsel)) "" nil) get the properties from a dynamic block ; (DynamicProps (car (entsel)) "Pipe length" 2000.0) set the properties from a dynamic block (defun DynamicProps (ename propname value / obj prpL cla cll prp) (setq obj (if (= (type ename) 'VLA-OBJECT) ename (vlax-ename->vla-object ename))) (setq prpL (vlax-invoke obj 'getdynamicblockproperties)) (setq return (if (setq prp (vl-remove-if-not (function (lambda(x)(= (vlax-get-property x 'PropertyName) propname))) prpL)) (mapcar (function (lambda(v) (if (and (/= value nil)(vlax-property-available-p v 'Value)(/= (type value)'LIST)) (progn (vlax-put-property v 'Value value)(vla-update obj)) ) (if (and (vlax-property-available-p v 'AllowedValues) (vlax-get v 'AllowedValues)) (list (vlax-get v 'Value)(vlax-get v 'AllowedValues)) (vlax-get v 'Value) ) )) prp) (mapcar (function (lambda(v)(list (vla-get-propertyName v)(vlax-get v 'Value) v))) prpL) ) ) return ) ;------------------------------------------------ MWE:GetDBlockNames ------------------ ; Function for filtering dynamic blocks ; Arguments: 1 ; arglst = list met names ; Syntax: (MWE:GetDBlockNames '("Issue Stamp")) --> (("ISSUE STAMP" "*U833" "*U841") ;function by James Allen. ;;; Returns all names used for a dynamic block, including ;;; the actual block name and all anonymous instances. ;;; ;;; (setq names (MWE:GetDBlockNames (list bname))) ;;; ;;; bname = Str - Dynamic block name ;;; names = List - List of all inserted blocks whose ;;; EffectiveName = bname ;;; ;;; (setq names (MWE:GetDBlockNames '("TestDBlock"))) ;;; ("TestDBlock" "*U4" "*U5" "*U6") ;;; ;;; James Allen - 26Apr07 ;;; Malicoat-Winslow Engineers, P.C. ;;; ;;; Thanks to Joe Burke for pointing out code 331 ;;; and to Tony Tanzillo for prodding in that direction. ;;; (defun MWE:GetDBlockNames (arglst / blk edt enm ins name names) (mapcar 'set '(name) arglst) (setq names (list name) name (strcase name)) (vl-load-com) (vlax-for blk (vla-get-Blocks (vlax-get (vlax-get-Acad-Object) 'ActiveDocument)) (if (and (setq enm (tblobjname "block" (vla-get-Name blk))) (setq edt (entget enm)) (= (logand (cdr (assoc 70 edt)) 1) 1)) (if (and (setq edt (entget (vlax-vla-object->ename blk))) (setq enm (cdr (assoc 331 edt))) (setq ins (vlax-ename->vla-object enm)) (eq (vla-get-ObjectName ins) "AcDbBlockReference") (wcmatch (strcase (vla-get-EffectiveName ins)) name)) (setq names (cons (vla-get-Name blk) names)) ) ) ) (reverse names) ) ;end ;------------------------------------------------ BlockNamesFilter ------------------ ;; Argument example: ("TestDBlock" "*U4" "*U5" "*U6") ;; Returns: "TestDBlock,`*U4,`*U5,`*U6," (defun BlockNamesFilter (strlst) (apply 'strcat (mapcar '(lambda (x) (if (wcmatch x "`**,`?*")(strcat "`" x ",")(strcat x ","))) strlst) ) ) ;----------------------------------------------------------- ChangeVisibility ----- ;; Argument example: (ChangeVisibility "Issue Stamp" "Review") ;; Returns: number of changed states (defun ChangeVisibility (BlkName state / names ss ssl tempEnt) (setq names (MWE:GetDBlockNames (list BlkName))) (prompt (strcat "\nSelect insert Name " BlkName ": ")) (if (and (setq ss (ssget (list '(0 . "INSERT")(cons 2 (BlockNamesFilter names))))) (> (setq ssl (sslength ss)) 0)) (progn (while (setq tempEnt (ssname ss 0)) (DynamicProps (vlax-ename->vla-object tempEnt) "Visibility" state) (ssdel tempEnt ss) ) (princ (strcat "\nChanged "(itoa ssl) " inserts to the visibility <" state ">.")) ssl ) (princ (strcat "\nInsert " BlkName " not found.")) ) ) ;----------------------------------------------------------- c:ChvConstruction ----- (defun c:ChvConstruction () (ChangeVisibility "Issue Stamp" "Construction") (princ) ) ;----------------------------------------------------------- c:ChvReview ----- (defun c:ChvReview () (ChangeVisibility "Issue Stamp" "Review") (princ) ) ;----------------------------------------------------------- c:ChvBid ----- (defun c:ChvBid () (ChangeVisibility "Issue Stamp" "Bid") (princ) ) ;----------------------------------------------------------- c:ChvReference ----- (defun c:ChvReference () (ChangeVisibility "Issue Stamp" "Reference") (princ) ) Quote
ASMI Posted February 17, 2009 Posted February 17, 2009 One more example how to get access to visibility parameter of dynamic block: ;; ============================================================ ;; ;; ;; ;; VICO.LSP - This lisp program copies visibility state from ;; ;; one dynamic block to others. ;; ;; ;; ;; ============================================================ ;; ;; ;; ;; Command(s) to call: VICO ;; ;; ;; ;; Select a sample dynamic block to get visibility state ;; ;; than select set of blocks to copy of state. ;; ;; ;; ;; ============================================================ ;; ;; ;; ;; THIS PROGRAM AND PARTS OF IT MAY REPRODUCED BY ANY METHOD ;; ;; ON ANY MEDIUM FOR ANY REASON. YOU CAN USE OR MODIFY THIS ;; ;; PROGRAM OR PARTS OF IT ABSOLUTELY FREE. ;; ;; ;; ;; THIS PROGRAM PROVIDES 'AS IS' WITH ALL FAULTS ;; ;; AND SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF ;; ;; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. ;; ;; ;; ;; ============================================================ ;; ;; ;; ;; V1.0, 10th Apr 2008, Riga, Latvia ;; ;; © Aleksandr Smirnov (ASMI) ;; ;; For AutoCAD 2000 - 2008 (isn't tested in a next versions) ;; ;; ;; ;; http://www.asmitools.com ;; ;; ;; ;; ============================================================ ;; (defun c:vico(/ sBlk eBlk dyPrp cProp curBl prLst cSt efNm fLst bSet nSet errCnt) (vl-load-com) (if (setq sBlk (entsel "\nSelect sample block to copy visibility state > ")) (if (and (= "INSERT"(cdr(assoc 0(entget(setq eBlk(car sBlk)))))) (setq sBlk(vlax-ename->vla-object(car sBlk))) (= :vlax-true(vla-get-IsDynamicBlock sBlk)) ); end and (progn (if(setq dyPrp(vla-GetDynamicBlockProperties sBlk)) (progn (setq dyPrp(vlax-safearray->list (vlax-variant-value dyPrp))) (foreach itm dyPrp (if(vlax-property-available-p itm 'AllowedValues) (setq cSt(vla-get-Value itm)) ); end if ); end foreach (if cSt (progn (setq efNm(vla-get-EffectiveName sBlk) errCnt 0 ); end setq (princ "\n<<< Select blocks to paste visibility state >>> ") (if(setq bSet(ssget '((0 . "INSERT")))) (progn (setq bSet(vl-remove-if 'listp (mapcar 'cadr(ssnamex bSet))) nSet(ssadd)) (foreach i bSet (setq curBl(vlax-ename->vla-object i)) (if (and (vlax-method-applicable-p curBl 'GetDynamicBlockProperties) (= efNm(vla-get-EffectiveName curBl)) ); end and (ssadd i nSet) ); end if ); end foreach (setq nSet(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr(ssnamex nSet))))) (foreach bl nSet (setq prLst(vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties bl)))) (foreach pr prLst (if(vlax-property-available-p pr 'AllowedValues) (if(vl-catch-all-error-p (vl-catch-all-apply 'vla-put-Value (list pr cSt))) (setq errCnt(1+ errCnt)) ); end if ); end if ); end foreach ); end foreach (if(/= 0 errCnt) (princ (strcat "\n>>> " (itoa errCnt) " were on locked layer! <<<")) ); end if ); end progn (princ "\n>>> Nothing selected! <<< ") ); end if ); end progn (princ "\n>>> 'VISIBILITY' parameter not found! <<< ") ); end if ); end progn ); end if ); end progn (princ "\n>>> It isn't Dynamic Block! <<< ") ); ens if (princ "\n>>> Nothing selected! <<< ") ); end if (princ) ); end of c:vico (princ "\n*** Type VICO to copy visibility state of dynamic blocks *** ") Quote
feargt Posted March 11, 2009 Author Posted March 11, 2009 Asmi, My apologies for the delay in replying but thanks for your version. I have decided to park this little idea for now until a later date. Thanks again. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.