Dismiss a Revit dialog (when Exporting nwc)

Hi All,

I was trying dismissing a Revit dialog below.

image

This is my code:

import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference("RevitAPIUI")
from  Autodesk.Revit.UI import *

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


def Module_Startup(sender, event):
	uiapp.DialogBoxShowing += EventHandler[DialogBoxShowingEventArgs](dismiss)

def dismiss (sender, event):
	t =  TaskDialogShowingEventArgs
	if t != null:
		DialogBoxShowingEventArgs.OverrideResult(TaskDialogResult.No)


views = UnwrapElement(IN[0])
path = IN[1]
#name = IN[2]

def RemoveFirstChar(text):
	return text[1:]

OUT = []
if IN[2]:
	for i in views:
		OUT.append(i)
		Options = Autodesk.Revit.DB.NavisworksExportOptions()
		Options.ConvertElementProperties=True
		Options.ExportScope = NavisworksExportScope.View
		Options.DivideFileIntoLevels =False
		Options.Coordinates=NavisworksCoordinates.Internal
		Options.ViewId = i.Id
		Options.ExportLinks = True
		Options.ExportRoomAsAttribute=False
		Options.ExportRoomGeometry=False
		Options.ExportUrls=False
		doc.Export(path, RemoveFirstChar(i.Name), Options)
		Module_Startup()
		
	TransactionManager.Instance.EnsureInTransaction(doc)
	doc.Regenerate()
	TransactionManager.Instance.TransactionTaskDone()

But I get an error, just calling

Module_Startup()

image

You’ve defined Module_Startup() with two parameters:

def Module_Startup(sender, event):
	uiapp.DialogBoxShowing += EventHandler[DialogBoxShowingEventArgs](dismiss)

but then you’re calling it with no parameters:

Module_Startup()

probably you just meant to define Module_Startup() with no parameters…

1 Like

Actually now that I look at it I see a few more issues…

Here is an attempt at fixing your code (I haven’t tested the dialog handler because I don’t know how to trigger that one)

import clr
import System
from System import EventHandler

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import *

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

def dismiss (sender, eventArgs):
	if isinstance(eventArgs, TaskDialogShowingEventArgs):
		eventArgs.OverrideResult(TaskDialogResult.No)
	return

views = UnwrapElement(IN[0])
path = IN[1]
#name = IN[2]

def RemoveFirstChar(text):
	return text[1:]

OUT = []
if IN[2]:
	for i in views:
		OUT.append(i)
		Options = Autodesk.Revit.DB.NavisworksExportOptions()
		Options.ConvertElementProperties=True
		Options.ExportScope = NavisworksExportScope.View
		Options.DivideFileIntoLevels =False
		Options.Coordinates=NavisworksCoordinates.Internal
		Options.ViewId = i.Id
		Options.ExportLinks = True
		Options.ExportRoomAsAttribute=False
		Options.ExportRoomGeometry=False
		Options.ExportUrls=False
		dialogEventHandler = EventHandler[DialogBoxShowingEventArgs](dismiss)
		
		uiapp.DialogBoxShowing += dialogEventHandler
		
		doc.Export(path, RemoveFirstChar(i.Name), Options)
		
		uiapp.DialogBoxShowing -= dialogEventHandler
		
	TransactionManager.Instance.EnsureInTransaction(doc)
	doc.Regenerate()
	TransactionManager.Instance.TransactionTaskDone()
6 Likes

@ElCapitanDan Thanks a lot!