Where is the correct API comment?

Hello,

I still learn API stuff. I found a fine script which duplicates types, but there are a lot of Duplicate-Methods(views, material,…). I use it for dublicate type for Generic_Models
Which one is here used? (Revit 2018.3.3):

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

result = []
insymbol = UnwrapElement(IN[0])
symbolnames =IN[1]

for s in symbolnames:
    TransactionManager.Instance.EnsureInTransaction(doc)
    newsymbol = insymbol.Duplicate(s)
    result.Add(newsymbol.ToDSType(True))
    TransactionManager.Instance.TransactionTaskDone()


OUT = result

I’m not sure why this has the transaction in the for loop… feels like it’s asking for things to go slower, but it may be a requirement for making new symbols I guess… anyway…

https://www.revitapidocs.com/2020/b0e7d5d5-f33a-8ff2-b471-78a213f06ef5.htm

1 Like

it works also this way:

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
TransactionManager.Instance.EnsureInTransaction(doc)

result = []
insymbol = UnwrapElement(IN[0])
symbolnames =IN[1]

for s in symbolnames:
    newsymbol = insymbol.Duplicate(s)
    result.Add(newsymbol.ToDSType(True))

TransactionManager.Instance.TransactionTaskDone()	

OUT = result

Perhaps try using some list comprehension to simplify further?

Haven’t tested myself but this should be a good start point.

doc = DocumentManager.Instance.CurrentDBDocument

insymbol = UnwrapElement(IN[0])
symbolnames =IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)
result = [ insymbol.Duplicate(s) for s in symbolnames ]
TransactionManager.Instance.TransactionTaskDone()	

OUT = [ r.ToDSType(True) for r in result ]
2 Likes

2021-02-06_17h53_33
well! Thank you
so you are not using Add just the for loop

Few notes:

  1. Comment our each line and describe in plain English (or your native language) what it does. This will ensure you know what each line is doing, ensuring you have the knowledge to continue to grow and will help troubleshooting later.

  2. Do not get in the habit of using python nodes unbound in your graph like the above for repeated, long term use. Each of that code set will need to be addressed on a 1x1 basis in every copy of every graph you have when the inevitable Python 3 conversion comes. Wrap it in a custom node and use a package you deploy to ensure the whole office gets the updates as needed.

  3. Do not forget to simplify your environmental set up as well. Things like ‘import *’ and ‘UIDoc’ when not needed is just sloppy. Simplified imports is a best practice - otherwise you are borrowing the entire bookcase when you really just need ‘FamilySymbol’.

1 Like