Jump to content

Dynamic Block Insertion and Use


Recommended Posts

Posted

Save the attached dynamic block somewhere. Load and run the program "dropin". I run it in a clean, empty, new drawing. Pick the block from your computer. Dropin will insert the block 3 times. Watch the screencast of the dynamic block error. Do you get the same result? 

 

I select the block to highlight the grips. I use a stretch grip to stretch the block. The block looks horrible. Lines are partially stretched or not stretched at all. So I leave it highlighted and type "bedit" at the command line. I enter block editor - I've learned that I have to change something no matter how small or insignificant. I've learned that all I have to do is change the zoom, so I give my scroll wheel a little 'flick'. Then I exit the block editor, saving changes. When it goes back to the drawing, the block has repaired itself and looks correct.

This has been going on for about 5 years that I'm aware. I've tried a "resetblock" command after inserting it. I've tried regens. I recently read a post that said "You can't use the basepoint parameters in dynamic blocks. They're broken, they don't work." I looked and had basepoints, so I deleted them. But that doesn't look like that was it. I suspect there's a bug in vla-insertblock. Does anyone have an AutoLISP routine that replaces that command? I need the function of that command, I need to be able to insert the block onto any space: Model Space, any Paper Space tab, etc.

 

Anyone have a solution? I don't know if there's an error in the block, or the code. I started typing this into the "Bug" forum, but stopped because if you insert the block manually it works fine. Seems like something I don't understand in the code. Thanks in advance. Sorry if I formatted anything wrong. (Is there a particular way to attach a screencast?

 

Screencast: https://autode.sk/2XP7nQj

 

