/
dtDynamo.cs
684 lines (621 loc) · 22.1 KB
/
dtDynamo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dynamo.Core;
using Dynamo.Applications;
using Autodesk.DesignScript.Runtime;
using System.Windows.Media;
namespace dtDynamo
{
public class NodeGraph
{
internal NodeGraph()
{
}
#region GetFromFilePath
/// <summary>
/// Retrieves the Dynamo node graph from the dyn file path.
/// </summary>
/// <param name="dynFilePath">string</param>
/// <returns name="nodeGraph">Dynamo.Graph.NodeGraph</returns>
/// <search>
/// dynamo, api, file, path, node, graph, retrieve, get, from
/// </search>
public static Dynamo.Graph.NodeGraph GetFromFilePath(string dynFilePath)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(dynFilePath);
Dynamo.Graph.NodeGraph nodeGraph;
Dynamo.Graph.Nodes.NodeLoaders.NodeFactory nodeFactory = new Dynamo.Graph.Nodes.NodeLoaders.NodeFactory();
nodeGraph = Dynamo.Graph.NodeGraph.LoadGraphFromXml(doc, nodeFactory);
return nodeGraph;
}
#endregion
#region Groups
/// <summary>
/// Retrieves the groups/annotations from the Node Graph
/// </summary>
/// <param name="nodeGraph">Dynamo.Graph.NodeGraph</param>
/// <returns name="groups">Dynamo.Graph.Annotations.AnnotationModel</returns>
/// <search>
/// dynamo, api, node, graph, annotation, model, groups
/// </search>
public static List<Dynamo.Graph.Annotations.AnnotationModel> Groups(Dynamo.Graph.NodeGraph nodeGraph)
{
return nodeGraph.Annotations;
}
#endregion
#region Connectors
/// <summary>
/// Retrieves the current amount of connectors from the node graph
/// </summary>
/// <param name="nodeGraph">Dynamo.Graph.NodeGraph</param>
/// <returns name="amount">int</returns>
/// <search>
/// dynamo, api, current, node, graph, wires, connectors, count
/// </search>
public static int Connectors(Dynamo.Graph.NodeGraph nodeGraph)
{
List<Dynamo.Graph.Connectors.ConnectorModel> con = new List<Dynamo.Graph.Connectors.ConnectorModel>(nodeGraph.Connectors);
return con.Count;
}
#endregion
#region Nodes
/// <summary>
/// Retrieves the nodes from the Node Graph
/// </summary>
/// <param name="nodeGraph">Dynamo.Graph.NodeGraphl</param>
/// <returns name="nodes">Dynamo.Graph.Nodes.NodeModel</returns>
/// <search>
/// dynamo, api, node, graph, nodes, model
/// </search>
public static IEnumerable<Dynamo.Graph.Nodes.NodeModel> Nodes(Dynamo.Graph.NodeGraph nodeGraph)
{
return nodeGraph.Nodes;
}
#endregion
#region Notes
/// <summary>
/// Retrieves the text from the notes of the supplied node graph
/// </summary>
/// <param name="nodeGraph">Dynamo.Graph.NodeGraph</param>
/// <returns name="notes">Dynamo.Graph.Notes.NoteModel</returns>
/// <search>
/// dynamo, api, current, node, graph, notes, text, string
/// </search>
public static IEnumerable<Dynamo.Graph.Notes.NoteModel> Notes(Dynamo.Graph.NodeGraph nodeGraph)
{
//List<Dynamo.Graph.Notes.NoteModel> notes = new List<Dynamo.Graph.Notes.NoteModel>(nodeGraph.Notes);
//
//List<string> output = new List<string>();
//foreach (var n in notes)
//{
// output.Add(n.Text.ToString());
//}
return nodeGraph.Notes;
}
#endregion
}
public class Workspace
{
internal Workspace()
{
}
#region Author
/// <summary>
/// Tells you the Dynamo Graphs Author.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="author">string</returns>
/// <search>
/// dynamo, api, workspace, author, name, person
/// </search>
public static string Author(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.Author;
}
#endregion
#region Connectors
/// <summary>
/// Retrieves the amount of connectors from the workspace
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="amount">int</returns>
/// <search>
/// dynamo, api, workspace, wires, connectors, count
/// </search>
public static int Connectors(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
List<Dynamo.Graph.Connectors.ConnectorModel> con = new List<Dynamo.Graph.Connectors.ConnectorModel>(workspace.Connectors);
return con.Count;
}
#endregion
#region Current
/// <summary>
/// Retrieves the current Dynamo workspace model.
/// </summary>
/// <returns name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</returns>
/// <search>
/// dynamo, api, current, workspace, retrieve, get
/// </search>
public static Dynamo.Graph.Workspaces.WorkspaceModel Current()
{
var model = Dynamo.Applications.DynamoRevit.RevitDynamoModel;
Dynamo.Graph.Workspaces.WorkspaceModel ws = model.CurrentWorkspace;
return ws;
}
#endregion
#region Description
/// <summary>
/// Tells you the Dynamo Graphs Description.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="description">string</returns>
/// <search>
/// dynamo, api, workspace, description, notes, field
/// </search>
public static string Description(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
var message = workspace.Description;
if (message == null)
{
return "Description field is empty.";
}
else
{
return message;
}
}
#endregion
#region FileName
/// <summary>
/// Tells you the Dynamo Graphs File Name.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="fileName">string</returns>
/// <search>
/// dynamo, api, workspace, filename
/// </search>
public static string FileName(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
string f = workspace.FileName;
if (f == "")
{
return "File has not been saved yet.";
}
int ind = f.LastIndexOf("\\");
string fN = f.Remove(0, (ind + 1));
return fN;
//return workspace.FileName;
}
#endregion
#region FilePath
/// <summary>
/// Tells you the Dynamo Graphs File Path.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="filePath">string</returns>
/// <search>
/// dynamo, api, workspace, file, path
/// </search>
public static string FilePath(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.FileName;
}
#endregion
#region Groups
/// <summary>
/// Retrieves the groups/annotations from the workspace
/// </summary>
/// <param name="workspace">Dynamo.Graph.NodeGraphl</param>
/// <returns name="groups">Dynamo.Graph.Annotations.AnnotationModel</returns>
/// <search>
/// dynamo, api, node, graph, annotation, model, groups
/// </search>
public static IEnumerable<Dynamo.Graph.Annotations.AnnotationModel> Groups(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.Annotations;
}
#endregion
#region GUID
/// <summary>
/// Tells you the Dynamo Graphs GUID.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="guid">Guid</returns>
/// <search>
/// dynamo, api, workspace, guid, global unique identifier, unique
/// </search>
public static Guid GUID(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.Guid;
}
#endregion
#region HasUnsavedChanges
/// <summary>
/// Tells you if the Dynamo Graph has any Unsaved Changes.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="bool">bool</returns>
/// <search>
/// dynamo, api, workspace, unsaved, changes,
/// </search>
public static bool UnsavedChanges(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.HasUnsavedChanges;
}
#endregion
#region IsReadOnly
/// <summary>
/// Tells you if the Dynamo Graph is Read Only.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="bool">bool</returns>
/// <search>
/// dynamo, api, workspace, readonly, read only, is read only
/// </search>
public static bool IsReadOnly(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.IsReadOnly;
}
#endregion
#region LastSaved
/// <summary>
/// Tells you the Dynamo Graphs last Save Time.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="lastSaved">DateTime</returns>
/// <search>
/// dynamo, api, workspace, save, last saved
/// </search>
public static DateTime LastSaved(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.LastSaved;
}
#endregion
#region Name
/// <summary>
/// Tells you the Dynamo Graphs Name.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="name">string</returns>
/// <search>
/// dynamo, api, workspace, name, title
/// </search>
public static string Name(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.Name;
}
#endregion
#region Nodes
/// <summary>
/// Retrieves the nodes from the workspace
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="nodes">Dynamo.Graph.Nodes.NodeModel</returns>
/// <search>
/// dynamo, api, node, workspace, nodes, model
/// </search>
public static IEnumerable<Dynamo.Graph.Nodes.NodeModel> Nodes(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.Nodes;
}
#endregion
#region Notes
/// <summary>
/// Retrieves all Notes from the workspace.
/// </summary>
/// <param name="workspace">Dynamo.Graph.Workspaces.WorkspaceModel</param>
/// <returns name="notes">Dynamo.Graph.Notes.NoteModel</returns>
/// <search>
/// dynamo, api, workspace, notes, text
/// </search>
public static IEnumerable<Dynamo.Graph.Notes.NoteModel> Notes(Dynamo.Graph.Workspaces.WorkspaceModel workspace)
{
return workspace.Notes;
}
#endregion
}
public class Node
{
internal Node()
{
}
#region Category
/// <summary>
/// Retrieves the current amount of nodes from the workspace
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="category">string</returns>
/// <search>
/// dynamo, api, node, model, name, string
/// </search>
public static string Category(Dynamo.Graph.Nodes.NodeModel node)
{
return node.Category;
}
#endregion
#region CreationName
/// <summary>
/// Retrieves the type of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="name">string</returns>
/// <search>
/// dynamo, api, node, model, name, string, creation
/// </search>
public static string CreationName(Dynamo.Graph.Nodes.NodeModel node)
{
return node.CreationName;
}
#endregion
#region Description
/// <summary>
/// Retrieves the description of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="desc">string</returns>
/// <search>
/// dynamo, api, node, model, description, string
/// </search>
public static string Description(Dynamo.Graph.Nodes.NodeModel node)
{
return node.Description;
}
#endregion
#region GUID
/// <summary>
/// Retrieves the Guid of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="guid">Guid</returns>
/// <search>
/// dynamo, api, node, model, guid
/// </search>
public static Guid GUID(Dynamo.Graph.Nodes.NodeModel node)
{
return node.GUID;
}
#endregion
#region IsFrozen
/// <summary>
/// Tells you if the node is frozen
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="bool">bool</returns>
/// <search>
/// dynamo, api, node, model, is, frozen, bool, yes, no, true, false
/// </search>
public static bool IsFrozen(Dynamo.Graph.Nodes.NodeModel node)
{
return node.IsFrozen;
}
#endregion
#region IsInErrorState
/// <summary>
/// Tells you if the node has an error
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="bool">bool</returns>
/// <search>
/// dynamo, api, node, element, state, error, is, in, bool, yes, no, true, false
/// </search>
public static bool IsInErrorState(Dynamo.Graph.Nodes.NodeModel node)
{
return node.IsInErrorState;
}
#endregion
#region Name
/// <summary>
/// Retrieves the name of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="name">string</returns>
/// <search>
/// dynamo, api, node, model, name, string
/// </search>
public static string Name(Dynamo.Graph.Nodes.NodeModel node)
{
return node.Name;
}
#endregion
#region Nickname
/// <summary>
/// Retrieves the nickname of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="nickname">string</returns>
/// <search>
/// dynamo, api, node, nickname, name, string
/// </search>
public static string Nickname(Dynamo.Graph.Nodes.NodeModel node)
{
return node.NickName;
}
#endregion
#region Position
/// <summary>
/// Retrieves the position of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="position">string</returns>
/// <search>
/// dynamo, api, node, model, position, x, y
/// </search>
public static string Position(Dynamo.Graph.Nodes.NodeModel node)
{
double x = node.CenterX;
double y = node.CenterY;
string pos = "x = " + x.ToString() + ", y = " + y.ToString();
return pos;
}
#endregion
#region State
/// <summary>
/// Tells you current state of the node. Will return either Active, AstBuildBroken, Dead, Error, PersistentWarning or Warning
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="state">string</returns>
/// <search>
/// dynamo, api, node, element, state, error, warning, active, AstBuildBroken, Dead, Error, PersistentWarning
/// </search>
public static string State(Dynamo.Graph.Nodes.NodeModel node)
{
string eS = node.State.ToString();
return eS;
}
#endregion
#region Tags
/// <summary>
/// Retrieves the Tags of the node
/// </summary>
/// <param name="node">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="tags">string</returns>
/// <search>
/// dynamo, api, node, model, tags
/// </search>
public static List<string> Tags(Dynamo.Graph.Nodes.NodeModel node)
{
return node.Tags;
}
#endregion
}
public class Note
{
internal Note()
{
}
#region GUID
/// <summary>
/// Retrieves the guid of the note
/// </summary>
/// <param name="note">Dynamo.Graph.Notes.NoteModel</param>
/// <returns name="guid">guid</returns>
/// <search>
/// dynamo, api, note, model, guid
/// </search>
public static Guid GUID(Dynamo.Graph.Notes.NoteModel note)
{
return note.GUID;
}
#endregion
#region Position
/// <summary>
/// Retrieves the position of the node
/// </summary>
/// <param name="note">Dynamo.Graph.Nodes.NodeModel</param>
/// <returns name="position">string</returns>
/// <search>
/// dynamo, api, note, model, position, x, y
/// </search>
public static string Position(Dynamo.Graph.Notes.NoteModel note)
{
double x = note.CenterX;
double y = note.CenterY;
string pos = "x = " + x.ToString() + ", y = " + y.ToString();
return pos;
}
#endregion
#region Text
/// <summary>
/// Retrieves the text of the note
/// </summary>
/// <param name="note">Dynamo.Graph.Notes.NoteModel</param>
/// <returns name="text">string</returns>
/// <search>
/// dynamo, api, note, text, string
/// </search>
public static string Text(Dynamo.Graph.Notes.NoteModel note)
{
return note.Text;
}
#endregion
}
public class Group
{
internal Group()
{
}
#region Colour
/// <summary>
/// Retrieves the colour of the group
/// </summary>
/// <param name="group">Dynamo.Graph.Annotations.AnnotationModel</param>
/// <returns name="colour">Colour</returns>
/// <search>
/// dynamo, api, group, annotation, model, colour, color
/// </search>
public static DSCore.Color Colour(Dynamo.Graph.Annotations.AnnotationModel group)
{
string back = group.Background;
Color colour = (Color)ColorConverter.ConvertFromString(back);
int a = colour.A;
int r = colour.R;
int g = colour.G;
int b = colour.B;
DSCore.Color dynColour = DSCore.Color.ByARGB(a, r, g, b);
return dynColour;
}
#endregion
#region FontSize
/// <summary>
/// Retrieves the font size of the group
/// </summary>
/// <param name="group">Dynamo.Graph.Annotations.AnnotationModel</param>
/// <returns name="fontSize">double</returns>
/// <search>
/// dynamo, api, group, annotation, model, font, size, text
/// </search>
public static double FontSize(Dynamo.Graph.Annotations.AnnotationModel group)
{
return group.FontSize;
}
#endregion
#region GUID
/// <summary>
/// Retrieves the guid of the group
/// </summary>
/// <param name="group">Dynamo.Graph.Annotations.AnnotationModel</param>
/// <returns name="guid">guid</returns>
/// <search>
/// dynamo, api, group, annotation, model, guid
/// </search>
public static Guid GUID(Dynamo.Graph.Annotations.AnnotationModel group)
{
return group.GUID;
}
#endregion
#region Position
/// <summary>
/// Retrieves the position of the group
/// </summary>
/// <param name="group">Dynamo.Graph.Annotations.AnnotationModel</param>
/// <returns name="position">string</returns>
/// <search>
/// dynamo, api, group, annotation, model, position, x, y
/// </search>
public static string Position(Dynamo.Graph.Annotations.AnnotationModel group)
{
double x = group.CenterX;
double y = group.CenterY;
string pos = "x = " + x.ToString() + ", y = " + y.ToString();
return pos;
}
#endregion
#region Title
/// <summary>
/// Retrieves the title of the group
/// </summary>
/// <param name="group">Dynamo.Graph.Annotations.AnnotationModel</param>
/// <returns name="title">string</returns>
/// <search>
/// dynamo, api, group, annotation, model, title, string, text
/// </search>
public static string Title(Dynamo.Graph.Annotations.AnnotationModel group)
{
return group.AnnotationText;
}
#endregion
}
}