Renumber Rebar Numbers with Dynamo

@Lawrence_Hooker I read this post on your blog, and the comment below:

Can the routine be extended to get the Rebar Numbers back in sync again, i.e overwrite the rebar numbers with the stored list of schedule marks?

I liked your idea with the schedule marks, and also the idea from the comments of being able to sync the values back to Rebar Numbers. I had a look in the docs and found a metod called ChangeNumber, and it looks like it works:

Rebar.SyncRebarNumbers.dyn (14.0 KB)

##The python script:

import clr 
 
clr.AddReference('RevitAPI') 
from Autodesk.Revit.DB import * 
from Autodesk.Revit.DB.Structure import * 
 
clr.AddReference('System') 
from System.Collections.Generic import List 
 
clr.AddReference('RevitNodes') 
import Revit 
clr.ImportExtensions(Revit.GeometryConversion) 
clr.ImportExtensions(Revit.Elements) 
 
clr.AddReference('RevitServices') 
import RevitServices 
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 
 
doc = DocumentManager.Instance.CurrentDBDocument 
 
#Preparing input from dynamo to revit 
sortedRebars = UnwrapElement(IN[0])
name = IN[1]
newStartNum = IN[2]
 
#Do some action in a Transaction 
TransactionManager.Instance.EnsureInTransaction(doc) 
schema = NumberingSchema.GetNumberingSchema(doc,NumberingSchemaTypes.StructuralNumberingSchemas.Rebar)
schema.RemoveGaps(name)

range = schema.GetNumbers(name)
range = range[0]
rangeSpan = 1 + (range.High - range.Low)
startNumber = rangeSpan+1000
schema.ShiftNumbers(name, startNumber)

for e in sortedRebars:
	num = int(e.get_Parameter(BuiltInParameter.REBAR_NUMBER).AsString())
	schema.ChangeNumber(name, num, newStartNum)
	newStartNum = newStartNum + 1
schema.RemoveGaps(name)
TransactionManager.Instance.TransactionTaskDone() 
 
OUT = 0
2 Likes

That looks very promising. Definitely will take a further look at this. Thanks for the share!

I have created a new and a bit more robust version. It is made for a workflow where the Schedule Mark is a combination of the partition name and the rebar number.

Example:

Rebar.SyncRebarNumberWithScheduleMark.dyn (33.3 KB)

Python Script:

#http://www.revitapidocs.com/2017/1042810e-72a4-1ab1-22f3-925f2f05e20a.htm
import clr

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

clr.AddReference('System')
from System.Collections.Generic import List

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

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

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
partition = IN[0]
fromNumbers = IN[1]
toNumbers = IN[2]
firstNumber = IN[3]

schema = NumberingSchema.GetNumberingSchema(doc,NumberingSchemaTypes.StructuralNumberingSchemas.Rebar)

range = schema.GetNumbers(partition)
delta = firstNumber - range[0].Low

TransactionManager.Instance.EnsureInTransaction(doc)
schema.ShiftNumbers(partition,firstNumber)
TransactionManager.Instance.TransactionTaskDone()

TransactionManager.Instance.EnsureInTransaction(doc)
OUT = []
for fromNumber,toNumber in zip(fromNumbers,toNumbers):
	eIds = schema.ChangeNumber(partition, fromNumber+delta, toNumber)
	OUT.append([doc.GetElement(eId) for eId in eIds])
TransactionManager.Instance.TransactionTaskDone()
3 Likes

Hi @Einar_Raknes this seems to be very helpful but I tried it it is not working.
what i need to do is just change the schedule mark to be in order right?

@ali.safiaddine difficult to tell why it’s not working for you. Maybe you can paste a screenshot of the graph with all previews open?

I Just tried it again and it is working properly, but please can you tell me what is the python script doing? I didn’t know exactly how the rebar number is changing

The script works in two steps.

  1. Add a delta value to the existing numbers, because they can not be overwritten.
  2. Change the old number+delta to new number

@Einar_Raknes Thank youu

Rebar%20Parameter%20Error

Hi, Just tried your workflow and getting the following error. Am I setting up correctly HHHHHHHHHHHHHHelp

thanks in advance

kevin