« UK Electrical Schedule Sample | Main | Happy New Year 2010 »

December 24, 2009

Comments

Dear Jeremy,

I am pretty new to ReviT API and have a following issue: I am batch creating a number ( big number ) of family types - actually instances of different type each, but they are all surfaces, not solids. So after every element is created, Revit displays a warning, which requires answer OK or CANCEL and this kills my idea of batch creating. How to make API answer always OK to such window ? I have already a function which handles this dialog box from Revit, but I can only ignore it using dialogBoxData.OverrideResult(1) function. And this of course prevents the element from being created .... prevents. I am working in Revit VSTA and IDE. My code is
below:
sing System;
using System.Windows.Forms;
using Autodesk;
using Autodesk.Revit;
using Autodesk.Revit.Elements;
using Autodesk.Revit.Structural.Enums;
using Autodesk.Revit.Symbols;
using Autodesk.Revit.Geometry;
using Autodesk.Revit.Events;

namespace V_family_test
{
[System.AddIn.AddIn("ThisApplication", Version = "1.0", Publisher = "", Description = "")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
this.OnDialogBox += new DialogBoxEventHandler(ThisApplication_OnDialogBox);
}

private void Module_Shutdown(object sender, EventArgs e)
{
this.OnDialogBox -= new DialogBoxEventHandler(ThisApplication_OnDialogBox);
}

void ThisApplication_OnDialogBox(DialogBoxData dialogBoxData)
{
dialogBoxData.OverrideResult(3);
}

#region VSTA generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion

public void Create_V_test()
{

String fileName = @"C:\Test_Macro\WesternFins_Module.rfa";
Document document = this.ActiveDocument;

document.BeginTransaction();

Family family = null;
if (!document.LoadFamily(fileName, out family))
{
throw new Exception("Unable to load" + fileName);
}

document.EndTransaction();

FamilySymbolSetIterator symbolItor = family.Symbols.ForwardIterator();
while (symbolItor.MoveNext())
{
FamilySymbol symbol = symbolItor.Current as FamilySymbol;

document.BeginTransaction();
XYZ location = this.Create.NewXYZ(0.0, 0.0, 0.0);
FamilyInstance instance = document.Create.NewFamilyInstance(location, symbol, StructuralType.NonStructural);
document.EndTransaction();
}
}
}
}

Dear Marcin,

Look at the Revit API documentation on the DialogBoxShowingEventArgs.OverrideResult method.

Any non-zero result will close the message box, not just the number 1.

You can return any standard Windows message box ID, such as IDOK and IDCANCEL, and all custom text buttons have custom IDs with incremental values starting at 1001, so they are all non-zero.

Find the ID corresponding to the button you want clicked and use that instead of the number 1.

If nothing else helps, you can also use the technique described in

http://thebuildingcoder.typepad.com/blog/2009/10/dismiss-dialogue-using-windows-api.html

Cheers, Jeremy.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)

Jeremy Tammik

AboutTopicsIndexSource