Jump to content
notredave

Can this be done with dynamic block

Recommended Posts

notredave

Good morning all,

 

We work with drawings that go thru status cycles. We send drawings to the client for approval and then we flip the drawings for construction. My question is, since this happens a lot, would there be a way to change dynamic stamp attached from "IFA" to "IFC". I will be going in manually next week into 82 drawings to change dynamic stamp after and if we receive any client comments back. I have used Lee Mac's bfind to change date on stamp with success, so date is not an issue. If someone will please help, I would so much appreciate it.

 

Thank you,

David

STAMP.dwg

Share this post


Link to post
Share on other sites
Emmanuel Delay

I'm not sure what you asking from us.

Sure, I can make a lisp routine that will change the visibility state to value "IFC".  Is that all you're asking? Because using the button is just as easy as loading the routine and executing it.

 

Or do you want a routine that opens all 82 drawings and auto performs that routine (which is harder)?

Share this post


Link to post
Share on other sites
notredave

Emmanuel, thank you for replying. I would like a lisp to change dynamic stamp from IFA to IFC. I, then can use Lee Mac's script writer to open all the drawings in directory, load the lisp and execute. If lisp can include the date I need would be a bonus but that might be asking to much. I appreciate your reply.

Share this post


Link to post
Share on other sites
Emmanuel Delay
Posted (edited)

Okay, like this

 

Command SDSV, for Set Dynamic Stamp Value (bottom function)

 

It will change all the stamps in the dwg.  Perhaps you have a stamp on each Layout, but you're currently on model space.  Regardless, it will change all.


(vl-load-com)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  GET

;; 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 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)))
    )
)

;; 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 / vis )
    (if (setq vis (LM:getvisibilityparametername blk))
        (LM:getdynpropvalue blk vis)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  SET

;; 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)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Effective Block Name  -  Lee Mac
;; obj - [vla] VLA Block Reference object
(defun LM:effectivename ( obj )
    (vlax-get-property obj
        (if (vlax-property-available-p obj 'effectivename)
            'effectivename
            'name
        )
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Set Dynamic Stamp Value

(defun c:sdsv ( / ss blockname val i obj)
  ;; settings
  (setq blockname "Dynamic Stamp")
  (setq val "IFC")

  (setq ss (ssget "_X" (list '(0 . "INSERT") )))  ;; selection of all blocks on the dwg, even if you're not on the right layout (model/paper)
  (setq i 0)
  (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss i)))
    (if (= blockname (LM:effectivename obj))  ;; for dynamic blocks you need to know the effective name, (assoc 2 entity) doesn't get you what you need
      (LM:SetVisibilityState obj val)
    )
    (setq i (+ i 1))
  )
  (princ)
)

Edited by Emmanuel Delay
  • Like 1

Share this post


Link to post
Share on other sites
notredave

Emmanuel, you are awesome. It works like a charm! Could a line be added to code to include date? I'm sorry for being picky but it would eliminate me using Lee's bfind. If it's to much trouble, please don't worry at all. Thank you much!!!

  • Like 1

Share this post


Link to post
Share on other sites
Emmanuel Delay

Sure.

 

In case you want month/day/year (I'm not sure),

change in function current_date:

  (setq txt    (strcat day "/" mth "/" yer))
to

  (setq txt    (strcat mth "/" day "/" yer))

 


(vl-load-com)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  GET

;; 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 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)))
    )
)

