Python List Output

Hey,

Would anyone mind helping me control my output to match the input lists here?

I can fix it with nodes, but I would like to better control my python code :slight_smile:

(if there was a way of removing the need to list cycle the sheet input, that would also be cool!)

image

thanks Konrad et al!
import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

revisions = UnwrapElement(IN[0])
sheets = UnwrapElement(IN[1])

revs = []
r = []
Output = []

for sheet, revision in zip(sheets, revisions):
    for sht, rev in zip(sheet, revision):
        r = Autodesk.Revit.DB.ViewSheet.GetRevisionNumberOnSheet(sht, rev.Id)        
        Output.append(r)
        

OUT = Output

test.dyn (10.2 KB)

Thanks a lot :slight_smile:

Mark

1 Like

Hello. Can you give a sample revit file too? Or a dummy dynamo file that doesn’t need Revit

Sure, thanks!
test.rvt (1.1 MB)

Something like this?

# Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

revisions = UnwrapElement(IN[0])
sheets = UnwrapElement(IN[1])

revs = []
r = []
Output = []

for sheet, revision in zip(sheets, revisions):
    revnum = []
    for rev in revision:
        r = Autodesk.Revit.DB.ViewSheet.GetRevisionNumberOnSheet(sheet, rev.Id)        
        revnum.append(r)
    Output.append(revnum)
        
OUT = Output
1 Like

You make it look so easy :smiley:

Cheers!

Mark

No problem. If you want to see a really complicated version, here are two others that work, one using an embedded for loop and the other using a lambda function inside an embedded for loop :grinning:

# Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

revisions = UnwrapElement(IN[0])
sheets = UnwrapElement(IN[1])

Output = []

for sheet, revision in zip(sheets, revisions):
    revnum = [Autodesk.Revit.DB.ViewSheet.GetRevisionNumberOnSheet(sheet, rev.Id) for rev in revision]
    Output.append(revnum)

OUT = Output

Lambda:

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

revisions = UnwrapElement(IN[0])
sheets = UnwrapElement(IN[1])

f = lambda sht, revi : [Autodesk.Revit.DB.ViewSheet.GetRevisionNumberOnSheet(sht, rev.Id) for rev in revi]

OUT = [f(sheet, revision) for sheet, revision in zip(sheets, revisions)]

Edit: removed unnecessary imports.

2 Likes

This is great stuff, it’s not really talked about too much in Python training, but it comes up so often for me!

1 Like

Although @jacob.small would say it would be better to not make it iterate in a list, just use the simple Autodesk.Revit.DB.ViewSheet.GetRevisionNumberOnSheet(UnwrapElement(IN[0]), UnwrapElement(IN[1]).Id) in a python node, put it into a custom node where the inputs are regulated to a single item, and let levels and lacing do the work for you.

1 Like

Adding a third option since I just learned about map + lambda :rofl:

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

revisions = UnwrapElement(IN[0])
sheets = UnwrapElement(IN[1])

f = lambda sht, revi : [Autodesk.Revit.DB.ViewSheet.GetRevisionNumberOnSheet(sht, rev.Id) for rev in revi]

OUT = map(f, sheets, revisions)
2 Likes

Just out of courisity
Would it make a difference if Revisions in Revit is set per Sheet / per Project?
Would it make a difference if there where dependant views with the revisions clouds on the Views?
Would it make a difference if Revision Clouds are on the Sheets?

1 Like

I have no clue :joy: I don’t have much if any experience with revisions so I don’t know the behavior. I would have to test it out.

1 Like

Hi Marcel,

Yes it is different if you set the Revisions By Project…

http://www.revitapidocs.com/2018/f46d2d49-1d37-6e99-f450-d21401fd848f.htm

You’ll see the method I’ve used in the Remarks…

I suspect that you can pull other info from Revision clouds, but I always have a Revision ticked in ‘Revisions on Sheet’ incase (when) someone deletes the cloud.

I would never put revisions on views incase (when) they get clipped and/or accidently copied from view to view.

Cheers,

Mark

1 Like

@kennyb6 Lambda’s scare the sh*t out of me :smiley:

1 Like

I was just wondering if the setup of Revisions would affect the Revision Matrix mentioned in this thread.

2 Likes

Hey, yes it would, but from a personal point of view it is a solid workflow.

Other people might have different workflows :smiley:

I think the major problem is the need for a custom parameter everytime you have a new revision. You’d want to add an auto parameter create as part of the graph and I don’t know how Revit would respond to having 2000 shared parameters in the sheet properties. I guess the OP will find out :slight_smile:

Cheers,

Mark

1 Like

I use a Revision Schedule in my TitleBlock, so, no need for extra parameters.
I would fire every teammember that needs 20 revisions to get it right :slight_smile:

This was to create a Drawing Issue Register… So you can pull every issue from every drawing and put it in a single place. This kind of thing…

I would generate an Excel, but the OP wanted it entirely in Revit and as a Parameter… Hence the need for a parameter to match every revision… Then the dynamo populates the parameters correctly.

Over the course of (5 years?) a GA plan might get issued 30 times… I wouldn’t sack someone personally, but I can see how it would focus your employees on early coordination and getting it right! :stuck_out_tongue:

Cheers,

Mark

2 Likes