Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I try to use the stacktrace of my revit scripts.
In this case I try to create a sheet with a number that already exist.
I want to retrieve the data from my stacktrace, for example the line of my script where this script goes wrong.
In this case "Line 30".
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Diagnostics;
using static VDS.VDS_standaard_definities;
namespace VDS
{
[Transaction(TransactionMode.Manual)]
public class StackTraceVDS : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//UIApplicatin, uidoc, doc
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
using (Transaction tx = new Transaction(doc, "Test"))
{
try
{
tx.Start();
VDS_Sheets vDS_Sheets = new VDS_Sheets();
Element tBlock = vDS_Sheets.VDS_GetTitleBlockByName(doc, "A3 Landschap");
ViewSheet sheet = ViewSheet.Create(doc, tBlock.Id);
sheet.SheetNumber = "L-00";
tx.Commit();
}
catch (Exception ex)
{
StackTrace stackTrace = new StackTrace(ex, true);
StackFrame stackFrame = stackTrace.GetFrame(0);
var fileName = stackFrame.GetFileName();
var method = stackFrame.GetMethod();
var number = stackFrame.GetFileLineNumber();
Debug.Print($"Filenaam: {fileName}");
Debug.Print($"Method: {method}");
Debug.Print($"number: {number}");
}
}
return Result.Succeeded;
}
}
}
This is what I retrieve in my debug:
Filenaam:
Method: Void set_SheetNumber(System.String)
number: 0
Any thoughts?
KG,
Jan Willem
Solved! Go to Solution.