本文整理汇总了C#中Transaction.SetFailureHandlingOptions方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.SetFailureHandlingOptions方法的具体用法?C# Transaction.SetFailureHandlingOptions怎么用?C# Transaction.SetFailureHandlingOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.SetFailureHandlingOptions方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Document doc = commandData.Application
.ActiveUIDocument.Document;
FilteredElementCollector collector
= new FilteredElementCollector( doc );
collector.OfClass( typeof( Level ) );
Level level = collector.FirstElement() as Level;
Transaction t = new Transaction( doc );
t.Start( "Create unbounded room" );
FailureHandlingOptions failOpt
= t.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(
new RoomWarningSwallower() );
t.SetFailureHandlingOptions( failOpt );
doc.Create.NewRoom( level, new UV( 0, 0 ) );
t.Commit();
return Result.Succeeded;
}
示例2: CanCreateAndDeleteAReferencePoint
public void CanCreateAndDeleteAReferencePoint()
{
using (var trans = new Transaction(RevitData.Document.Document, "CreateAndDeleteAreReferencePoint"))
{
trans.Start();
FailureHandlingOptions fails = trans.GetFailureHandlingOptions();
fails.SetClearAfterRollback(true);
trans.SetFailureHandlingOptions(fails);
ReferencePoint rp = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ());
//make a filter for reference points.
ElementClassFilter ef = new ElementClassFilter(typeof(ReferencePoint));
FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
fec.WherePasses(ef);
Assert.AreEqual(1, fec.ToElements().Count());
RevitData.Document.Document.Delete(rp);
trans.Commit();
}
}
示例3: OnIFCExport
/// <summary>
/// Implementation of the command binding event for the IFC export command.
/// </summary>
/// <param name="sender">The event sender (Revit UIApplication).</param>
/// <param name="args">The arguments (command binding).</param>
public void OnIFCExport(object sender, CommandEventArgs args)
{
try
{
// Prepare basic objects
UIApplication uiApp = sender as UIApplication;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
TheDocument = doc;
IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap();
configurationsMap.Add(IFCExportConfiguration.GetInSession());
configurationsMap.AddBuiltInConfigurations();
configurationsMap.AddSavedConfigurations();
String mruSelection = null;
if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration))
mruSelection = m_mruConfiguration;
PotentiallyUpdatedConfigurations = false;
IFCExport mainWindow = new IFCExport(doc, configurationsMap, mruSelection);
mainWindow.ShowDialog();
// If user chose to continue
if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings)
{
// change options
IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration();
// Prepare the export options
IFCExportOptions exportOptions = new IFCExportOptions();
selectedConfig.UpdateOptions(exportOptions, uiDoc.ActiveView.Id);
// prompt for the file name
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.AddExtension = true;
String defaultDirectory = m_mruExportPath != null ? m_mruExportPath : null;
if (defaultDirectory == null)
{
String revitFilePath = doc.PathName;
if (!String.IsNullOrEmpty(revitFilePath))
{
defaultDirectory = Path.GetDirectoryName(revitFilePath);
}
}
if (defaultDirectory == null)
{
defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
String defaultFileName = doc.Title;
if (String.IsNullOrEmpty(defaultFileName))
{
defaultFileName = "Project";
}
else
{
defaultFileName = Path.GetFileNameWithoutExtension(defaultFileName);
}
String defaultExtension = mainWindow.GetFileExtension();
fileDialog.FileName = defaultFileName;
fileDialog.DefaultExt = defaultExtension;
fileDialog.Filter = mainWindow.GetFileFilter();
fileDialog.InitialDirectory = defaultDirectory;
bool? fileDialogResult = fileDialog.ShowDialog();
// If user chose to continue
if (fileDialogResult.HasValue && fileDialogResult.Value)
{
// Prompt the user for the file location and path
String fullName = fileDialog.FileName;
String path = Path.GetDirectoryName(fullName);
String fileName = Path.GetFileName(fullName);
// IFC export requires an open transaction, although no changes should be made
Transaction transaction = new Transaction(doc, "Export IFC");
transaction.Start();
FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(false);
transaction.SetFailureHandlingOptions(failureOptions);
// There is no UI option for this, but these two options can be useful for debugging/investigating
// issues in specific file export. The first one supports export of only one element
//exportOptions.AddOption("SingleElement", "174245");
// The second one supports export only of a list of elements
//exportOptions.AddOption("ElementsForExport", "174245;205427");
// This option should be rarely used, and is only for consistency with old files. As such, it is set by environment variable only.
String use2009GUID = Environment.GetEnvironmentVariable("Assign2009GUIDToBuildingStoriesOnIFCExport");
//.........这里部分代码省略.........
示例4: ExportLinkedDocuments
//.........这里部分代码省略.........
else
{
// check if there are multiple instances with the same name
bool bMultiple = (rvtLinkNamesDict[linkFileName] > 1);
// add the path
linkFileName = fileName + "-" + linkFileName;
// add the guid
if (bMultiple)
{
linkFileName += "-";
linkFileName += linksGUIDsCache[currRvtLinkInstance.Id];
}
}
// add the extension
linkFileName += sExtension;
linkFileNames.Add(linkFileName);
// scale the transform origin
tr.Origin *= lengthScaleFactorLink;
// serialize transform
serTransforms.Add(SerializeTransform(tr));
}
// IFC export requires an open transaction, although no changes should be made
Transaction transaction = new Transaction(documentCopy, "Export IFC Link");
transaction.Start();
FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(false);
transaction.SetFailureHandlingOptions(failureOptions);
// export
try
{
int numLinkInstancesToExport = linkFileNames.Count;
exportOptions.AddOption("NumberOfExportedLinkInstances", numLinkInstancesToExport.ToString());
for (int ii = 0; ii < numLinkInstancesToExport; ii++)
{
string optionName = (ii == 0) ? "ExportLinkInstanceTransform" : "ExportLinkInstanceTransform" + (ii + 1).ToString();
exportOptions.AddOption(optionName, serTransforms[ii]);
// Don't pass in file name for the first link instance.
if (ii == 0)
continue;
optionName = "ExportLinkInstanceFileName" + (ii + 1).ToString();
exportOptions.AddOption(optionName, linkFileNames[ii]);
}
// Pass in the first value; the rest will be in the options.
String path_ = Path.GetDirectoryName(linkFileNames[0]);
String fileName_ = Path.GetFileName(linkFileNames[0]);
bool result = documentCopy.Export(path_, fileName_, exportOptions); // pass in the options here
}
catch
{
}
// rollback the transaction
transaction.RollBack();
示例5: OnIFCExport
//.........这里部分代码省略.........
if (fileDialogResult.HasValue && fileDialogResult.Value)
{
// change options
IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration();
// Prompt the user for the file location and path
String fullName = fileDialog.FileName;
String path = Path.GetDirectoryName(fullName);
String fileName = multipleFiles ? string.Empty : Path.GetFileName(fullName);
// This option should be rarely used, and is only for consistency with old files. As such, it is set by environment variable only.
String use2009GUID = Environment.GetEnvironmentVariable("Assign2009GUIDToBuildingStoriesOnIFCExport");
bool use2009BuildingStoreyGUIDs = (use2009GUID != null && use2009GUID == "1");
string unsuccesfulExports = string.Empty;
// In rare occasions, there may be two projects loaded into Revit with the same name. This isn't supposed to be allowed, but can happen if,
// e.g., a user creates a new project, exports it to IFC, and then calls Open IFC. In this case, if we export both projects, we will overwrite
// one of the exports. Prevent that by keeping track of the exported file names.
ISet<string> exportedFileNames = new HashSet<string>();
foreach (Document document in mainWindow.DocumentsToExport)
{
TheDocument = document;
// Call this before the Export IFC transaction starts, as it has its own transaction.
IFCClassificationMgr.DeleteObsoleteSchemas(document);
Transaction transaction = new Transaction(document, "Export IFC");
transaction.Start();
FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(false);
transaction.SetFailureHandlingOptions(failureOptions);
// Normally the transaction will be rolled back, but there are cases where we do update the document.
// There is no UI option for this, but these two options can be useful for debugging/investigating
// issues in specific file export. The first one supports export of only one element
//exportOptions.AddOption("SingleElement", "174245");
// The second one supports export only of a list of elements
//exportOptions.AddOption("ElementsForExport", "174245;205427");
if (multipleFiles)
{
fileName = GenerateFileNameFromDocument(document, exportedFileNames) + "." + defaultExt;
fullName = path + "\\" + fileName;
}
// Prepare the export options
IFCExportOptions exportOptions = new IFCExportOptions();
ElementId activeViewId = GenerateActiveViewIdFromDocument(document);
selectedConfig.UpdateOptions(exportOptions, activeViewId);
selectedConfig.ActiveViewId = selectedConfig.UseActiveViewGeometry ? activeViewId.IntegerValue : -1;
bool result = document.Export(path, fileName, exportOptions);
Dictionary<ElementId, string> linksGUIDsCache = new Dictionary<ElementId, string>();
if (result)
{
// Cache for links guids
if (selectedConfig.ExportLinkedFiles == true)
{
Autodesk.Revit.DB.FilteredElementCollector collector = new FilteredElementCollector(document);
collector.WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_RvtLinks);
System.Collections.Generic.ICollection<ElementId> rvtLinkInstanceIds = collector.ToElementIds();
示例6: OnIFCExport
/// <summary>
/// Implementation of the command binding event for the IFC export command.
/// </summary>
/// <param name="sender">The event sender (Revit UIApplication).</param>
/// <param name="args">The arguments (command binding).</param>
public void OnIFCExport(object sender, CommandEventArgs args)
{
try
{
// Prepare basic objects
UIApplication uiApp = sender as UIApplication;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
TheDocument = doc;
IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap();
configurationsMap.Add(IFCExportConfiguration.GetInSession());
configurationsMap.AddBuiltInConfigurations();
configurationsMap.AddSavedConfigurations();
String mruSelection = null;
if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration))
mruSelection = m_mruConfiguration;
PotentiallyUpdatedConfigurations = false;
IFCExport mainWindow = new IFCExport(doc, configurationsMap, mruSelection);
mainWindow.ShowDialog();
// If user chose to continue
if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings)
{
// change options
IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration();
// Prepare the export options
IFCExportOptions exportOptions = new IFCExportOptions();
selectedConfig.UpdateOptions(exportOptions, uiDoc.ActiveView.Id);
// prompt for the file name
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.AddExtension = true;
String defaultDirectory = m_mruExportPath != null ? m_mruExportPath : null;
if (defaultDirectory == null)
{
String revitFilePath = doc.PathName;
if (!String.IsNullOrEmpty(revitFilePath))
{
defaultDirectory = Path.GetDirectoryName(revitFilePath);
}
}
if (defaultDirectory == null)
{
defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
String defaultFileName = doc.Title;
if (String.IsNullOrEmpty(defaultFileName))
{
defaultFileName = "Project";
}
else
{
defaultFileName = Path.GetFileNameWithoutExtension(defaultFileName);
}
String defaultExtension = mainWindow.GetFileExtension();
fileDialog.FileName = defaultFileName;
fileDialog.DefaultExt = defaultExtension;
fileDialog.Filter = mainWindow.GetFileFilter();
fileDialog.InitialDirectory = defaultDirectory;
bool? fileDialogResult = fileDialog.ShowDialog();
// If user chose to continue
if (fileDialogResult.HasValue && fileDialogResult.Value)
{
// Prompt the user for the file location and path
String fullName = fileDialog.FileName;
String path = Path.GetDirectoryName(fullName);
String fileName = Path.GetFileName(fullName);
// Call this before the Export IFC transaction starts, as it has its own transaction.
IFCClassificationMgr.DeleteObsoleteSchemas(doc);
// IFC export requires an open transaction, although no changes should be made
Transaction transaction = new Transaction(doc, "Export IFC");
transaction.Start();
FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(false);
transaction.SetFailureHandlingOptions(failureOptions);
// There is no UI option for this, but these two options can be useful for debugging/investigating
// issues in specific file export. The first one supports export of only one element
//exportOptions.AddOption("SingleElement", "174245");
// The second one supports export only of a list of elements
//exportOptions.AddOption("ElementsForExport", "174245;205427");
//.........这里部分代码省略.........
示例7: StartTransaction
/// <summary>
/// Starts a RevitAPI Transaction that will be managed by this TransactionManager instance.
/// </summary>
/// <param name="document">Document (DB) to start a Transaction for. The parameter can not be null.</param>
public TransactionHandle StartTransaction(Document document)
{
if (Transaction == null || Transaction.GetStatus() != TransactionStatus.Started)
{
TransactionManager.Log("Starting Transaction.");
// Dispose the old transaction so that it won't impact the new transaction
if (null != Transaction && Transaction.IsValidObject)
Transaction.Dispose();
Transaction = new Transaction(document, "Dynamo Script");
Transaction.Start();
FailureHandlingOptions failOpt = Transaction.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(handler);
Transaction.SetFailureHandlingOptions(failOpt);
RaiseTransactionStarted();
}
return Handle;
}
示例8: Execute
/// <summary>
/// Execute method invoked by Revit via the
/// external event as a reaction to a call
/// to its Raise method.
/// </summary>
public void Execute(Autodesk.Revit.UI.UIApplication a)
{
// As far as I can tell, the external event
// should work fine even when switching between
// different documents. That, however, remains
// to be tested in more depth (or at all).
//Document doc = a.ActiveUIDocument.Document;
//Debug.Assert( doc.Title.Equals( _doc.Title ),
// "oops ... different documents ... test this" );
UIDocument uidoc = a.ActiveUIDocument;
while (COVER.Instance.messageQueue.Count > 0)
{
COVERMessage m = COVER.Instance.messageQueue.Dequeue();
if ((MessageTypes)m.messageType == MessageTypes.AvatarPosition || (MessageTypes)m.messageType == MessageTypes.SetView || (MessageTypes)m.messageType == MessageTypes.Resend)//read only messages
{
COVER.Instance.handleMessage(m.message, m.messageType, a.ActiveUIDocument.Document, uidoc,a);
}
else
{
Transaction transaction = new Transaction(a.ActiveUIDocument.Document);
FailureHandlingOptions failOpt = transaction.GetFailureHandlingOptions();
failOpt.SetClearAfterRollback(true);
failOpt.SetFailuresPreprocessor(new NoWarningsAndErrors());
transaction.SetFailureHandlingOptions(failOpt);
if (transaction.Start("changeParameters") == TransactionStatus.Started)
{
COVER.Instance.handleMessage(m.message, m.messageType, a.ActiveUIDocument.Document, uidoc,a);
if (TransactionStatus.Committed != transaction.Commit())
{
// Autodesk.Revit.UI.TaskDialog.Show("Failure", "Transaction could not be committed");
//an error occured end resolution was cancled thus this change can't be committed.
// just ignore it and dont bug the user
}
}
}
}
}
示例9: idleUpdate
public void idleUpdate(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
{
e.SetRaiseWithoutDelay();
UIApplication uiapp = sender as UIApplication;
Document doc = uiapp.ActiveUIDocument.Document;
UIDocument uidoc = uiapp.ActiveUIDocument;
while (COVER.Instance.messageQueue.Count > 0)
{
COVERMessage m = COVER.Instance.messageQueue.Dequeue();
if ((MessageTypes)m.messageType == MessageTypes.AvatarPosition || (MessageTypes)m.messageType == MessageTypes.SetView || (MessageTypes)m.messageType == MessageTypes.Resend)//read only messages
{
COVER.Instance.handleMessage(m.message, m.messageType, doc, uidoc,uiapp);
}
else
{
Transaction transaction = new Transaction(doc);
FailureHandlingOptions failOpt = transaction.GetFailureHandlingOptions();
failOpt.SetClearAfterRollback(true);
failOpt.SetFailuresPreprocessor(new NoWarningsAndErrors());
transaction.SetFailureHandlingOptions(failOpt);
if (transaction.Start("changeParameters") == TransactionStatus.Started)
{
COVER.Instance.handleMessage(m.message, m.messageType, doc, uidoc,uiapp);
if (TransactionStatus.Committed != transaction.Commit())
{
// Autodesk.Revit.UI.TaskDialog.Show("Failure", "Transaction could not be committed");
//an error occured end resolution was cancled thus this change can't be committed.
// just ignore it and dont bug the user
}
}
}
}
}
示例10: Build
/// <summary>
/// The build method is called back from the child class.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Build(object sender, EventArgs e)
{
dynElement el = sender as dynElement;
bool useTransaction = true;
object[] attribs = el.GetType().GetCustomAttributes(typeof(RequiresTransactionAttribute), false);
if (attribs.Length > 0)
{
if ((attribs[0] as RequiresTransactionAttribute).RequiresTransaction == false)
{
useTransaction = false;
}
}
#region using transaction
if (useTransaction)
{
Transaction t = new Transaction(dynElementSettings.SharedInstance.Doc.Document, el.GetType().ToString() + " update.");
TransactionStatus ts = t.Start();
try
{
FailureHandlingOptions failOpt = t.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(dynElementSettings.SharedInstance.WarningSwallower);
t.SetFailureHandlingOptions(failOpt);
el.Destroy();
el.Draw();
UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { el });
elementsHaveBeenDeleted = false;
ts = t.Commit();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
dynElementSettings.SharedInstance.Bench.Log(ex.Message);
SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
new object[] { ex.Message});
MarkConnectionStateDelegate mcsd = new MarkConnectionStateDelegate(MarkConnectionState);
Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
new object[] { true });
if (ts == TransactionStatus.Committed)
{
t.RollBack();
}
t.Dispose();
dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
}
try
{
el.UpdateOutputs();
}
catch(Exception ex)
{
//Debug.WriteLine("Outputs could not be updated.");
dynElementSettings.SharedInstance.Bench.Log("Outputs could not be updated.");
if (ts == TransactionStatus.Committed)
{
t.RollBack();
}
t.Dispose();
dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
}
}
#endregion
#region no transaction
if (!useTransaction)
{
try
{
el.Destroy();
el.Draw();
UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
//.........这里部分代码省略.........
示例11: OnIFCExport
/// <summary>
/// Implementation of the command binding event for the IFC export command.
/// </summary>
/// <param name="sender">The event sender (Revit UIApplication).</param>
/// <param name="args">The arguments (command binding).</param>
public void OnIFCExport(object sender, CommandEventArgs args)
{
try
{
// Prepare basic objects
UIApplication uiApp = sender as UIApplication;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
IFCExportConfigurationsMap configurationsMap = new IFCExportConfigurationsMap();
configurationsMap.Add(IFCExportConfiguration.GetInSession());
configurationsMap.AddBuiltInConfigurations();
configurationsMap.AddSavedConfigurations(doc);
String mruSelection = null;
if (m_mruConfiguration != null && configurationsMap.HasName(m_mruConfiguration))
mruSelection = m_mruConfiguration;
IFCExport mainWindow = new IFCExport(configurationsMap, mruSelection);
mainWindow.ShowDialog();
// If user chose to continue
if (mainWindow.Result == IFCExportResult.ExportAndSaveSettings)
{
// change options
IFCExportConfiguration selectedConfig = mainWindow.GetSelectedConfiguration();
// Prepare the export options
IFCExportOptions exportOptions = new IFCExportOptions();
selectedConfig.UpdateOptions(exportOptions, uiDoc.ActiveView.Id);
// prompt for the file name
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.AddExtension = true;
String defaultDirectory = m_mruExportPath != null ? m_mruExportPath : null;
if (defaultDirectory == null)
{
String revitFilePath = doc.PathName;
if (!String.IsNullOrEmpty(revitFilePath))
{
defaultDirectory = Path.GetDirectoryName(revitFilePath);
}
}
if (defaultDirectory == null)
{
defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
String defaultFileName = doc.Title;
if (String.IsNullOrEmpty(defaultFileName))
{
defaultFileName = "Project";
}
else
{
defaultFileName = Path.GetFileNameWithoutExtension(defaultFileName);
}
String defaultExtension = mainWindow.GetFileExtension();
fileDialog.FileName = defaultFileName;
fileDialog.DefaultExt = defaultExtension;
fileDialog.Filter = mainWindow.GetFileFilter();
fileDialog.InitialDirectory = defaultDirectory;
bool? fileDialogResult = fileDialog.ShowDialog();
// If user chose to continue
if (fileDialogResult.HasValue && fileDialogResult.Value)
{
// Prompt the user for the file location and path
String fullName = fileDialog.FileName;
String path = Path.GetDirectoryName(fullName);
String fileName = Path.GetFileName(fullName);
// IFC export requires an open transaction, although no changes should be made
Transaction transaction = new Transaction(doc, "Export IFC");
transaction.Start();
FailureHandlingOptions failureOptions = transaction.GetFailureHandlingOptions();
failureOptions.SetClearAfterRollback(false);
transaction.SetFailureHandlingOptions(failureOptions);
// There is no UI option for this, but these two options can be useful for debugging/investigating
// issues in specific file export. The first one supports export of only one element
//exportOptions.AddOption("SingleElement", "174245");
// The second one supports export only of a list of elements
//exportOptions.AddOption("ElementsForExport", "174245;205427");
bool result = doc.Export(path, fileName, exportOptions); // pass in the options here
if (!result)
{
//TODO localization
TaskDialog taskDialog = new TaskDialog("Error exporting IFC file");
//.........这里部分代码省略.........
示例12: Execute
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements)
{
try
{
//create a log file
string tempPath = System.IO.Path.GetTempPath();
string logPath = Path.Combine(tempPath, "dynamoLog.txt");
if (File.Exists(logPath))
File.Delete(logPath);
tw = new StreamWriter(logPath);
tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString());
m_revit = revit.Application;
m_doc = m_revit.ActiveUIDocument;
trans = new Transaction(m_doc.Document, "Dynamo");
trans.Start();
FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(new DynamoWarningSwallower());
trans.SetFailureHandlingOptions(failOpt);
m_revit.Idling += new EventHandler<IdlingEventArgs>(OnIdling);
#region default level
Level defaultLevel = null;
FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document);
fecLevel.OfClass(typeof(Level));
for (int i = 0; i < fecLevel.ToElements().Count; i++)
{
defaultLevel = fecLevel.ToElements()[i] as Level;
break;
}
#endregion
DynamoWarningSwallower swallow = new DynamoWarningSwallower();
dynElementSettings.SharedInstance.Revit = m_revit;
dynElementSettings.SharedInstance.Doc = m_doc;
dynElementSettings.SharedInstance.DefaultLevel = defaultLevel;
dynElementSettings.SharedInstance.WarningSwallower = swallow;
dynElementSettings.SharedInstance.MainTransaction = trans;
dynElementSettings.SharedInstance.Writer = tw;
//dynElementSettings settings = new dynElementSettings(m_revit, m_doc,
//defaultLevel, swallow, trans);
//show the log
dynamoForm = new dynBench();
//get the window handle
Process process = Process.GetCurrentProcess();
new System.Windows.Interop.WindowInteropHelper(dynamoForm).Owner = process.MainWindowHandle;
dynamoForm.Show();
if (dynamoForm.DialogResult.HasValue && dynamoForm.DialogResult.Value == false) //the WPF false is "cancel"
{
tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString());
tw.Close();
return Autodesk.Revit.UI.Result.Cancelled;
}
}
catch (Exception e)
{
trans.Dispose();
Debug.WriteLine(e.Message + ":" + e.StackTrace);
Debug.WriteLine(e.InnerException);
message = e.Message + " : " + e.StackTrace;
if (tw != null)
{
tw.WriteLine(e.Message);
tw.WriteLine(e.StackTrace);
tw.Close();
}
return Autodesk.Revit.UI.Result.Failed;
}
trans.Commit();
return Autodesk.Revit.UI.Result.Succeeded;
}
示例13: StartTransaction
/// <summary>
/// Starts a RevitAPI Transaction that will be managed by this TransactionManager instance.
/// </summary>
/// <param name="document">Document (DB) to start a Transaction for.</param>
public TransactionHandle StartTransaction(Document document)
{
if (Transaction == null || Transaction.GetStatus() != TransactionStatus.Started)
{
TransactionManager.Log("Starting Transaction.");
Transaction = new Transaction(document, "Dynamo Script");
Transaction.Start();
FailureHandlingOptions failOpt = Transaction.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(handler);
Transaction.SetFailureHandlingOptions(failOpt);
RaiseTransactionStarted();
}
return Handle;
}
示例14: Execute
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
m_revitApp = commandData.Application.Application;
m_doc = commandData.Application.ActiveUIDocument.Document;
Level level1 = GetLevel();
if (level1 == null)
{
throw new Exception("[ERROR] Failed to get level 1");
}
try
{
//
// Post a warning and resolve it in FailurePreproccessor
try
{
Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor");
FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
FailurePreproccessor preproccessor = new FailurePreproccessor();
options.SetFailuresPreprocessor(preproccessor);
transaction.SetFailureHandlingOptions(options);
transaction.Start();
FailureMessage fm = new FailureMessage(m_idWarning);
m_doc.PostFailure(fm);
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Warning_FailurePreproccessor";
return Result.Failed;
}
//
// Dismiss the overlapped wall warning in FailurePreproccessor
try
{
Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor_OverlappedWall");
FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
FailurePreproccessor preproccessor = new FailurePreproccessor();
options.SetFailuresPreprocessor(preproccessor);
transaction.SetFailureHandlingOptions(options);
transaction.Start();
Line line = m_revitApp.Create.NewLineBound(new XYZ(-10, 0, 0), new XYZ(-20, 0, 0));
Wall wall1 = m_doc.Create.NewWall(line, level1, false);
Wall wall2 = m_doc.Create.NewWall(line, level1, false);
m_doc.Regenerate();
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Warning_FailurePreproccessor_OverlappedWall";
return Result.Failed;
}
//
// Post an error and resolve it in FailuresProcessingEvent
try
{
m_revitApp.FailuresProcessing += new EventHandler<Autodesk.Revit.DB.Events.FailuresProcessingEventArgs>(FailuresProcessing);
Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessingEvent");
transaction.Start();
Line line = m_revitApp.Create.NewLineBound(new XYZ(0, 10, 0), new XYZ(20, 10, 0));
Wall wall = m_doc.Create.NewWall(line, level1, false);
m_doc.Regenerate();
FailureMessage fm = new FailureMessage(m_idError);
FailureResolution fr = DeleteElements.Create(m_doc, wall.Id);
fm.AddResolution(FailureResolutionType.DeleteElements, fr);
m_doc.PostFailure(fm);
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Error_FailuresProcessingEvent";
return Result.Failed;
}
//
// Post an error and resolve it in FailuresProcessor
//.........这里部分代码省略.........