Grasshopper

algorithmic modeling for Rhino

Hallo,

Somehow with this code the component will not recalculate when I change the settings in Menu? Any idea?

Protected Overrides Sub AppendAdditionalComponentMenuItems(ByVal menu As System.Windows.Forms.ToolStripDropDown)
MyBase.AppendAdditionalComponentMenuItems(menu)

Menu_AppendItem(menu, "delete", AddressOf setDelete, True, 0 = GetValue("methode", 0))
Menu_AppendItem(menu, "merge", AddressOf setMerge, True, 1 = GetValue("methode", 0))
End Sub

Private Sub setDelete()
SetValue("methode", 0)
SetMessage()
ExpireSolution(True)
End Sub

Private Sub setMerge()
SetValue("methode", 1)
SetMessage()
ExpireSolution(True)
End Sub

Private Sub SetMessage()
Select Case GetValue("methode", 0)
Case 0
Message = "delete"
Case 1
Message = "merge"
End Select

End Sub

Protected Overrides Sub SolveInstance(DA As Grasshopper.Kernel.IGH_DataAccess)
Dim G_DATATREE As Grasshopper.Kernel.Data.GH_Structure(Of Grasshopper.Kernel.Types.GH_Integer) = Nothing
Dim V_List As New List(Of Grasshopper.Kernel.Types.GH_Integer)

If (Not DA.GetDataList("Vertices", V_List)) Then Return
If (Not DA.GetDataTree("Graph", G_DATATREE)) Then Return

If (V_List.Count <= 0) Then Return

Dim M As Integer = GetValue("methode", 0)

For i As Integer = 0 To V_List.Count - 1
Select Case M
Case 0
GraphEdge.DeleteVertices(V_List.Item(i), G_DATATREE)
Case 1
GraphEdge.MergeVertices(V_List.Item(i), G_DATATREE)
End Select
Next

DA.SetDataTree(0, G_DATATREE)
End Sub

Views: 731

Replies to This Discussion

Surely this doesn't even compile?

The delegate you have to supply in Menu_AppendItem requires a signature like:

sub name(byval sender as object, byval e as eventargs)

--

David Rutten

david@mcneel.com

Tirol, Austria

No works great this way with other methodes, and also the message tags change so the delegates call the SetMessage methode but the solution isn't updated. Only when I recompute the complite solution it updates.

Changed the delegate signature, no change in behavior.

Attached the version of the component with a sample file.

Rar files don't work on Ning, you'll have to post it as a Zip.

--

David Rutten

david@mcneel.com

Tirol, Austria

Sorry, didn't remember

Attachments:

It totally recomputes for me. If I attach a Data Recorder to the manipulateGraph object it will keep on growing. However it does generate the same result each time, regardless of "delete" vs. "merge". The problem may be in GetValue and SetValue, debugging now...

--

David Rutten

david@mcneel.com

Tirol, Austria

I've put breakpoints on the GetValue and SetValue functions and I can't find anything wrong. I am returning 0 or 1 depending on which menu item was last clicked.

Can you circumvent the GetValue / Select Case logic with hardcoded calls to DeleteVertices and MergeVertices to see if those functions behave like expected?

--

David Rutten

david@mcneel.com

Tirol, Austria

Will do tomorrow, but as fare as I can tell the functions behave as expected. If you recompute the complete solution after changing delete/merge, the outcome is correct (besides that it only works for undirected graphs in the sample I uploaded. This has been changed by now).

delete: all edges leading from the specified vertex are deleted.

merge: all edges are reconnected between the neighbours of the specified vertex, and the edges leading from the specified vertex are deleted.

I am guessing by now that it might has to do something with G_DATATREE as it is the variable taking the input and send ByRef to the GraphEdge.DeleteVertices(ByVal, ByRef). and also used for the output I tried G_DATATREE.Duplicate() but that didn't change a thing.

thx for looking in that close,

Richard

Yes, you're right. I'll dig some more later today.

--

David Rutten

david@mcneel.com

Tirol, Austria

I did find one fairly suspicious bit of code. It seems you are modifying the datatree you're getting from the input parameter inside SolveInstance. Inside DeleteVertices you're removing items from branches. This is not legal. If you're getting datatrees from inputs you are messing directly with the storage of data inside the input parameter.

If you want to remove or add items to such a tree, you should first create a shallow copy. If you want to modify the state of objects inside that tree then you will need to create a deep copy.

--

David Rutten

david@mcneel.com

Tirol, Austria

Thx, that solved the problem.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service