Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Small Improvment to UNDYNAMIC LSP Routine Please

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
braudpat
1491 Views, 6 Replies

Small Improvment to UNDYNAMIC LSP Routine Please

 

Hello

 

This beautiful routine "UNDYNAMIC" acts on ALL dynamic blocks (and even on locked layers !) = OK

 

Please I need a special version :

- 1 - Use standard ACAD Selection (not ALL the DWG)

- 2 - Don't run on selected Dynamic Blocks on locked layers !

- 3 -All resulting Blocks are numbered STATIC_00-STATIC_99 or something like that !?

I need a small improvment on this NEW name :

At the beginning of the routine, Ask for the Prefix Name (default="STATIC_") ? xxxxxx

Begin with xxxxxx_100000 to xxxxxx_999999

 

Thanks in advance, Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


6 REPLIES 6
Message 2 of 7
braudpat
in reply to: braudpat

 

Hello

 

SORRY I have forgotten a small DWG to test !

 

I would like to transform to STATIC ONLY the blocks at the bottom with a standard ACAD selection ...

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 3 of 7
lando7189
in reply to: braudpat

Give this a whirl.

 

- Lanny

 

;;
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/dynamic-block-to-static-block-renamed-after-visibility-state/m-p/7257238#M356330 
;; 
;; http://www.theswamp.org/index.php?topic=32681.msg382548
;;
;; Routine: UnDynamic by MP Seagull - March 26, 2010
;; 
;; MODIFIED BY Lanny Schiele (aka 'HatchMaker Maker') - 10/27/2017
;;
(vl-load-com)

(defun c:UnDynamic

    (   /
        _DefGetString
        _get_item
        _right
        _make_key
        _dynamic->static_block
        _get_locked
        _get_dynamic_inserts
        _main
    )

	;;;* GET STRING WITH DEFAULT
	(defun _DefGetString (prmpt default allowspace / d2)
	  (if allowspace
	    (setq
	      ans
	       (cond
	         ((not
	            (= (setq
	                 d2 (getstring T (strcat prmpt " <" default ">: "))
	               ) ;_ end of setq
	               ""
	            ) ;_ end of =
	          ) ;_ end of not
	          d2
	         )
	         (default)
	       ) ;_ end of cond
	    ) ;_ end of setq
	    (setq
	      ans
	       (cond
	         ((not
	            (= (setq d2 (getstring (strcat prmpt " <" default ">: ")))
	               ""
	            ) ;_ end of =
	          ) ;_ end of not
	          d2
	         )
	         (default)
	       ) ;_ end of cond
	    ) ;_ end of setq
	  ) ;_ end of if
	  ans
	) ;_ end of defun
  

    (defun _get_item ( collection key / item )
        (vl-catch-all-apply
           '(lambda ( ) (setq item (vla-item collection key)))
        )
        item
    )

    (defun _right ( str n / len )
        (if (< n (setq len (strlen str)))
            (substr str (1+ (- len n)))
            str
        )
    )

    (defun _make_key ( collection prefix len / key )
        (   (lambda ( i pad )
                (while
                    (_get_item collection
                        (setq key
                            (strcat prefix
                                (_right
                                    (strcat pad (itoa (setq i (1+ i))))
                                    len
                                )
                            )
                        )
                    )
                )
                key
            )
         ;;;0
            99999
            (   (lambda ( pad )
                    (while (< (strlen pad) len)
                        (setq pad (strcat "0" pad))
                    )
                    pad
                )
                ""
            )
        )
    )


    (defun _dynamic->static_block ( blocks insert len )
        (vla-ConvertToStaticBlock
            insert
            (_make_key blocks *UnDynamic:Prefix* len)
        )
    )


    (defun _get_locked ( layers / locked )
        (vlax-for layer layers
            (if (eq :vlax-true (vla-get-lock layer))
                (setq locked (cons layer locked))
            )
        )
        locked
    )


    (defun _get_dynamic_inserts ( blocks / block object inserts )
        (vlax-for block blocks
            (vlax-for object block
                (if (eq "AcDbBlockReference" (vla-get-objectname object))
                    (if (eq :vlax-true (vla-get-isdynamicblock object))
                        (setq inserts (cons object inserts))
                    )
                )
            )
        )
        inserts
    )
  

    (defun _get_dynamic_inserts_from_pickset ( ss / i object inserts )
        (setq i 0)
        (while (< i (sslength ss))
                (setq object (vlax-ename->vla-object (ssname ss i)))
                (if (eq "AcDbBlockReference" (vla-get-objectname object))
                    (if (eq :vlax-true (vla-get-isdynamicblock object))
                        (setq inserts (cons object inserts))
                    )
                )
                (setq i (1+ i))
        )
        inserts
    )


    (defun _main ( document / ss blocks inserts locked len )
        (if (not *UnDynamic:Prefix*)
          (setq *UnDynamic:Prefix* "STATIC_")
        )
        (if (and
              (setq blocks (vla-get-blocks document))
              (setq ss (ssget ":L" (list (cons 0 "INSERT"))))
              (setq inserts (_get_dynamic_inserts_from_pickset ss))
              (setq *UnDynamic:Prefix* (_DefGetString "\nPrefix for static block names" *UnDynamic:Prefix* T))
            )
;;;            (setq inserts
;;;                (_get_dynamic_inserts
;;;                    (setq blocks (vla-get-blocks document))
;;;                )
;;;            )
            
            (progn
;;;                (foreach layer (setq locked (_get_locked (vla-get-layers document)))
;;;                    (vla-put-lock layer :vlax-false)
;;;                )
;;;                (setq len (strlen (itoa (length inserts))))
                (setq len 6)
                (foreach insert inserts
                    (_dynamic->static_block blocks insert len)
                )
;;;                (foreach layer locked
;;;                    (vla-put-lock layer :vlax-true)
;;;                )
                (princ "\n...done.")
            )
            (princ "\nNo dynamic blocks found - no block inserts were changed.")
        )
        (princ)
    )

    (_main (vla-get-activedocument (vlax-get-acad-object)))

)

;|«Visual LISP© Format Options»
(72 2 40 2 T "end of " 60 2 0 0 0 nil T nil T)
;*** DO NOT add text below the comment! ***|;
Message 4 of 7
braudpat
in reply to: braudpat

Hello

Thanks for your effort !

I will check and test on Monday/Tuesday...

Regards, Patrice
Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 5 of 7
braudpat
in reply to: lando7189

 

Hello Lanny

 

THANKS it's exactly what I need !


Sorry for my delay to test and VALIDATE, Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 6 of 7
RBernaz
in reply to: lando7189

Hi I would like to tell that this is an excellent routine. I would like to know if it can be improved by adding one more action. 

I need to use this routine which is fantastic but my dynamic blocks have fields with calculations on it and when I do the undynamic those fields become lost and ilegible.

What I would like to know is if this same undynamic routine can include a convert field to text before the undynamic action.

I have a lisp which I found it her as well and I would like to know a way to join both together.

Simple field to text + undynamic, by selection

 

Thank you in advance   

Message 7 of 7
ndikesh
in reply to: lando7189

Hi there, can you please modify it so that it automatically does

  • selects all the objects in the drawing and
  • prefix for static block name "static" 

Regards

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost