-
Notifications
You must be signed in to change notification settings - Fork 668
Revit element selection nodes should serialize and deserialize properly in Json #8131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@alfarok Is there a JIRA task for this? |
| /// <typeparam name="TSelection">The type which is used to constrain the selection.</typeparam> | ||
| /// <typeparam name="TResult">The type which is returned from the selection or subselection.</typeparam> | ||
| [DataContract] | ||
| public abstract class SelectionBase<TSelection, TResult> : NodeModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only way I have been able to prevent the freezing from occurring, even when adding [JsonIgnore] on all public properties. The [DataContract] prevents serialization unless explicitly defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the issue or not, but just in case it helps 😄 : where the deserialization is happening, have you tried specifying a JsonSerializerSettings settings object. This is where you declare how to handle nulls or missing properties during deserialization.
I've found explicitly declaring how to handle these clears up this kind of issues.
Also, I've had issues in the past with [JsonIgnore] being ignored itself, had to implement my own attribute.
| IEnumerable<string> selectionIdentifier, | ||
| IEnumerable<PortModel> inPorts, | ||
| IEnumerable<PortModel> outPorts) : base(inPorts, outPorts) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also still getting double output ports when deserializing even after adding these parameters. I know this was due to recent changes in the node model base class but not sure why it is still occurring. Maybe an empty constructor should be created at the DSFaceSelection level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah try that and make sure NodeModel(IEnumerable inPorts, IEnumerable outPorts) is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QilongTang @mjkkirschner I have actually made some progress by adding JsonConstructors through the entire inheritance chain shown in the description making sure to pass all the original parameters plus the revit element id propety data and port data. I am now getting a single output and the Revit referenced element is deserializing properly. The issue now is I can't select a new element after opening the file but I have a few ideas on resolving this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alfarok I believe the comment above is no longer valid? Do you have an update pic of the same DYN?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QilongTang yup this has all been resolved and I verified model elements outside of the standard geometry types are properly restoring as well (wall, roof, etc).

|
@mjkkirschner after updating all the references in D4R to point at my local build of Dynamo (opposed to the default NuGet packages) I still find that the base class I am referencing in Dynamo isn't updating in D4R. It seems it is still referencing some old cached metadata? For example, if I were to add a public property to the base class in Dynamo I am unable to access that inherited property in D4R |
|
@alfarok please confirm your json constructor is called at all?
|
| private List<TResult> selectionResults = new List<TResult>(); | ||
| private List<TSelection> selection = new List<TSelection>(); | ||
| private IEnumerable<string> selectionIdentifier; | ||
| private List<string> selectionIdentifier; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why this needed to be a List?
| { | ||
| selectionIdentifier = selection.Select(GetIdentifierFromModelObject).Where(x => x != null).ToList(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small change is still needed here. I believe this logic prevents the selectionIdentifier from updating once an initial value is stored. It will appear as if the new selection has been updated in Dynamo background preview, however the initial selection id will serialize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should write a test for that. Your own fault for bringing it up 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha probably for the best anyway...but does that mean RTF? 😕
| ShouldDisplayPreviewCore = true; | ||
|
|
||
| SelectionIdentifier = selectionIdentifier; | ||
| ResetSelectionFromIds(SelectionIdentifier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjkkirschner it could be an enum and this line changes to ResetSelectionFromIds(SelectionIdentifier.toList());
|
Seems to be working as expected now, going to work on some testing to verify further |
"Nodes": [
{
"ConcreteType": "Dynamo.Nodes.SelectFaces, DSRevitNodesUI",
"NodeType": "ExtensionNode",
"InstanceId": [
"3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:5:SURFACE",
"3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:6:SURFACE",
"3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:10:SURFACE",
"3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:18:SURFACE"
],
"Id": "4d90c28040f247ef8cc0a3d0e6eed4d7",@gregmarr Hey Greg, I was wondering if there should be another |
|
Revit bindings should probably go in here, that's what this is designed for: |
|
Does this node do anything else, or is it just a place to store these IDs? |
|
Ah, this sounds like a geometry input node. We've talked about adding one but haven't yet. https://jira.autodesk.com/browse/AGD-47 Edit: Ah, yes, I see that you edited the original message to say that, I didn't see the update until after my first two responses. |

Purpose
QNTM-1284
The purpose of this PR is to enable the serialization and deserialization of Revit element selection nodes in Json. Previously Revit/Dynamo would freeze when attempting save a graph containing Revit selection nodes and the Json file is never written. The selection node should also maintain the Revit element id that is referenced so it will automatically be recognized when reopening a graph.
Supplemental to D4R PR #1768
Updated Json Output
{ "Uuid": "ac033b17-4df4-4c56-bc42-533f7bad27fe", "IsCustomNode": false, "Description": null, "Name": "Home", "ElementResolver": { "ResolutionMap": {} }, "Inputs": [], "Nodes": [ { "ConcreteType": "Dynamo.Nodes.SelectFaces, DSRevitNodesUI", "NodeType": "ExtensionNode", "InstanceId": [ "3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:5:SURFACE", "3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:6:SURFACE", "3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:10:SURFACE", "3a376239-8db9-4f12-8dbb-774857dd156f-0000097b:18:SURFACE" ], "Id": "4d90c28040f247ef8cc0a3d0e6eed4d7", "Inputs": [], "Outputs": [ { "Id": "4953c930ce1040ea828e6f8a94328d8a", "Name": "Surfaces", "Description": "The selected elements.", "Level": 2, "UseLevels": false, "KeepListStructure": false } ], "Replication": "Disabled" } ], "Connectors": [], "Dependencies": [], "Bindings": [], "View": { "Camera": { "Name": "Background Preview", "EyeX": -17.0, "EyeY": 24.0, "EyeZ": 50.0, "LookX": 12.0, "LookY": -13.0, "LookZ": -58.0, "UpX": 0.0, "UpY": 1.0, "UpZ": 0.0 }, "NodeViews": [ { "ShowGeometry": true, "Name": "Select Faces", "Id": "4d90c28040f247ef8cc0a3d0e6eed4d7", "IsUpstreamVisible": true, "Excluded": false, "X": 135.60000000000002, "Y": 128.79999999999993 } ], "Notes": [], "Annotations": [], "X": 0.0, "Y": 0.0, "Zoom": 1.0 } }All RTF selection tests are passing including new tests:

Declarations
Check these if you believe they are true
*.resxfilesReviewers
@mjkkirschner
@QilongTang
FYIs