(DEFUN c:dropin	(/	A      BLOCKNAME     I#	   INDEX
		 OCA	OCN    PT     S#     T1	    TEXT   TOTMODS
		 VOBJECT       X
		)
  (vl-load-com)
  (setq	oca	  '((18 18 18 18) (18 18 18 18 19) (17 17 17 17))
	INDEX	  1
	T1	  NIL
	pt	  '(0 0)
	BLOCKNAME (getfiled "Select Block" "" "dwg" 16)
	oca	  '((19 19 19 19) (18 18 18 18) (19 19 18 18))
	ocn	  '((1) (2) (3))
  )					;SETQ
  (FOREACH A OCA
    (SETQ vobject
		  (vla-insertblock
		    (vlax-get-property
		      (vla-get-activedocument (vlax-get-acad-object))
		      'modelspace
		    )
		    (vlax-3D-point (trans pt 1 0))
		    blockname
		    1.0
		    1.0
		    1.0
		    0.0
		  )
	  INDEX	  1
	  text	  nil
	  totmods 0
	  i#	  (car (nth (vl-position a oca) ocn))
	  s#	  1
    )					;setq
    (mapcar
      '(lambda (x)
	 (if (= "Lookup1" (vla-get-propertyname x))
	   (vla-put-value
	     x
	     (vlax-make-variant
	       (length A)
	       (vlax-variant-type (vla-get-value x))
	     )
	   )
	 )
       )
      (vlax-invoke vobject 'getdynamicblockproperties)
    )
    (FOREACH B A
      (SETQ TEXT    (APPEND TEXT
			    (LIST (CONS	(STRCAT	"STRING"
						(ITOA (- (length A) 3))
						"-"
						(ITOA INDEX)
					)
					(STRCAT	"INV"
						(if (= (strlen (itoa i#)) 1)
						  (strcat "0" (itoa i#))
						  (itoa i#)
						)
						"-"
						"S"
						(if (= (strlen (itoa s#)) 1)
						  (strcat "0" (itoa s#))
						  (itoa s#)
						)
						":("
						(itoa b)
						")"
					)
				  )
			    )
		    )
	    INDEX   (1+ INDEX)
	    totmods (+ totmods b)
	    s#	    (1+ s#)
      )					;SETQ
    )					;FOREACH
    (SETQ TEXT (APPEND TEXT
		       (LIST (CONS "SUB-ARRAY-LINE-1"
				   (strcat "("
					   (itoa totmods)
					   ") BOB'S AWESOME MODULES"
				   )
			     )
		       )
	       )
	  TEXT (APPEND TEXT
		       (LIST (CONS "ES#"
				   (strcat (ITOA (1+ (CADR A)))
				   )
			     )
		       )
	       )
    )					;setq
    (mapcar
      '(lambda (x)
	 (if (assoc (vla-get-tagstring x) text)
	   (vla-put-textstring
	     x
	     (cdr (assoc (vla-get-tagstring x) text))
	   )
	 )
       )
      (vlax-invoke vobject 'getattributes)
    )					;mapcar
    (SETQ PT (POLAR PT (* PI 1.5) 3)
    )
  )
)					;dropin

 

2DED 1-Line Array.dwg

Posted (edited)

Hmm, that's a first for me. For all the times I've used vla-insertblock, it never glitches like that. Quite funny.

Edited by Jonathan Handojo
Posted

paste your block into Bcad just normal block not DB. only 1 grip: Insertion point. no others stretch grips etc..

or incompatible? (some members still using <2010)

 

not sure, try vla-update 

Posted

I might be missing something, but you have 2 oca variables in first (setq)... What do you want to achieve with this?

Posted
14 minutes ago, marko_ribar said:

I might be missing something, but you have 2 oca variables in first (setq)... What do you want to achieve with this?

 

Now that I looked at your screencast I understand what is the problem... You probably typed oca twice for testing purposes...

Haven't tested your code with your attached Dynamic block, but I see it in screencast. However I don't know what could be the thing that's causing problem with stretch action in newly insertions of DB...

Posted

If it will make you feel better and on my testings A2018 it bahaves exactly like in your screencast - there is some kind of bug... Still I've checked your code and it looks good to me, I only changed one line in portion where you change "Lookup1" value... I don't know much with DB, but here is my revision although it's all in vain and with unpredicted symptoms.

 

(DEFUN c:dropin ( / BLOCKNAME I# INDEX OCA OCN PT S# TEXT TOTMODS VOBJECT )
  (vl-load-com)
  (setq INDEX        1
        pt           '(0 0)
        BLOCKNAME    (getfiled "Select Block" "" "dwg" 16)
        oca          '((19 19 19 19) (18 18 18 18) (19 19 18 18))
        ocn          '((1) (2) (3))
  )                                        ;SETQ
  (FOREACH A OCA
    (SETQ vobject
                  (vla-insertblock
                    (vlax-get-property
                      (vla-get-activedocument (vlax-get-acad-object))
                      'modelspace
                    )
                    (vlax-3D-point (trans pt 1 0))
                    blockname
                    1.0
                    1.0
                    1.0
                    0.0
                  )
          INDEX   1
          text    nil
          totmods 0
          i#      (car (nth (vl-position a oca) ocn))
          s#      1
    )                                        ;setq
    (mapcar
      '(lambda ( x )
         (if (= "Lookup1" (vla-get-propertyname x))
           (vla-put-value
             x
             (nth (length A) (safearray-value (variant-value (vla-get-allowedvalues x))))
           )
         )
       )
      (vlax-invoke vobject 'getdynamicblockproperties)
    )
    (FOREACH B A
      (SETQ TEXT    (APPEND TEXT
                            (LIST (CONS (STRCAT "STRING"
                                                (ITOA (- (length A) 3))
                                                "-"
                                                (ITOA INDEX)
                                        )
                                        (STRCAT "INV"
                                                (if (= (strlen (itoa i#)) 1)
                                                  (strcat "0" (itoa i#))
                                                  (itoa i#)
                                                )
                                                "-"
                                                "S"
                                                (if (= (strlen (itoa s#)) 1)
                                                  (strcat "0" (itoa s#))
                                                  (itoa s#)
                                                )
                                                ":("
                                                (itoa b)
                                                ")"
                                        )
                                  )
                            )
                    )
            INDEX   (1+ INDEX)
            totmods (+ totmods b)
            s#      (1+ s#)
      )                                        ;SETQ
    )                                        ;FOREACH
    (SETQ TEXT (APPEND TEXT
                       (LIST (CONS "SUB-ARRAY-LINE-1"
                                   (strcat "("
                                           (itoa totmods)
                                           ") BOB'S AWESOME MODULES"
                                   )
                             )
                       )
               )
          TEXT (APPEND TEXT
                       (LIST (CONS "ES#"
                                   (strcat (ITOA (1+ (CADR A)))
                                   )
                             )
                       )
               )
    )                                        ;setq
    (mapcar
      '(lambda ( x )
         (if (assoc (vla-get-tagstring x) text)
           (vla-put-textstring
             x
             (cdr (assoc (vla-get-tagstring x) text))
           )
         )
       )
      (vlax-invoke vobject 'getattributes)
    )                                        ;mapcar
    (SETQ PT (POLAR PT (* PI 1.5) 3))
  )
  (princ)
)                                        ;dropin

 

Posted

Like you suspected, you were right... The problem was (vla-insertblock)... I've retested and now everything worked as desired with this revision :

 

(DEFUN c:dropin ( / *ERROR* BLOCKNAME I# INDEX OCA OCN PT S# TEXT TOTMODS VOBJECT ATTR )

  (vl-load-com)

  (defun *error* ( m )
    (if attr (setvar 'attreq attr))
    (if m (prompt m))
    (princ)
  )

  (setq INDEX        1
        pt           '(0 0)
        BLOCKNAME    (getfiled "Select Block" "" "dwg" 16)
        oca          '((19 19 19 19) (18 18 18 18) (19 19 18 18))
        ocn          '((1) (2) (3))
  )                                        ;SETQ
  (setq attr (getvar 'attreq))
  (setvar 'attreq 0)
  (FOREACH A OCA
    (SETQ INDEX   1
          text    nil
          totmods 0
          i#      (car (nth (vl-position a oca) ocn))
          s#      1
    )                                        ;setq
    (vl-cmdf "_.-INSERT" BLOCKNAME "_S" 1.0 "_R" 0.0 "_non" pt)
    (setq vobject (vlax-ename->vla-object (entlast)))
    (mapcar
      '(lambda ( x )
         (if (= "Lookup1" (vla-get-propertyname x))
           (vla-put-value
             x
             (nth (length A) (safearray-value (variant-value (vla-get-allowedvalues x))))
           )
         )
       )
      (vlax-invoke vobject 'getdynamicblockproperties)
    )
    (FOREACH B A
      (SETQ TEXT    (APPEND TEXT
                            (LIST (CONS (STRCAT "STRING"
                                                (ITOA (length A))
                                                "-"
                                                (ITOA INDEX)
                                        )
                                        (STRCAT "INV"
                                                (if (= (strlen (itoa i#)) 1)
                                                  (strcat "0" (itoa i#))
                                                  (itoa i#)
                                                )
                                                "-"
                                                "S"
                                                (if (= (strlen (itoa s#)) 1)
                                                  (strcat "0" (itoa s#))
                                                  (itoa s#)
                                                )
                                                ":("
                                                (itoa b)
                                                ")"
                                        )
                                  )
                            )
                    )
            INDEX   (1+ INDEX)
            totmods (+ totmods b)
            s#      (1+ s#)
      )                                        ;SETQ
    )                                        ;FOREACH
    (SETQ TEXT (APPEND TEXT
                       (LIST (CONS "SUB-ARRAY-LINE-1"
                                   (strcat "("
                                           (itoa totmods)
                                           ") BOB'S AWESOME MODULES"
                                   )
                             )
                       )
               )
          TEXT (APPEND TEXT
                       (LIST (CONS "ES#"
                                   (strcat (ITOA (1+ (CADR A)))
                                   )
                             )
                       )
               )
    )                                        ;setq
    (mapcar
      '(lambda ( x )
         (if (assoc (vla-get-tagstring x) text)
           (vla-put-textstring
             x
             (cdr (assoc (vla-get-tagstring x) text))
           )
         )
       )
      (vlax-invoke vobject 'getattributes)
    )                                        ;mapcar
    (SETQ PT (POLAR PT (* PI 1.5) 3))
  )                                          ;foreach
  (*error* nil)
)                                        ;dropin

HTH., M.R.

Posted

I'm not familiar with vla-update. I can't seem to find documentation on it. I'll continue to look into it.

 

I was hoping for a revelation here, I have it on the autodesk forum as well. This has been going on for me for 5 years. One thing I tried this week seems to work-around. And for all the bugs I find, a quick work-around is good enough for me. I said I tried the "resetblock" and thought it was working but recently found out that it was not. Here's the flow I tried previously:

 

vla-insertblock

(command "resetblock" (entlast) "")

set dynamic block properties

populate attributes

 

Here's what I tried that seems to work:

vla-insertblock

set dynamic block properties

populate attributes

(command "resetblock" (entlast) "")

set dynamic block properties

 

Yeah, I had to set the properties twice. But here's another oddity. On the last block that's inserted & messed up, this doesn't work. So what I did was wrote a little routine that:

 

get dynamic block properties

"resetblock"

set dynamic block properties back with the ones I just got

 

I run that routine at the exit of the program, and inside my error trap program in case someone escapes out. That seems to clear this up. In my own testing it works. But I haven't yet given it out to my co-workers for use. So we'll see if that's a fix.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...