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

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

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
formobalaji
800 Views, 13 Replies

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

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

13 REPLIES 13
Message 2 of 14
paullimapa
in reply to: formobalaji

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
Message 3 of 14
daniel_cadext
in reply to: formobalaji

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
Message 4 of 14
formobalaji
in reply to: daniel_cadext

THANKS FOR REPLY

BUT I NEED IN AUTOLISP

Message 5 of 14
daniel_cadext
in reply to: formobalaji

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
Message 6 of 14
diagodose2009
in reply to: formobalaji

 

╔═══════════════════════════════════════════╗
║ 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
Message 7 of 14
paullimapa
in reply to: formobalaji

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
Message 8 of 14
komondormrex
in reply to: formobalaji

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

 

 

Message 9 of 14
formobalaji
in reply to: formobalaji

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

 

Message 10 of 14
paullimapa
in reply to: formobalaji

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
Message 11 of 14
komondormrex
in reply to: formobalaji

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

 

Message 12 of 14
formobalaji
in reply to: formobalaji

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

Message 13 of 14
komondormrex
in reply to: formobalaji

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

Message 14 of 14
formobalaji
in reply to: formobalaji

NEED TO SAVE THE BLOCKS IN DXF V2010

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report