Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm attempting to port one of my Python nodes from Dynamo to ZeroTouch and I cant get the active document. All I am trying to do is convert the Python code to C# then import the library into Dynamo, not exactly hard, only I dont know how to get the active doc. I understand I have to create an IExternalCommand object then call an execute function and that's where I'm stumped as I cant return the document object from it. Can someone point me in the right direction:
Original code in Python:
import clr # Import DocumentManager and TransactionManager clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager # Import RevitAPI clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * doc = DocumentManager.Instance.CurrentDBDocument lineStyle = doc.Settings.Categories.get_Item( BuiltInCategory.OST_Lines ) lineStyleSubTypes = lineStyle.SubCategories listNames = [] listRGB = [] lineWeight = [] for i in lineStyleSubTypes: rgb = [i.LineColor.Red, i.LineColor.Green, i.LineColor.Blue] weight = i.GetLineWeight(GraphicsStyleType.Projection) listNames.append(i.Name) listRGB.append(rgb) lineWeight.append(weight) OUT = listNames, lineWeight, listRGB
Attempts in C#
public class GetActiveDocument : IExternalCommand { private Document _doc; internal GetActiveDocument(Document doc) { _doc = doc; } public static GetActiveDocument getDoc2(Document doc) { return new GetActiveDocument(doc); } public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Get application and document objects UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; return Result.Succeeded; } public Document getDoc { get { return _doc; } } }
Solved! Go to Solution.