Donate Now Goal amount for this year: 2500 USD, Received: 1627 USD (65%)

Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12
Like Tree18Likes

Thread: RevitAPI Docs to Python

  1. #11
    Member ScubaMan's Avatar
    Join Date
    July 6, 2015
    Current Local Time
    03:41 PM
    Super happy they record the presentations. Cannot wait to watch it. Thanks Sol
    amoursol and johnp like this.

  2. #12
    Senior Member amoursol's Avatar
    Join Date
    November 21, 2012
    London, United Kingdom
    Current Local Time
    11:41 PM
    ModNote from cellophane: Copied from this thread:

    Hello all,

    The primary difference between Python (standard) and Dynamo's implementation is that Dynamo uses IronPython - and an older version at that. A lot of functionality from Python is ported through - but the primary focus of IronPython is to allow for the .NET framework to be imported into the Dynamo environment.

    In terms of portability, there are a few Dynamo centric parts you need to implement. Predominantly these are surrounding imports.

    RevitPythonShell version (Note needs to be indented properly to work):

    from Autodesk.Revit.DB import Transaction, Element
    from Autodesk.Revit.DB import FilteredElementCollector
    from Autodesk.Revit.DB import ViewFamilyType, ViewDrafting, Element
    from Autodesk.Revit.DB import ViewFamily
    uidoc = __revit__.ActiveUIDocument
    doc = uidoc.Document
    t = Transaction(doc, 'Create Drafting View')
    def get_drafting_type_id():
        viewfamily_types = FilteredElementCollector(doc).OfClass(ViewFamilyTy pe)
        for i in viewfamily_types:
            if i.ViewFamily == ViewFamily.Drafting:
                return i.Id
    drafting_type_id = get_drafting_type_id()
    drafting_view = ViewDrafting.Create(doc, drafting_type_id)
    Dynamo Version:

    import clr
    from Autodesk.Revit.DB import *
    from RevitServices.Persistence import DocumentManager
    from RevitServices.Transactions import TransactionManager
    doc = DocumentManager.Instance.CurrentDBDocument
    def get_drafting_type_id():
        viewfamily_types = FilteredElementCollector(doc).OfClass(ViewFamilyType)
        for i in viewfamily_types:
            if i.ViewFamily == ViewFamily.Drafting:
                return i.Id
    if IN[0]:
        forceClose = TransactionManager.Instance.ForceCloseTransaction()
        t = Transaction(doc, 'Create Drafting View')
        drafting_type_id = get_drafting_type_id()
        drafting_view = ViewDrafting.Create(doc, drafting_type_id)
    OUT = drafting_view
    The variances are as follows:

    1. Importing. You'll have to append paths to the CLR (Common Language Runtime) module. This is an IronPython thing. Any module not hard-coded with a path inside of the Dynamo Python IDE (i.e ProtoGeometry) will need to be appended here. If you are using normal Python modules inside of Dynamo, you'll need to append the system path too**.
    2. The way we pull the Document and Transactions is typically different. It's via the RevitServices manager. You can pull the other way as stipulated in your original code - but typically it's done as I have in my redux of the code.
    3. Dynamo interacts with Transactions differently than RevitPythonShell. So you'll have to run a 'ForceCloseTransaction' call before creating a new one if you wish to take this path (Named transactions). The reason for this is that Revit can get stuck inside a Transaction and Dynamo won't execute. Otherwise, you simply call 'DocumentManager.Instance.EnsureInTransaction(doc)' at the start and 'DocumentManager.Transaction.TransactionTaskDone()' at the end - this is the safer path hence most Python code inside of Dynamo using it.
    4. You'll need to put a boolean check in this kind of script - or you'll run into Recursion issues. So I've put a simple switch in - toggle true and it will create, toggle false and it won't. Every time you 'touch' the Python code, it will re-execute. This is either by changing the code inside, or flicking the boolean, or toggling input port amount.
    5. You'll also need an OUT port - of which you can push anything out.

    I hope this helps!

    ** If you wish to append the System path, you do so as follows:

    import sys
    sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
    import csv
    import math
    Last edited by cellophane; April 30th, 2018 at 01:49 PM.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. BIM 360 Glue/Field/Docs
    By Empirical objections in forum Forum Suggestions and Feedback
    Replies: 2
    Last Post: April 13th, 2016, 09:58 PM
  2. David Light: BIM360 Docs
    By David Light Blog in forum Blog Feeds
    Replies: 0
    Last Post: February 6th, 2016, 12:15 PM
  3. Replies: 0
    Last Post: December 1st, 2015, 09:45 PM
  4. Schedules and Excel Docs
    By Lox in forum Architecture and General Revit Questions
    Replies: 6
    Last Post: March 20th, 2014, 12:13 AM
  5. David Light: BIM Docs!
    By David Light Blog in forum Blog Feeds
    Replies: 0
    Last Post: April 25th, 2013, 08:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts