Python Output Types

Hello All,
I’m using a python node to set text note widths.
The python script works perfectly but i’d like to learn how to also output the original widths.
This has no real benefit in terms of workflow purpose, just simply something i’d like to understand for the future.

This is the workflow:

This is the python script:

import clr

# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk

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

doc = DocumentManager.Instance.CurrentDBDocument

ReqNoteWidth = IN[1]

if isinstance(IN[0], list):
    txts = UnwrapElement(IN[0])
else:
    txts = [UnwrapElement(IN[0])]

# Place your code below this line
output = []
for txt in txts:
    TransactionManager.Instance.EnsureInTransaction(doc)
    try:
        width = txt.Width
        txt.Width = ReqNoteWidth #change this to whatever width needed
        output.append("Success")
    except:
        output.append("FAIL")
    TransactionManager.Instance.TransactionTaskDone()

# Assign your output to the OUT variable.
OUT = [output, width]

I can see that the following line is included:
output =
which tells me the output will be a list?

OUT is set to [output, width]

The problem i have is that the width only outputs as a single item (likely the first or last item i’d assume).
How would i also ensure the 2nd output is formatted as a list too.

I tried adding width = to format the text widths as a list but this didn’t work :slight_smile:

Thanks in advance,
Jack.

Dynamo File : WF - Set Text Note Widths.dyn (3.6 KB)

I appear to have done it.

Revised part of script:

# Place your code below this line
output = []
oldsize = []
for txt in txts:
    TransactionManager.Instance.EnsureInTransaction(doc)
    try:
        width = txt.Width
        txt.Width = ReqNoteWidth #change this to whatever width needed
        output.append("Success")
        oldsize.append(width)
    except:
        output.append("FAIL")
    TransactionManager.Instance.TransactionTaskDone()
   
# Assign your output to the OUT variable.
OUT = [output, oldsize]

Suppose i will accept this as the solution :smiley:
If anyone has a “Cleaner” way of writing the script then i’m still all ears.

Thanks
Jack.

1 Like