Hello,
Im new to the whole extentions and view extentions in dynamo and am trying to create an view extention that modifies existing groups and the nodes in them. So far im able to:
Get all nodes
_p.CurrentWorkspaceModel.Nodes (_p = ViewLoadedParams)
Create new nodes
_p.CommandExecutive.ExecuteCommand(new DynamoModel.CreateNodeCommand(pythonNode, 0, 0,true, false), ExtentionDefaults.UniqueId, ExtentionDefaults.Name);
Create new groups and add nodes to the new group
Dynamo.Graph.Annotations.AnnotationModel annotation = new Dynamo.Graph.Annotations.AnnotationModel(new List() { pythonNode }, new List<Dynamo.Graph.Notes.NoteModel>());
I cannot seem to find a way to get existing groups, i would expect that there to be something like
_p.CurrentWorkspaceModel.Annotations but there isnt
is it possible to get the existing groups in the workspacemodel?
https://www.fuget.org/packages/DynamoVisualProgramming.Core/2.5.0-beta6104/net47/lib/DynamoCore.dll/Dynamo.Graph.Workspaces/WorkspaceModel#Annotations
you likely need to cast the workspace to WorkspaceModel
since its just an interface
IWorkspaceModel
something like
(_p.CurrentWorkspaceModel as WorkspaceModel).Annotations but there isnt
Many thanks for this solution, it is working and i can get the existing groups.
i noticed however that the WorkspaceModel.Annotations is obsolete
and i cannot cast the Currentworkspacemodel as WorkspaceViewModel. How would i get the WorkspaceViewModel of my active window?
Hi Martin, there is a solution but I hesitate to share it because it is a hack we intend to obsolete and provide better APIs for in the future.
knowing this, it is likely we will not remove the obsolete properties from WorkspaceModel for some time.
Currently you can get the DynamoWindow from the extension, then cast its DataContext to a DynamoViewModel - if you do this please be aware it’s not stable and we’re working to provide a more robust API.
then ill use the casting to WorkspaceModel, many thanks again