Python script to trigger "Itemized" all Schedules

Hi all,

I do not want to take the schedules one by one, but take all my schedules in once in my Python script.
can someone help me please with the script.

Preformatted text

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *

#Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

refschedule = UnwrapElement(IN[0])
gg = UnwrapElement(IN[1])

refdefinition = refschedule.Definition
lol = refdefinition

TransactionManager.Instance.EnsureInTransaction(doc)

refdefinition.IsItemized = gg

TransactionManager.Instance.TransactionTaskDone()

OUT = refdefinition

Preformatted text

Thank you in advance.

Regards

Kangal

The best solution would probably be to nest the python in a custom node :slight_smile:

Hi Jonathan,

You already know how my company thinks about Custom Node :sweat_smile:
In January I have an appointment to tell how important Custom nodes are.

I need help until then. Can you help me please :smiling_face_with_three_hearts:

Regards

Kangal

I’m not at a computer till tomorrow, but try to look into ‘‘for loops’’ in python and give it a shot :slight_smile: it is not as scary as it seems :slight_smile:

Hi,

I am now behind the PC and try different things in Python. :crossed_fingers:
in January I will also receive a course on Pyton with revitAPI

Hope to see your reaction tomorrow. :hugs:

Regards

Kangal

Hi @Kangal @Jonathan.Olesen

How about creating a script with any list structure :sunglasses:

import clr

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

ProcessLists = lambda function, lists: [ProcessLists(function, item) if isinstance(item, list) else function(item) for item in lists]
ApplyFunction = lambda func, objs: ProcessLists(func, objs) if isinstance(objs, list) else [func(objs)]

def Unwrap(item):
    return UnwrapElement(item)
    
if isinstance(IN[0], list):
	schedule = ProcessLists(Unwrap, IN[0])
else:
	schedule = Unwrap(IN[0])

itemize = IN[1]
	
def task(schedule):
	definition = schedule.Definition
	result = definition
	TransactionManager.Instance.EnsureInTransaction(doc)
	result.IsItemized = itemize
	TransactionManager.Instance.TransactionTaskDone()
	return result

OUT = ApplyFunction(task,schedule)
9 Likes

For those who do not know, what is the concern?

Hi Jacob,

My company does not want to use a custom node.

it can be shared between different branches without having to download the package.
I’m talking with IT-department how we can arrange / download parts in advance without bothering the users.

The goal is that de users use the script in DynamoPayer, without downloading anythng.

Regards

Kangal

Hi Kulkul,

This is awesome, it works fine!
Thank you :hugs:

1 Like

As a novice in python this was really cool to see. The lambda function and its recursion is all new to me. Thanks for sharing!

1 Like

Sharing is caring :wink:

2 Likes