Export DWG creashes Revit

584 views
Skip to first unread message

Callum Freeman

unread,
Apr 12, 2015, 6:44:42 PM4/12/15
to revitpyt...@googlegroups.com
Hey everyone, Im having Revit crash when exporting DWG files:



# WARNING: Code could crash Revit session
import clr
import math

from collections import OrderedDict
from System.Collections.Generic import List

clr
.AddReference('RevitAPI')
clr
.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

app
= __revit__.Application
doc
= __revit__.ActiveUIDocument.Document

# path for export file
folder
= doc.PathName[0:doc.PathName.rfind('\\')]+'\\'

# fetch first sheet
sheet
= list(FilteredElementCollector(doc).OfClass(ViewSheet))[0]

# create collection for doc.Export command
sheetWrap
= []
sheetWrap
.Add(sheet.Id)
collection
= List[ElementId](sheetWrap)

dwgOption
= DWGExportOptions.GetPredefinedOptions(doc, BaseExportOptions.GetPredefinedSetupNames(doc)[0])

try:
 doc
.Export(folder, str(sheet.Name), collection, dwgOption)
except Exception as e:
 
print e

# BOOM



- This script exports the DWG file into the specified folder correctly
- This script will export a whole list of sheets correctly
- Have tried code in transaction

... but then it brings Revit crashing down!

- Note the try/except doesnt catch

Any help appreciated, thanks in advance!

Daren Thomas

unread,
Apr 15, 2015, 4:17:22 AM4/15/15
to revitpyt...@googlegroups.com
Hey Callum,

I have just tried this out with the newest build for Revit 2015 and it seems to work. One thing I did change was set

dwgOption = DWGExportOptions()

mainly because the file I was testing with did not have any predefined setup names.

Do you have a sample file I could use? Or more information about what version you were using? Also, a screenshot of the "Revit crashing down"?

Have you tried pasting each line into the interactive shell? does that work?

Best,
Daren

Callum Freeman

unread,
Apr 15, 2015, 4:31:59 PM4/15/15
to revitpyt...@googlegroups.com
Hmmmm it must be something local for me. Ive just reinstalled the latest version and the crash still happens. Ive also tried the code below to print a pdf and I get the same crash (but the pdf still prints)

- There isnt an error message, a screenshot showing Revit crashing would be my blank desktop!
- Im using the latest RPS 2015 install from the website
- Each line works well (and the code works too, I still output a pdf or dwgs).
- Ive cleared startup scripts, no luck
- Ive tried it on a few different files, and on R2014 and R2015. All crash printing and exporting!

Code that crashes printing:


import clr

clr
.AddReference('RevitAPI')
clr
.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
app
= __revit__.Application

ui
= __revit__.ActiveUIDocument
doc
= __revit__.ActiveUIDocument.Document


printManager
= doc.PrintManager

printManager
.SelectNewPrintDriver('PDFCreator')
printManager
.PrintToFileName = 'C:\Addin - PDFs\Why hello there.pdf'

doc
.PrintManager.CombinedFile = True
printManager
.PrintRange = PrintRange.Select
viewSheetSetting
= printManager.ViewSheetSetting

printManager
.SubmitPrint()


Having no error message makes it a tough issue to track down! Is there any way to get better quality crash info? Ive attached the journal file, not sure if this sheds some light...

Any help appreciated, let me know if you need any more info.
journal.0785.txt

Daren Thomas

unread,
Apr 16, 2015, 3:48:11 AM4/16/15
to revitpyt...@googlegroups.com
OK. This really is going to be a tough one - can you try this on another machine? Does it work there?

