Is there any way to batch create families by cad block with dynamo?

Hi, I have too many CAD blocks need to make as revit families! Is there any way to batch create families by cad block with dynamo? Thank you very much first !
Usually, I need to create a new family file, then import the cad block, then explode the imported CAD block, and finally save it as a completed family file.
Now I want to know how to use Dynamo to complete batch family file creation.
This’re CAD files of furniture(Change ‘dwg’ format to ‘zip’ please).dwg (2.0 MB)


I’m sure there are other ways to do this, but I used this approach when I had to convert 100s of .objs to .rfas. This should work with dwgs as well.

@echo off
SETLOCAL EnableDelayedExpansion

SET FILEEXT=DWG
SET TEMPLATEFILENAME=template

for /R "%~dp0" %%f in (*.%FILEEXT%) do (
    echo processing: %%f
        
    copy "%~dp0\%TEMPLATEFILENAME%.rfa" "%~dp0%%~nf.rfa"
    echo "%~dp0%%~nf.rfa">> "%~dp0filelist.txt"
)

Maybe you can also do this in dynamo, I like to do file manipulations in batch or bash, they are quicker.

This workflow doesn’t create true revit geometry from the imported dwgs, they will be only imports. You just have to figure out what you really want, add it to the script, and cycle through the script with BatchProcessor.

7 Likes

Thank you for helping me!!!
I try it first

Apologies for bringing this post back to life. I am using your process above and came across an issue. The imported 3D CAD only shows up on the ref. level. I understand you have to specify a view in the Import DWG node, so I’m wondering if there’s a way to have the import show up on all views?

Hello, and welcome to the forum!

This is a limitation in the GeniusLoci Import Dwg node. You can change this behavior manually: open the node and edit the python code manually. Change line 29 from True to False:

options.ThisViewOnly = False

This line: GeniusLociForDynamo/Import DWG.dyf at 63c11774ebb281ae5e0ed073e7c64ec5e45eb03d · albandechasteigner/GeniusLociForDynamo · GitHub

Now imported dwgs will become 3D elements.

1 Like

Hi Nick,

You will find the updated Import Dwg node in the Genius Loci package version 2021.6.3.
import DWG

2 Likes

Thanks Alban, it has worked for me! Cheers!

Does any one care to share their .dyn to reverse engineer? Help out a Dynamo novice learn some more? =)

Beautiful AutoLISP code from there:

(arxload "DOSLib24x64.arx" nil)) ;; uses DOSLib
(defun c:wblockm  ()
  (setq cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)			;
  (if (not dos_getdir)
    (setq path (getstring "\nDS> Target Folder: " T))
    (setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX"))))
  (if (/= path nil)
    (progn (if (= (substr path (strlen path) 1) "\\")
	     (setq path (substr path 1 (1- (strlen path)))))
	   (princ "\nDS> Building List of Blocks ... ")
	   (setq lst nil)
	   (setq itm (tblnext "BLOCK" T))
	   (while (/= itm nil)
	     (setq nam (cdr (assoc 2 itm)))
	     (setq pass T)
	     (if (/= (cdr (assoc 1 itm)) nil)
	       (setq pass nil)
	       (progn (setq ctr 1)
		      (repeat (strlen nam)
			(setq chk (substr nam ctr 1))
			(if (or (= chk "*") (= chk "|"))
			  (setq pass nil))
			(setq ctr (1+ ctr)))))
	     (if (= pass T)
	       (setq lst (cons nam lst)))
	     (setq itm (tblnext "BLOCK")))
	   (setq lst (acad_strlsort lst))
	   (princ "Done.")		;
	   (foreach blk	 lst
	     (setq fn (strcat path (chr 92) blk))
	     (if (findfile (strcat fn ".dwg"))
	       (command "_.WBLOCK" fn "_Y" blk)
	       (command "_.WBLOCK" fn blk))))) ;
  (setvar "CMDECHO" cmdecho)
  (princ))

How the .BAT works:

Here is an attempt to import DWGs into 3 Views for a 3D-ish Family:


Needs more work to make it batch.