Revit 2017.1 Python Macro Manager / General API concerns

Revit 2017.1 Python Macro Manager / General API concerns

Anonymous
Not applicable
1,670 Views
4 Replies
Message 1 of 5

Revit 2017.1 Python Macro Manager / General API concerns

Anonymous
Not applicable

A custom python node for Dynamo lost functionality with the 2017.1 Revit update. I found by making a new script that the following statement causes a crash:

 

import clr

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

 

In an effort to debug, I opened the Revit Macro Manager, and found that attempting to run the basic python module crashed the program.

 

Has anyone else come across these issues? Also, if there is a link to the Python specific 2017.1 API I would greatly appreciate it. 

Thanks!

0 Likes
Accepted solutions (1)
1,671 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

Can you confirm that the exact same Dynamo code works fine in the macro manager in Revit 2017?

 

Thank you!



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hello Jeremy,

 

I actually made a very basic mistake, but made one discovery. I didn't realize that Dynamo must be opened from within Revit in order to gain API access. It makes sense, but just a beginner mistake.

 

However, I also found one change to the API, which is documented in the C# / VB Api, and was simple to correct.

 

I will reply with the change tomorrow, upon access to my work computer. I'm wondering if there is a document of api contents for Python. I am fluent in C#, so the conversion should generally be straightforward, but is there a resource for the Python API?

 

Thanks, and I'll have an additional post which will hopefully help someone else with this issue.

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk

Congratulations on that fundamental discovery  🙂

 

The Revit API can only be used within a valid Revit API context, and such a context is only provided within the scope of event handler method called by Revit.

 

A typical example of an event handler (the most typical) is the external command Execute method.

 

The Revit API is purely .NET based.

 

Any programming language supporting .NET can be used, including C# and IronPython, which is what both Dynamo and the built-in Revit SharpDevelop macro IDE are based on.

 

Therefore, the Revit API documentation is completely generic and applies to all programming languages.

 

You can access it from the Revit API developer centre, by downloading the Revit SDK:

 

www.autodesk.com/developrevit

 

I would also suggest working through the generic Revit API getting started material:

 

thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

That will significantly help you understand the architecture of normal Revit add-ins, and also Dynamo, built on top of that.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

As for the API change which caused the error, it was the use of Segment.Curve. The new API uses a function which is Segment.GetCurve()

 

Example wrong code: 

 

 

options = Autodesk.Revit.DB.SpatialElementBoundaryOptions()
boundsegs = room.GetBoundarySegments(options)

for bound in boundsegs:
     for seg in bound:
          crv = seg.Curve

 

Fixed code:

 

for bound in boundsegs:
     for seg in bound:
          crv = seg.GetCurve()

 

I'm sure there are plenty of these sort of instances in old custom Dynamo nodes, and your fix could be something as simple as this. Thanks for the help Jeremy 🙂

0 Likes