Good morning forum,
I am in the process of starting my journey in the explicit nodes world. Until now I have managed to get a control on the node to show an icon and to define the node itself.
The problem now is to get it to work! Can anyone help me to understand what am I missing? Any better documentation to look at?
Can’t get it to work properly and to use the default values…
The same node in ZeroTouch version works perfectly.
using AECOM.Civil;
using DynAECOMo.UI.Controls;
using Dynamo.Controls;
using Dynamo.Graph.Nodes;
using Dynamo.Wpf;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DynAECOM.Nodes.Landxml
{
[NodeCategory("DynAECOM.Landxml")]
[NodeName("OpenDocument")]
[NodeDescription("Open a landxml document")]
[InPortTypes("string", "double", "double")]
[InPortNames("filePath", "easting", "northing")]
[OutPortTypes("AECOM.Civil.LandXml")]
[OutPortNames("landxml")]
public class OpenDocument : NodeModel
{
public LandXml Landxml { get; set; }
public double Easting { get; set; }
public double Northing { get; set; }
[JsonConstructor]
public OpenDocument(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
}
public OpenDocument()
{
//InPorts.Add(new PortModel(PortType.Input, this, new PortData("File Path", "The file path for the landxml file")));
//InPorts.Add(new PortModel(PortType.Input, this, new PortData("Easting", "Easting project base point [Default is 0.0]")));
//InPorts.Add(new PortModel(PortType.Input, this, new PortData("Northing", "Northing project base point [Default is 0.0]")));
//OutPorts.Add(new PortModel(PortType.Output, this, new PortData("Landxml", "The landxml parsed object")));
RegisterAllPorts();
ArgumentLacing = LacingStrategy.Disabled;
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
// If any of the input nodes is not connected, assign output node 0 a null node return value
if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[0].Connectors.Any())
{
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
}
AssociativeNode inputNode = AstFactory.BuildFunctionCall(
new Func<string, double, double, LandXml>(LandxmlFunctions.OpenLandxmlDocument),
new List<AssociativeNode> { inputAstNodes[0], inputAstNodes[1], inputAstNodes[2] }
);
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), inputNode) };
}
}
public class OpenDocumentNodeView : INodeViewCustomization<OpenDocument>
{
public void CustomizeView(OpenDocument model, NodeView nodeView)
{
var control = new OpenControlUI();
nodeView.inputGrid.Children.Add(control);
control.DataContext = model;
}
public void Dispose()
{
}
}
}
And then the function
using AECOM.Civil;
using Autodesk.DesignScript.Runtime;
namespace DynAECOM
{
public class LandxmlFunctions
{
private LandxmlFunctions() { }
[IsVisibleInDynamoLibrary(false)]
public static LandXml LandXml { get; set; }
[IsVisibleInDynamoLibrary(false)]
public static double Easting { get; set; }
[IsVisibleInDynamoLibrary(false)]
public static double Northing { get; set; }
[IsVisibleInDynamoLibrary(false)]
public static LandXml OpenLandxmlDocument(string filePath, double easting = 0, double northing = 0)
{
LandXml = new LandXml(filePath);
Easting = easting;
Northing = northing;
return LandXml;
}
}
}
And finally a portion of the class which literally does nothing but opening a file
public class LandXml
{
/// <summary>
/// The XML file path
/// </summary>
public string FilePath { get; set; }
public XmlDocument Document { get; private set; }
public Application Application => GetApplication();
public ICollection<Alignment> Alignments => GetAlignments();
public ICollection<Surface> Surfaces => GetSurfaces();
public LandXml(string filePath)
{
this.FilePath = filePath;
this.Document = new XmlDocument();
this.Document.Load(this.FilePath);
}
}