;; 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 / vis )
    (if (setq vis (LM:getvisibilityparametername blk))
        (LM:getdynpropvalue blk vis)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  SET

;; 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)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Effective Block Name  -  Lee Mac
;; obj - [vla] VLA Block Reference object
(defun LM:effectivename ( obj )
    (vlax-get-property obj
        (if (vlax-property-available-p obj 'effectivename)
            'effectivename
            'name
        )
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun current_date ()
  (setq
    cd    (getvar "CDATE")
    dte    (rtos cd 2 4)
    ;;  yer    (substr dte 1 4)   ;; in case you want the full year
    yer    (substr dte 3 2)   ;; in case you want the 2 digits year
    mth    (substr dte 5 2)
    day    (substr dte 7 2)
    )
  (setq txt    (strcat day "/" mth "/" yer))
)      

;;  Set Dynamic Stamp Value

(defun c:sdsv ( / ss blockname val i obj datetag)
  ;; settings
  (setq blockname "Dynamic Stamp")
  (setq val "IFC")
  (setq datetag "DATE")

  (setq ss (ssget "_X" (list '(0 . "INSERT") )))  ;; selection of all blocks on the dwg, even if you're not on the right layout (model/paper)
  (setq i 0)
  (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss i)))
    (if (= blockname (LM:effectivename obj))  ;; for dynamic blocks you need to know the effective name, (assoc 2 entity) doesn't get you what you need
      (progn
        (LM:SetVisibilityState obj val)
        (LM:vl-setattributevalue obj datetag (current_date))
      )
    )
    (setq i (+ i 1))
  )
  (princ)
)

Share this post


Link to post
Share on other sites
notredave

Emmanuel, I changed this like you said

 

(defun current_date ()
  (setq
    cd    (getvar "CDATE")
    dte    (rtos cd 2 4)
    ;;  yer    (substr dte 1 4)   ;; in case you want the full year
    yer    (substr dte 3 2)   ;; in case you want the 2 digits year
    mth    (substr dte 5 2)
    day    (substr dte 7 2)
    )
  (setq txt    (strcat 09 "/" 05 "/" 19))
)      

 

But, i get this error:

; error: bad argument type: stringp 9

 

Share this post


Link to post
Share on other sites
Tharwat

Hi,

This should be more than enough I believe.

(defun c:Stamp ( / sel int ent obj)
  ;; Tharwat - Date: 20.Aug.2019	;;
  (and (setq int -1 sel (ssget "_X" '((0 . "INSERT") (66 . 1))))
       (while (setq int (1+ int) ent (ssname sel int))
         (and (= (vla-get-EffectiveName (setq obj (vlax-ename->vla-object ent))) "Dynamic Stamp")
              (vl-some '(lambda (x) (if (= (vla-get-propertyname x) "Visibility1") (progn (vlax-put x 'Value "IFC") t)))
                       (vlax-invoke obj 'getdynamicBlockproperties))
              (foreach att (vlax-invoke obj 'getattributes)
                (and (= (vla-get-tagstring att) "DATE") (vla-put-textstring att "20/08/19"))
                )
              )
         )
       )
  (princ)
  ) (vl-load-com)

 

  • Like 1

Share this post


Link to post
Share on other sites
Emmanuel Delay
Posted (edited)

The error you're getting, is because you cannot string concatenate (function strcat) numbers.  Nor do you want to put that in the function current_date

 

If you want a fixed date (for example 09/05/19),

 

(LM:vl-setattributevalue obj datetag "09/05/19")
Edited by Emmanuel Delay

Share this post


Link to post
Share on other sites
notredave

Unbelievable!!! I want to thank you very much Tharwat and Emmanuel for you contribution, you just have no idea how much time and effort this will save me next week and going into the future! You guys are awesome and so darn smart!!!  They both work great and does exactly what I want it to do. Consider this thread closed.

 

Thank you very much again,

David

  • Like 1

Share this post


Link to post
Share on other sites
ronjonp

Why are you not using an xref for this? Make a change in one place and 82 drawings are done...

Share this post


Link to post
Share on other sites
notredave

ronjonp, that would make it a lot easier, lol. WOW, I feel like an idiot, thank you very much for suggestion and responding! I really appreciate it.

Share this post


Link to post
Share on other sites
ronjonp
10 minutes ago, notredave said:

ronjonp, that would make it a lot easier, lol. WOW, I feel like an idiot, thank you very much for suggestion and responding! I really appreciate it.

Hahaha ... well maybe for the next project :) . Do you use an xref for your titleblock? If so then this could still work! 

Share this post


Link to post
Share on other sites
notredave

no, title blocks are not xrefed

Share this post


Link to post
Share on other sites
ronjonp
35 minutes ago, notredave said:

no, title blocks are not xrefed

😬 Next project use xrefs .. they are prefect for this type of work.

Share this post


Link to post
Share on other sites
notredave

ronjonp, are you saying that I can't xref all 82 drawings and change dynamic stamp data? If so, do you recall a post where making a change that will fix all drawings xrefed?

Share this post


Link to post
Share on other sites
ronjonp
6 minutes ago, notredave said:

ronjonp, are you saying that I can't xref all 82 drawings and change dynamic stamp data? If so, do you recall a post where making a change that will fix all drawings xrefed?

I just figured you have a workable lisp solution so next time around you'll maybe think to organize differently and you won't need code to do this. If this project is ongoing, you might want to convert to xrefs. Don't know your situation though.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...