Insert static block from dynamic block

Insert static block from dynamic block

djurk_haas
Advocate Advocate
1,969 Views
8 Replies
Message 1 of 9

Insert static block from dynamic block

djurk_haas
Advocate
Advocate

Hello,

 

I have a drawing with several dynamic blocks in it.

The dwg file must be read into another program that is only suitable for static blocks.

So I need a lisp that inserts static blocks based on data in the dynamic blocks. An example drawing has been added to the appendix.

 

The static block must inherit the following data (attributes) from the dynamic block:

1 blockname = "Ultimo_ID-Tappunt" (visibilitystate dynamic block = Tappunt) at wich the attribute value (TAG: LEGIONELLA) is composed: ("Tagvalue BOUWDEEL" "." "T" "Tagvalue NUMMER_TAPPUNT")

or

2 blockname =  "Ultimo_ID-Keerklep" (visibilitystate dynamic block = Keerklep) at wich the attribute value (TAG: LEGIONELLA) is composed: ("Tagvalue BOUWDEEL" "." "K" "Tagvalue NUMMER_KEERKLEP")

 

The static blocks must be inserted with the same coordinates of the dynamicblocks.

 

I had a work arround wich was based on the following:

(command "_-INSERT" "Ultimo_ID-Tappunt" "61656, -12576" 1 1 0 "A00.T001" )

(command "_-INSERT" "Ultimo_ID-Keerklep" "50656, -45576" 1 1 0 "A00.K002" )

but somehow this code doesn't work anymore (when pasting on the commandline).

 

Thanks in advance

0 Likes
Accepted solutions (2)
1,970 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

I would think that the best approach would be to insert a dynblock as it is and undynamic it backward.

Attached a routine from my archive. Credits to MP from theswamp.

I think you can manage on your own to find the main sub and use it... do you?

 

 
Message 3 of 9

djurk_haas
Advocate
Advocate

Thanks for the quick response.


I have already seen thas lisp, but it gives each static block a unique name.
I just want the two blockname as indicated in my first post.

In addition, it would be great if the attrtibute value of the static block can be composed from the different tag in the dynamic block.

Message 4 of 9

ronjonp
Mentor
Mentor

This should give you a start .. no time to pretty it up for you.

(defun c:foo (/ s v v1)
  (if (setq s (ssget ":L" '((0 . "insert"))))
    (foreach o (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      (and (setq v (vl-remove-if-not
		     '(lambda (x) (wcmatch (strcase (vlax-get x 'propertyname)) "*VISIBILITY*"))
		     (vlax-invoke o 'getdynamicblockproperties)
		   )
	   )
	   (setq v (vlax-get (car v) 'value))
	   (setq v1
		  (vl-remove-if-not
		    '(lambda (x) (wcmatch (strcase (vlax-get x 'tagstring)) "BOUWDEEL,NUMMER_KEERKLEP"))
		    (vlax-invoke o 'getattributes)
		  )
	   )
	   (= 2 (length v1))
	   (setq v
		  (apply 'strcat (append (list (strcat "Ultimo_ID-" v)) (mapcar 'vla-get-textstring v1)))
	   )
	   (not (tblobjname "block" v))
	   (vla-converttostaticblock o v)
      )
    )
  )
  (princ)
)
(vl-load-com)
0 Likes
Message 5 of 9

djurk_haas
Advocate
Advocate

 

Hello,

 

Thankd for your reply but this code makes a static block and gives each individual static block a different name, while for my application it is important that the name of the static blocks remains the same.

 

Is it possible to create a code based on the code I am now generating using Excel: (command "_-INSERT" "Ultimo_ID-Tapping" "61656, -12576" 1 1 0 "A00.T001")

 

My reasoning is to store the value of the attributes in the dynamic block in different variables that we then use to insert the static block.

So from the dynamic block “TAPPUNT_CZE” store the following variables (tags in capital letters):

“POSITIE” -> setq positie

“BOUWDEEL” -> setq bouwdeel

“TAPPUNT/KEERKLEP”  -> setq tapkeer (can only be “T” or “K”)

 

If variable tapkeer is “T” then setq nr = “NUMMER_TAPPUNT”

If variable tapkeer is “K” then setq nr = “NUMMER_KEERKLEP”

 

(setq legionella(stracat(bouwdeel ”.” tapkeer nr)))

 

If variable tapkeer is “T” then setq blockname = “Ultimo_ID-Tappunt”

If variable tapkeer is “K” then setq blockname = “Ultimo_ID-Keerklep”

 

The static blocks may then be inserted with:

(command "_-INSERT" blockname positie 1 1 0 legionella )

 

I hope someone can follow my train of thought and translate it into a working code.

 

Thanks in advance for the effort taken!

0 Likes
Message 6 of 9

pbejse
Mentor
Mentor

 