Also, this line is most likely an error: printManager.PrintToFileName = 'C:\Addin - PDFs\Why hello there.pdf'
(you need to either use `r'C:\Addin - PDFs\why hello there.pdf'` or `'C:\\Addin - PDFs\\Why hello there.pdf')

Can you post a (minimal) Revit document that exposes this behavior?

Can you specify which shell you are using? (modal / non-modal)

Best,
Daren

--
You received this message because you are subscribed to the Google Groups "RevitPythonShell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daren Thomas

unread,
Apr 16, 2015, 3:53:31 AM4/16/15
to revitpyt...@googlegroups.com
update: this is the Revit version Callum is using:


To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshell+unsubscribe@googlegroups.com.

Callum Freeman

unread,
Apr 16, 2015, 7:58:15 AM4/16/15
to revitpyt...@googlegroups.com
Ive tried it on a home tablet-pc thing and it crashes just like at work.

Ive updated the file path string and still no luck. When exporting the file string works fine - the dwg is exports to the correct folder - but Revit crashes straight after. When Im running the export command from a winForm, it waits until I close the form before crashing. hmmm. Both modal and non-modal crash.

I just made the smallest project possible and tried to export something and it crashed - attached .rvt file 

Has anyone else (other than the super-helpful Darren) tried running the export code? any problems?

 

On Monday, April 13, 2015 at 10:44:42 AM UTC+12, Callum Freeman wrote:
Project1.rvt

Callum Freeman

unread,
Apr 19, 2015, 6:32:34 PM4/19/15
to revitpyt...@googlegroups.com
Have now tried it on a colleagues computer too - it still crashes after successfully printing/exporting.

Has anyone used the latest RPS to print/export views or sheets?


On Monday, April 13, 2015 at 10:44:42 AM UTC+12, Callum Freeman wrote:

Daren Thomas

unread,
Apr 20, 2015, 3:52:55 AM4/20/15
to revitpyt...@googlegroups.com


this is the version i'm using. 20140322_1515(x64). it seems a lot older - i'll try and update sometime soon.

2015-04-20 09_49_52-Autodesk Revit Architecture 2015 - Not For Resale Version - [Floor Plan_ Level 1.png

Callum Freeman

unread,
Apr 20, 2015, 6:33:47 PM4/20/15
to revitpyt...@googlegroups.com
Have found a workaround! I think the problem was to do with threading, so I wrapped the export in a function and attached it to the idling event: 

def export (sender, event):
 doc
.Export(folder, str(sheet.Name), collection, dwgOption)
 __revit__
.Idling -= export


__revit__
.Idling += export

Notes: 
- you have to exit the RPS console for the Idling event to fire
- be sure to have the function remove itself otherwise it continuously loops. 

Thanks Darren for your help and ideas


On Monday, April 13, 2015 at 10:44:42 AM UTC+12, Callum Freeman wrote:

Daren Thomas

unread,
Apr 21, 2015, 3:52:36 AM4/21/15
to revitpyt...@googlegroups.com
Note: you can also create an `ExternalEvent` and raise that - then you avoid having to go through the idling event (and removing your function from it afterwards).

Also, RPS tries very hard to stay in the Revit API context *inside the modal shell* - the non-modal shell of course is not in the Revit API context.

I will investigate this further to see why things were not working properly.

Thank you, Callum for posting a workaround for this - I think this might be a solution for other similar problems, should they arrive in future... How about a wrapper method, something like:

    revitutil.force_api_context(export)

to do the idling/ExternalEvent wrapping on-the-fly? I'll think about that too...

Best,
Daren

--
You received this message because you are subscribed to the Google Groups "RevitPythonShell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshe...@googlegroups.com.

Callum Freeman

unread,
Apr 21, 2015, 4:48:34 PM4/21/15
to revitpyt...@googlegroups.com
Hi Darren, is there any documentation on how to create an ExternalEvent? Trying to interpret C++ examples is painful!


On Monday, April 13, 2015 at 10:44:42 AM UTC+12, Callum Freeman wrote:

Daren Thomas

unread,
Apr 22, 2015, 8:27:27 AM4/22/15
to revitpyt...@googlegroups.com
hi callum,

i'm busy writing an article/book chapter on how to create a webserver inside revit. it uses externalevents. look here at what i've already published, you should be able to figure it out from there - otherwise, i'll gladly fill in the missing pieces...


best,
daren

Reply all
Reply to author
Forward
0 new messages