Message 1 of 3
Creating a Drafting View
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to just create a new drafting view....I have found the following series of back and forth, and it definitely helped me get somewhere.
https://forums.autodesk.com/t5/revit-api-forum/viewdrafting-create-viewfamilytypeid/td-p/5679197
HOWEVER, when I click the command in a Revit project, it just crashes and closes. From what little I understand at the moment, I think this has something to do with the "Transaction".
Is there anyone that wouldnt mind explaining, on a basic level since I am new at this, how to create a new drafting view, and where I am going wrong. I want to understand this on a fundamental level and not simply cookbook code.
The following is the code I managed to pull together
[Transaction(TransactionMode.Manual)] public class Command : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; ViewFamilyType vd = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast<ViewFamilyType>() .FirstOrDefault(q => q.ViewFamily == ViewFamily.Drafting); ViewDrafting view = ViewDrafting.Create(doc, vd.Id); return Result.Succeeded; } }
Please and thank you.
JW