@djurk_haas wrote:

...this code makes a static block and gives each individual static block a different name, while for my application it is important that the name of the static blocks remains the same.


Can you show that to us on the sample drawing that you posted [ WA-tappunt.dwg ] .

 


@djurk_haas wrote:

So from the dynamic block “TAPPUNT_CZE” store the following variables (tags in capital letters):

“POSITIE” -> setq positie


What is the source for “POSITIE”? are you sure that's a TAG? 

Please be aware that you can only have one "look" per blockname.

 

 

0 Likes
Message 7 of 9

pbejse
Mentor
Mentor
Accepted solution

I just realize @djurk_haas , that there are no conversion involve. so scratch whatever is said on my previous post.

Gather data from Dynamic Block , then insert a static block. 

 

Change the name to whatever you prefer. right now its just something

(defun c:something ( / data ss i ev edp positie vv vatb bouwdeel tapkeer legionella nr)
(setq data '(("Keerklep" "NUMMER_KEERKLEP" "Ultimo_ID-Tappunt")
	     ("Tappunt" "NUMMER_TAPPUNT" "Ultimo_ID-Keerklep"))
      )
      (if (and
                (vl-every '(lambda (b)
                      (tblsearch "BLOCK" b))
                            (cons "TAPPUNT_CZE" (mapcar 'caddr data)))
                (setq ss  (ssget ":L" '((0 . "insert")(66 . 1))))
                )
          (repeat (setq i (sslength ss))
                (setq ev (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
		(if
                      (and
	                (eq (strcase (vla-get-effectivename ev)) "TAPPUNT_CZE")
	                (setq edp (vl-some '(lambda (dp)
	                                          (if (eq (vlax-get dp 'propertyname) "Visibility1") dp))
	                                (vlax-invoke ev 'getdynamicblockproperties)
	                                )
	                      )
	                (setq positie (vlax-get ev 'Insertionpoint))
	                (setq vv (vlax-get edp 'value))
	                (setq vatb (mapcar '(lambda (at)
	                                 (list (vla-get-tagstring at)(vla-get-textstring at)))
				    (vlax-invoke ev 'Getattributes))
				  )
	         	(setq bouwdeel (cadr (assoc "BOUWDEEL" vatb)))
	        	(Setq tapkeer  (cadr (assoc "TAPPUNT/KEERKLEP" vatb)))
	        	(setq nr (assoc tapkeer data))
	                (setq legionella (strcat bouwdeel "." tapkeer "." (Cadr nr)))
	                (setq blockname  (caddr nr))
	                (Setq insertedblock (vlax-invoke
	                 		(vlax-get (vla-get-ActiveLayout
	                                               (vla-get-activedocument
	                                                     (vlax-get-acad-object)))
	                                         'Block) 'InsertBlock
	                                   positie blockname 1 1 1 0))
                	)
                (setpropertyvalue (vlax-vla-object->ename insertedblock) "LEGIONELLA" legionella)
                		)
            		)
		)      
	(princ)
      )

 HTH

 

0 Likes
Message 8 of 9

djurk_haas
Advocate
Advocate

Hello,

 

Thanks for the code it works perfectly.

Now, however, you have to select each block individually.
Is it also possible to automatically select all blocks with the name "TAPPUNT_CZE" at once?

 

 

0 Likes
Message 9 of 9

pbejse
Mentor
Mentor
Accepted solution

@djurk_haas wrote:

Thanks for the code it works perfectly.


You are welcome @djurk_haas 

 


@djurk_haas wrote:

Is it also possible to automatically select all blocks with the name "TAPPUNT_CZE" at once?


Yes of course

Change this

 

 

 (setq ss  (ssget ":L" '((0 . "insert")(66 . 1))))

 

to

 

 (setq ss  (ssget "_X" '((0 . "insert")(66 . 1))))

 

But that will select all BLOCKS on the drawing, only unaltered Dynamic blocks will keep its name as it was , but any changes the users made on the block will give you an anonymous name intead.

 Block Name: "TAPPUNT_CZE"
 Anonymous Name: "*U13"
(ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "TAPPUNT_CZE")))

That will only select the Dynamic block TAPPUNT_CZE  on its unaltered state. and will ignore the rest.

 

This one is the same as above but it includes all blocks with the prefx "*U"

(ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "`*U*,TAPPUNT_CZE")))

The other blocks will be ignored anyway during processing.

 

(eq (strcase (vla-get-effectivename ev)) "TAPPUNT_CZE")

 

Finally, we can another filter, blocks under  "_Ultimo_ID" layer,  and only at Model Space

 (setq ss  (ssget "_X" '((0 . "insert")(66 . 1)(2 . "`*U*,TAPPUNT_CZE")(410 . "Model")(8 .  "_Ultimo_ID"))

HTH

 

 

0 Likes