I am back from my vacation. I had a wonderful time.
Now, let's look at two important recurring topics that came up while I was away:
Before getting to those, let me mention some of the nice places and mountain tours I was blessed with in the past few weeks:
- Pallanza and the Lago Maggiore:
- Mont Blanc, mountaneering and climbing around the Cabane d'Orny:
- Monte Leone above Locarno (photo album):
- Pizzo Stella and Pizzo Groppera:
- Les Monnins Dessous and some creative art:
- Levantina and Val Sambuco, hiking, cooking, bivouacing:
Now I am refreshed and happily back at work, so let's continue with the Revit API discussion forum and look at those Revit API issues:
Revit API Context Summary
This kind of question comes up on a regular basis, and is discussed in the topic group on driving Revit from outside; now Daren Thomas provided a beautifully succinct answer that says it all in the StackOverflow discussion on starting a transaction from an external application running outside of API context is not allowed:
Question: Starting a transaction from an external application running outside of API context is not allowed. Cannot start transaction.
Answer: Using my magic psychic crystal ball to guess you are asking how to avoid getting this error message in your Revit / RPS plugins, here is a short bit of extra information:
- all Revit API calls should happen inside the "API context"
- this "API context" lives in a special thread
- you are probably accessing the API from another thread
- this often happens when you make a
Formand call into the API from one of the events, e.g.,
What you want to do is figure out how to get back into the API context to execute your code.
There are two main methods for doing this, assuming you have already left the
- polling for jobs inside the
- using an
Since you mentioned RevitPythonShell in the tags, why don't you check out how I used external events in my web server example.
- create an IExternalEventHandler
- implement its Execute method, which runs in the Revit API context
- create an
ExternalEvent(using the event handler just created)
- when you need to do something in the Revit API context, notify the external event via
As said, The Building Coder provides more details and other samples in the topic group on driving Revit from outside.
Detailed Form Creation Error Information
Question: How can I receive detailed error messages from failed geometry creation calls?
I'm making a call to the doc.FamilyCreate.NewSweptBlendForm method.
However, it throws an exception: Autodesk.Revit.Exceptions.InvalidOperationException.
Unfortunately, the message of the exception is "Cannot create swept blend form."
This does not provide much information, and it's difficult to debug with just this in hand.
Is there any more detailed information that I can access when a call like this fails?
Answer: Unfortunately, the answer is No, not at this moment. The API method makes a direct call to a native method in Revit core which returns an error value, which – again unfortunately – seem to be only either SUCCESS or FAILURE. Additional observation can be made by debugging the concrete case, but for the caller, there is no additional info Revit API can provide. Sorry about that.
The best approach for now might be to create model lines from the input that you are passing into the NewSweptBlendForm method and then execute the sweep in the manual user interface instead. That often provides more detailed info on what is going wrong, as explained in the discussion on debugging geometric form creation.