a code to save all the block in the file to individual dxf with its block name

formobalaji
Enthusiast
Enthusiast

a code to save all the block in the file to individual dxf with its block name

formobalaji
Enthusiast
Enthusiast

i need a autolips code to save all the block in the file to individual dxf with its block name

0 Likes
Reply
Accepted solutions (1)
800 Views
13 Replies
Replies (13)

paullimapa
Mentor
Mentor

this app will let you select the blocks you want and export them out as dwg

https://apps.autodesk.com/ACD/en/Detail/Index?id=6861263512373641535&appLang=en&os=Win32_64


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

daniel_cadext
Advisor
Advisor

You can do this in ARX or .NET

I’m using Python just because it’s easy to prototype quick stuff

https://github.com/CEXT-Dan/PyRx

 

 

 

 

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import traceback

def PyRxCmd_doit():
    try:
        db = Db.curDb()
        bt = Db.BlockTable(db.blockTableId())
        for name, id in bt.toDict().items():
            btr = Db.BlockTableRecord(id)
            if btr.isLayout():
                continue
            if btr.isAnonymous():
                continue
            if btr.isFromExternalReference():
                continue
            if btr.isFromOverlayReference():
                continue
            if(name.startswith("A$")):
                continue
            doutDb = db.wblock(id)
            outDb.dxfOut("E:\\temp\\{}.DXF".format(name))
            
    except Exception as err:
        traceback.print_exception(err)

 

 

 

output.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes

formobalaji
Enthusiast
Enthusiast

THANKS FOR REPLY

BUT I NEED IN AUTOLISP

daniel_cadext
Advisor
Advisor

maybe this

https://blog.draftsperson.net/wblock-all-lisp-routine/

just replace the extension from .dwg to .dxf

I didn't try though

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes

diagodose2009
Collaborator
Collaborator

 

╔═══════════════════════════════════════════╗
║ Nr. blocuri =35
║ Format-nume BlocK = *
║ Ora si data = 
║ Cale pe disc = C:\Vlaxcompil\0User\
║ Timpul de scriere = *
║ Lista numelor blocurilor este 
║ si blocuri sunt   salvat\343 in acelasi 
║ director << Here you all names>
╠═══════════════════════════════════════════╣
║ NORD1
║ STILBET
║ PUTAMER
║ PUNCT
║ CVCAN
║ GAGER
║ HIDRANT
║ CVGAZE
║ CVTEL
║ PTSTALP
║ STLEA
║ STELLIN
║ STLEMN
║ STILLMN
║ STTEL
║ STELCF

 

 

 

 

  • 😃I have the programe , export many blocks to path, but with extension Dwg.
  • If you need ,forced to DXF, then you send  the pm. to me

00)Always you save the "CurrentDrawing.dwg" , where your need path for store all blocks/dwg

01)You  see the snapshot.gif 

02You my explorer-picture "topGradRepeat.jpg:

03)You open "anexa1_35_landscapeb5_2k.dwg"

04)You appload "pp_libcache_block_plugin.vlx"

06)You enter the command (C:q2) pr Q2[enter]

  • You need the full-source(directly.lsp100%) then we can collaborate online 
  • or you change the language to english, germany, polish for pp_libcache_block_plugin.vlx
0 Likes

paullimapa
Mentor
Mentor

Try this: DwgACCBlk2Dxf.lsp

It'll first export all the blocks as dwgs.

Then it'll convert them to dxfs.

So you'll end up with both dwgs & dxfs.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

komondormrex
Advisor
Advisor
Accepted solution

check the following. will save all drawing blocks to drawing path\All_Blocks_DXF\ in DXF format. if block with same name already is in directory it will be skipped.

 

 

(defun c:all_dwg_blocks_to_dxf (/ blocks_dxf_directory block_count block_name block_dxf_name)
	(setvar 'cmdecho 0) 
	(setq blocks_dxf_directory (strcat (vlax-get (vla-get-activedocument (vlax-get-acad-object)) 'path) "\\All_Blocks_DXF")
	      block_count 0
	)
	(if (null (vl-file-directory-p blocks_dxf_directory))
		  (vl-mkdir blocks_dxf_directory)
	)
	(vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (block)
			(and
			  	(setq block_name (vla-get-name block))
				(snvalid block_name)
				(null (findfile (setq block_dxf_name (strcat blocks_dxf_directory "\\" (setq block_name (vla-get-name block)) ".dxf"))))
				(setq block_count (1+ block_count))
				(command "_-wblock" block_dxf_name "" block_name)
			)
		 )
	)
	(setvar 'cmdecho 1)
	(princ (strcat "\nTotal " (itoa block_count) " blocks saved to \"" blocks_dxf_directory "\" directory"))
	(princ)
)

 

 

formobalaji
Enthusiast
Enthusiast

in ABOVE CODE need ADDITIONALLY ONE to automatically explode all the blocks before SAVING

 

0 Likes

paullimapa
Mentor
Mentor

Lots of options by just doing a simple search like this one

https://www.cadtutor.net/forum/topic/44634-explode-all-blocks/


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

komondormrex
Advisor
Advisor

added

 

(defun c:all_dwg_blocks_to_dxf (/ insert_sset exploded_list blocks_dxf_directory block_count block_name block_dxf_name)
	(if (setq insert_sset (ssget "_x" '((0 . "insert"))))
		(foreach insert (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset))))
			(setq exploded_list (list insert))
			(while exploded_list
				(foreach insert exploded_list 
					(setq exploded_list (append exploded_list (vlax-invoke insert 'explode))
						  exploded_list (vl-remove insert exploded_list)
					)
					(vla-erase insert)
				)
				(setq exploded_list (vl-remove-if-not 
										'(lambda (object) (= "AcDbBlockReference" (vla-get-objectname object))) 
										 exploded_list
									)
				)
			)
		)
	)
	(setvar 'cmdecho 0) 
	(setq blocks_dxf_directory (strcat (vlax-get (vla-get-activedocument (vlax-get-acad-object)) 'path) "\\All_Blocks_DXF")
	      block_count 0
	)
	(if (null (vl-file-directory-p blocks_dxf_directory))
		  (vl-mkdir blocks_dxf_directory)
	)
	(vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (block)
			(and
			  	(setq block_name (vla-get-name block))
				(snvalid block_name)
				(null (findfile (setq block_dxf_name (strcat blocks_dxf_directory "\\" (setq block_name (vla-get-name block)) ".dxf"))))
				(setq block_count (1+ block_count))
				(command "_-wblock" block_dxf_name "" block_name)
			)
		 )
	)
	(setvar 'cmdecho 1)
	(princ (strcat "\nTotal " (itoa block_count) " blocks saved to \"" blocks_dxf_directory "\" directory"))
	(princ)
)

 

0 Likes

formobalaji
Enthusiast
Enthusiast

SORRY

ACTUALLY WHAT IAM LOOKING FOR IS, AFTER EXTACTING THE BLOCKS AND SAVING IT AS SEPARTED DXF, I NEED TO EXPLODE THE SKETCH IN THE NEW CREATED DXF

0 Likes

komondormrex
Advisor
Advisor

you'd better post an example of your block and show what you need to be exploded.

0 Likes

formobalaji
Enthusiast
Enthusiast

NEED TO SAVE THE BLOCKS IN DXF V2010

0 Likes