Goodday
Im having trouble with applying a loop to my python script.
What im trying to accomplish is to fill in 2 (Instance) parameters of a family placed in a family, and after it fills in the parameters it needs to save the family and continue with the next value’s in the list.
This process needs to be repeated the amount of time it gets input from my excel sheet, in this example there are only 2 options (Those options are defined in a code block not through excel).
Placing a single tube and filling in the parameters and saving it works (Script: Single Version - Working)
But once i add the loop to the script it start to give me the error as you can see in the screenshot.
Containing:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
doc = DocumentManager.Instance.CurrentDBDocument
name = IN[0]
compact = IN[1]
newcentral = IN[2]
isworkshared = IN[3]
elmts = IN[4]
parmNam = IN[5]
val = IN[6]
for i in range(len(name)):
Revit.Elements.Element.SetParameterByName(elmts[i], parmNam[0], val[i][0])
Revit.Elements.Element.SetParameterByName(elmts[i], parmNam[1], val[i][1])
TransactionManager.Instance.ForceCloseTransaction()
if doc.IsFamilyDocument:
name += '.rfa'
else:
name += '.rvt'
opt = SaveAsOptions()
opt.OverwriteExistingFile = True
opt.Compact = compact
if isworkshared and newcentral:
wsopt = WorksharingSaveAsOptions()
wsopt.ClearTransmitted = True
wsopt.SaveAsCentral = True
opt.SetWorksharingOptions(wsopt)
try:
doc.SaveAs(name, opt)
OUT = 'done'
except:
try:
wsopt.ClearTransmitted = False
opt.SetWorksharingOptions(wsopt)
doc.SaveAs(name, opt)
OUT = 'not done'
except:
OUT = 'not done'
i cant find the reason why i get an index error…
Can anyone help me applying the loop to the script?
Thanks already!
Tom B
Working version of the script: (Can’t upload my .py because im a new member sorry!)
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
doc = DocumentManager.Instance.CurrentDBDocument
name = IN[0]
compact = IN[1]
newcentral = IN[2]
isworkshared = IN[3]
elmts1 = IN[4]
parmNam1 = IN[5]
val1 = IN[6]
Revit.Elements.Element.SetParameterByName(elmts1[0], parmNam1[0], val1[0])
Revit.Elements.Element.SetParameterByName(elmts1[0], parmNam1[1], val1[1])
TransactionManager.Instance.ForceCloseTransaction()
if doc.IsFamilyDocument:
name += '.rfa'
else:
name += '.rvt'
opt = SaveAsOptions()
opt.OverwriteExistingFile = True
opt.Compact = compact
if isworkshared and newcentral:
wsopt = WorksharingSaveAsOptions()
wsopt.ClearTransmitted = True
wsopt.SaveAsCentral = True
opt.SetWorksharingOptions(wsopt)
try:
doc.SaveAs(name, opt)
OUT = 'done'
except:
try:
wsopt.ClearTransmitted = False
opt.SetWorksharingOptions(wsopt)
doc.SaveAs(name, opt)
OUT = 'not done'
except:
OUT = 'not done'
Dynamo Core: 2.1.0.7500
Dynamo Revit:2.1.0.7733