Blocks from dwg files

Blocks from dwg files

Anonymous
Not applicable
1,119 Views
8 Replies
Message 1 of 9

Blocks from dwg files

Anonymous
Not applicable

Hello

I have 331 dwg files with objects I would like to convert to blocks inside one dwg file . For example I have file bgb.dwg with two arcs i would like to convert to block bgb. Is any simple way to do it automatic with lisp?

 

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

Anonymous
Not applicable

Or how to insert 331 blocks ( i know blocks name) at 0,0 point with lisp or command?

0 Likes
Message 3 of 9

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Or how to insert 331 blocks ( i know blocks name) at 0,0 point with lisp or command?


 

You mean you wanted the blocks to inserted and not just part of a drawing block collection?

(defun c:InsertThem ( / aDoc f dwgFiles StrDiaFnme fnSTR StrDIA dd F2process insertedfile)
(setq aDoc (vla-get-activedocument (vlax-get-acad-object)))
  (and
	(setq f (acet-ui-pickdir "Select Project Folder" (getvar 'dwgprefix)))
	(setq dwgFiles (vl-directory-files f  "*.dwg"  1))
	(progn
		(setq StrDiaFnme (vl-filename-mktemp "tmp.DCL"))
	      	(setq fnSTR (open StrDiaFnme "w"))
	            (write-line
	                  "dcl_settings : default_dcl_settings { audit_level = 3; }
			  ListOfTags : dialog 
			  { label = \"Select Tag(s)\"; 
			  : list_box { key = \"TagList\"; multiple_select = true;
			  width = 8.0; height = 30.0; } spacer ;
			  ok_cancel;  }"              fnSTR)
	            	(close fnSTR)
		(setq StrDIA (load_dialog StrDiaFnme))
		(if (not (new_dialog "ListOfTags" StrDIA))
		  (exit)
		  )
		(start_list "TagList")
		(mapcar 'add_list dwgFiles)
		(end_list)
		(action_tile "TagList" "(setq dd (get_tile \"TagList\"))")
		(action_tile "accept" "(done_dialog 1)")
		(action_tile "cancel" "(done_dialog 0)")
		(start_dialog)
		(unload_dialog StrDIA)
	        (vl-file-delete StrDiaFnme)
		dd
                  )
	  (setq F2process (mapcar '(lambda (k) (nth k dwgFiles))
	                                     (read (strcat "(" dd ")"))))
	  (foreach itm F2process
	    (vlax-invoke (vlax-get (vla-get-ActiveLayout aDoc)
	                                         'Block)
	                                   'InsertBlock
	                                   '(0.0 0.0 0.0)
	                                   (setq insertedfile (strcat f "\\" itm))
	                                   1 1 1 0)
	    (print  insertedfile)
	    )
  	)
  (princ)
  )

This way, the user gets to select the files to be inserted.

HTH

 

 

Message 4 of 9

maratovich
Advisor
Advisor

Please attach an example of your files (2-3) and an example of how it should turn out.

Maybe this will help you: AutoImportCAD 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 5 of 9

Anonymous
Not applicable

It was exactly what i was trying to do 🙂 Great job

0 Likes
Message 6 of 9

pbejse
Mentor
Mentor

@Anonymous wrote:

It was exactly what i was trying to do 🙂 Great job


Glad it works for you.

You are welcome 😊

 

0 Likes
Message 7 of 9

cadffm
Consultant
Consultant

And if you don't have a tool, ot ACAD LT, use the XREF method, then bind(insert) xrefs to blocks.

Run Attsync if attdefs are involved

done.

 

 

Sebastian

Message 8 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

If you want all drawings in a specific folder  brought into the current drawing as Blocks, >here< are two routines, BlockImport.lsp that only brings them in as Block definitions, and BlockChart.lsp that Inserts them all in rows as a kind of chart.

Kent Cooper, AIA
Message 9 of 9

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

... that only brings them in as Block definitions..


 

That is my preference as well, I tweaked the code to insert the block onto the current layout as it is the requirement.

The orignal code use CopyObjects and ObjectDBX. 

 

Nice work with BlockChart.lsp BTW. 

 

0 Likes