Freeze Drawings from Revit

Hello,

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 : https://www.youtube.com/watch?v=oLBTsZC0Ajk

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
Else: 
   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
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference("RevitServices")
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'
sys.path.append(pyt_path)


# 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:
	vFamTypeIds.append(UnwrapElement(famType).Id)
	
TransactionManager.Instance.EnsureInTransaction(doc)
for index, view in enumerate(IN[0]):
	currView = UnwrapElement(view)
	#vSet = ViewSet()
	sheet = UnwrapElement(IN[1][index])
	sheets.append(sheet)
	#vSet.Insert(currView)
	vPort = Viewport.Create(doc, sheet.Id, currView.Id, XYZ(0, 0 ,0))
	viewports.append(vPort)
	iList = List[ElementId](sheet.Id.IntegerValue)
	iList.Add(sheet.Id)
	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
			break
		except:
			if index == length -1:
				OUT.append("ViewFamilyType Error")
			else :
				pass
	doc.Link(str(directory) + "\\" + str(sheetName) + ".dwg", importOptions, vDraft)
TransactionManager.Instance.TransactionTaskDone()

# Affectez la sortie à la variable OUT.

OUT.append(viewports)

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