Freeze Drawings from Revit


I’m trying to recreate the process explained here by @Gabriel_Nones-Newman Few years ago on LinkedIn but I have a little trouble with the Python part off the script.

I have this error image that seems obviously right : there is a for loop for an input with a single element, but it seems to be the way that the original script is done, so maybe I lost myself somewhere …

The objective of the script, that could be deploy for a firm : “convert” a 3D View to a 2D detail View to have a fast tool to add annotations (the original Add-in for Revit has been discontinuous like this :

Here is the script and screenshots

Home 2.dyn (82.4 KB)

1 Like

If you get that error you can simply turn the input into a list by wrapping it in [ ]. If you want to do it in a nice way so you don’t accidentally wrap a list into a list then use the following code.

If isinstance(input,list):
   X = input
   X = [input]

This checks if input is of type list. If not, then you make it into a list.

Thank you Daniel, can you tell me where to add this lines and if I have to “customize” them replacing words in it ?

I added a List.Create Node at Input [4] for the moment so it works but I have to continue to debug the script

# Activer la prise en charge de Python et charger la bibliothèque DesignScript
import clr
from Autodesk.DesignScript.Geometry import *

import Autodesk
from Autodesk.Revit.DB import *

import RevitServices
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

from System.Collections.Generic import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'

# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
dataEnteringNode = IN

viewports = []
sheets = []
directory = IN[2]
exportOptions = DWGExportOptions()
importOptions = DWGImportOptions()
vFamTypeIds = []
famTypes = IN[4]
OUT = []

# Placer votre code au-dessous de cette ligne

for famType in famTypes:
for index, view in enumerate(IN[0]):
	currView = UnwrapElement(view)
	#vSet = ViewSet()
	sheet = UnwrapElement(IN[1][index])
	vPort = Viewport.Create(doc, sheet.Id, currView.Id, XYZ(0, 0 ,0))
	iList = List[ElementId](sheet.Id.IntegerValue)
	sheetName = IN[3][index]
	doc.Export(directory,sheetName, iList, exportOptions)
	length = len(vFamTypeIds)
	for index, id in enumerate(vFamTypeIds):
		try :
			vDraft = ViewDrafting.Create(doc, id)
			vDraft.Name = sheetName
			if index == length -1:
				OUT.append("ViewFamilyType Error")
			else :
	doc.Link(str(directory) + "\\" + str(sheetName) + ".dwg", importOptions, vDraft)

# Affectez la sortie à la variable OUT.


It’s getting worse …

For the code in my previous message, input can be any variable you want to check for being a list (for example IN[0]) and you can replace x by any variable you want to store the variable to that you’re checking (wrapped in to a list or not depending on the type of input you’re giving it)

You can then also use the code at the top of your script where you store your IN variables to something more understandable

Is it possible that the views you’re trying to add to a sheet are already on that sheet? If so, that might explain why you can’t add the view to your sheet since it’s already there (something Revit just doesn’t allow).