DynamoCore Accessing External Graph

Hi all,
I am trying to access an external graph through the following code in c#, but there is an error with doc.Load(test); system.Xml.XmlException: ‘Data at the root level is invalid. Line 1, position 1.’

public static NodeGraph GetFromFilePath(string test)
{
XmlDocument doc = new XmlDocument();
doc.Load(test);

       NodeGraph nG;
       NodeFactory nF = new NodeFactory();
       nG = NodeGraph.LoadGraphFromXml(doc, nF);
   

       return nG;
   }

Is there any other way to access an external graph and its nodes?
Thanks

you’re probably trying to load a dynamo 2.x graph which is json not xml.
What are you trying to accomplish in the end?

2 Likes

Yes, it is 2.X. I am trying to access an external graph to get the input nodes from it.
Could I access it from json?
Thanks

Could anybody help?

What are you trying to do with the input nodes?

If you just need to know about them you can just parse the json with any json library in any languge - and be done with it -

if you want to interact with them then you should probably be writing a Dynamo extension, access the current workspace, find the nodes that are inputs and do you work there.

see:
DynamoSamples/Extension.cs at master · DynamoDS/DynamoSamples (github.com)

and
DynamoSamples/SampleViewExtension.cs at master · DynamoDS/DynamoSamples (github.com)

alternatively you can of course consume the dynamo nugets and build your own mini dynamo sandbox application that creates a workspace and does whatever.
Eventually you’d want to call Dynamo/DynamoModel.cs at b49c661abeb0b70599526a1c8a64017b95bc24a5 · DynamoDS/Dynamo (github.com) to open a json file.

Thanks @Michael_Kirschner2 ! We will give it a try. We are trying to access them from a C# Revit Add-In to modify the input values and return them to Dynamo for execution. We achieved the execution through JournalPaths and we wondered it there would be an easy way to do this without implementing everything for a Dynamo extension.

ahh, well it’s possible, but Dynamo is not designed to have multiple DynamoModels (applications) existing at the current time in the same process. Weird things will happen, like double backup save etc.

So - you may want to attach to the currently loaded DynamoModel - thats why an extension is nice.

Alternatively, to be safe you could try starting a new process, create your DynamoModel there, open the workspace, make modifications, save.

Or, just modify the json directly, - this is not a great idea, but it has pros as well if you make very constrained modifications where you know exactly what you’re doing.

1 Like

Thanks @Michael_Kirschner2 !
I was using a method similar to this one;

I created a ViewExtension for Dynamo as well.
But is there a way to run the view extension or to detect input nodes, add values, run and save graph within Parallax Method?