Rebar.SetLayoutAsMaximumSpacing error

Hi Friends,
i am trying to set layout as Maximum spacing for some rebars but i am getting an error in Revit 2020.2

this is my code:

import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import*

from System.Collections.Generic import IList, List

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

# dynamo curves as input
rebar = IN[0]
spacing = IN[1]
array_length = IN[2]

rebars = []

TransactionManager.Instance.EnsureInTransaction(doc)
for i, j, k in zip(rebar, spacing, array_length):       
    rebar = i.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(j, k, true, true, true)
    rebars.append(rebar)
   
TransactionManager.Instance.TransactionTaskDone()

OUT = rebars

this is the error

May anyone tell me how to fix the code to get the right output.
Thanks in advance.

Hi @hanywillim You are on write path but there are few things that u missed and that’s causing this error for u, here i’m pasting the code

rebar = UnwrapElement(IN[0])
spacing = IN[1]
array_length = IN[2]

rebars = []

TransactionManager.Instance.EnsureInTransaction(doc)
for i, j, k in zip(rebar, spacing, array_length):       
    rebar = i.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(j, k, True, True, True)
    rebars.append(i)
   
TransactionManager.Instance.TransactionTaskDone()

OUT = rebars

Here As u could see in comparison with yours to follow your approach i kept it same but at the same time few alterations:-

  1. The UnwrapElment wasn’t used. (For more check this 4.4 Unwrapping Revit Elements - Dynamo Python Primer (gitbook.io) )

  2. true will be written with " T " in Caps.

I hope it helps.

Regards,
BM

1 Like