Batch insert CAD in families

Hi everyone.
For an exercise I would solve this quest that’s driving me mad:
I have a certain number of CAD files. From these files I need to create copies of families with the same name (and this wasn’t difficult at all) and then batch open them and insert (using the method in the image below) matching name CAD files, explode them, save close.
I’m missing how to import CAD files in families and explode them, I can’t really find a way out.

If you know how to solve this please help!!

Thx in advance

I

Hi @e.cietto is it something here you are after ?

Hi @sovitek , That was the first way I tried through Genius Loci and Bimorph but still give me error.
I attatch here one of those files, maybe the problem is the dwg itself, but I cannot really undeerstad why. It contains just a block with file’s name; the block then is a Solid 3D.

Thx for helping

23601SLTA80010020.dwg (157.9 KB)

alright…something here ?

Wow it works for you!!!
I guess I have a problem with the Import DWG.dyf

Or with the Python code in it??

#Based on a Konrad Sobon script
#Additions by Alban de Chasteigner 2018
#Suggestion of Ryan Lenihan

import clr

Import DocumentManager and TransactionManager

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import RevitAPI

clr.AddReference(‘RevitAPI’)
import Autodesk
from Autodesk.Revit.DB import *

inputdoc = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]
filePaths = IN[1] if isinstance(IN[01],list) else [IN[1]]
views = UnwrapElement(IN[2]) if isinstance(IN[2],list) else [UnwrapElement(IN[2])]
customscale = IN[3]
colormode = IN[4]
placement = IN[5]
unit = IN[6]
allView = IN[7]
order = IN[8]

if inputdoc[0] == None :
doc = DocumentManager.Instance.CurrentDBDocument
else : doc = inputdoc[0]
viewsplaced,outName,CADlinktype,importinstance = ,,,

options = DWGImportOptions()
options.AutoCorrectAlmostVHLines = True
options.OrientToView = True
if allView :options.ThisViewOnly = False
else: options.ThisViewOnly = True
options.VisibleLayersOnly = True
options.CustomScale = customscale
if colormode == None: ImportColorMode.Preserved
else: options.ColorMode = colormode
if placement == None: ImportPlacement.Shared
else :options.Placement= placement
if unit == None : ImportUnit.Default
else : options.Unit = unit

Create ElementId / .NET object

linkedElem = clr.ReferenceElementId

TransactionManager.Instance.ForceCloseTransaction()
TransactionManager.Instance.EnsureInTransaction(doc)
for view in range(len(views)):
doc.Import(filePaths[view], options, views[view], linkedElem)
viewsplaced.append(views[view])
importinst = doc.GetElement(linkedElem.Value)
importinstance.append(importinst)
CADLink = doc.GetElement(importinst.GetTypeId())
CADlinktype.append(CADLink)
outName.append(Element.Name.GetValue(CADLink))
if not allView :
importinst.get_Parameter(BuiltInParameter.IMPORT_BACKGROUND).Set(order)
TransactionManager.Instance.TransactionTaskDone()

if isinstance(IN[0], list): OUT = viewsplaced,outName,CADlinktype,importinstance
else: OUT = viewsplaced[0],outName[0],CADlinktype[0],importinstance[0]

I would also ask from what package tha last node comes from??

Thx againg, you’re my saviour

do you have dynamoironpython 2.7 ver. 2.5 installed ?

PS sometimes i need a restart in both revit and dynamo…after many runs…can probably help

Btw which revit version are you in ?

I have the 2.7 installed in Revit 2023.1.
I don’t really know what’s happening, uff.

1 Like

hmm have you try restart all ? and your iron python 2.7 is version 2.5 ?

@sovitek Version is 3.2.1, the latest.
By the way seems to work but I still don’t know from which package you picked the “k-import family” you used, could you please share this last thing please?

Thx

That build is for Revit 2025; you need to go back to version 2.5 for 2023/2024 if memory serves.

Here is a direct download link: https://dynamopackages.com/download/6967bd4a-b61e-4dfe-85e0-761dc24b03ed/2.5.0

Save that as a zip, unblock it, close Revit, and copy that folder into your Dynamo packages folder.

2 Likes

yeah it was synthezise toolkit…probably better with a freeform in a family document…then try spring geometry freeform…depends…

Thank you very much, you made my day

1 Like

Thx a lot @jacob.small

2 Likes