Scripting tutorial failed, why? are there principles?

Hello,

Doing some exercise

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


OUT = [doc,**uiapp**,app]

I want just get my current document, but for any reason, i can’t get it.

Are there prinziples f.e. Can I say that:

1.) I need a current document
2.) I need tools for transaction
3.) Do something (f.e. with elements… for…loop)
4.) Close the task

doc = DocumentManager.Instance.CurrentDBDocument

elements = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

for e in elements:
    doc.Delete(e.Id)

TransactionManager.Instance.TransactionTaskDone()

OUT = "terminated!"

KR

Andreas

GetCurrentDoc.dyn (3.9 KB)

remove the **

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

OUT = [doc,uiapp,app]

You’re missing a bunch of things as well.

You need to import RevitServices to be able to call on DocumentManager.
You also need it for Transaction manager to be able to start and end a transaction.

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

1 Like

See here for a detailed breakdown of what you’re trying to accomplish

Delete elements article at Danimosite

1 Like