algorithmic modeling for Rhino
Dear All,
I want that as a base setting, when adding a new component to the canvas, Hidden is set to true. This is because I linked certain (time consuming) calculations to if the object is previewed in the view-port.
I added:
Me.Hidden = true
it to the NEW() method and to AddedToDocument(...)
This results in the problem that when opening a file, these components are automatically set to hidden,
What do I have to change?
thx Richard
Tags:
For a Python component you can add this line of code:
ghenv.Component.Hidden = True
Edit: Just realized that you had already figured this out. Will keep the reply for future reference.
Maybe I can rephrase this:
When I add a component to the document which of the two methods are called?
When I copy a component which of the two methods are called?
When I open a file which of the two methods are called?
It will be difficult to figure out whether a component was pasted, duplicated, merged from another document or whether it was created anew.
I'd recommend setting Hidden to False in the constructor and actually doing your own hidden (de)serialization:
Public Overrides Function Write(writer As GH_IO.Serialization.GH_IWriter) As Boolean
Dim rc As Boolean = MyBase.Write(writer)
writer.SetBoolean("CustomHidden", Hidden)
Return rc
End Function
Public Overrides Function Read(reader As GH_IO.Serialization.GH_IReader) As Boolean
Dim rc As Boolean = MyBase.Read(reader)
If (reader.ItemExists("CustomHidden")) Then
Hidden = reader.GetBoolean("CustomHidden")
End If
Return rc
End Function
--
David Rutten
david@mcneel.com
That Worked, a further question regarding this topic. I am using the PreviewChange Sub to detect if the preview has change or not:
Private Sub PreviewChange(ByVal sender As Object, ByVal e As GH_ObjectChangedEventArgs)
SetValue("hidden", Me.Hidden)
' If (e.Type = GH_ObjectEventType.Preview) Then
Me.ExpireSolution(True)
Me.ExpirePreview(True)
' End If
End Sub
which I controll thorugh: AddHandler Me.ObjectChanged, AddressOf PreviewChange
This works create if I change the preview through the object menu but when changing the preview status for multiple objects this doesn't force the component to recompute. How can I fix this?
That's my bug I'm afraid, the event doesn't get raised in that case. Little you can do to fix that.
On the other hand, you certainly don't want to start a new solution+redraw for every object that has its Hidden flag changed. If you switch the preview off for 50 components at once, it's going to take a long time and look very messy as they -one by one- change and update the viewports.
Am I right in thinking that the problem here is that if the preview is switched ON, you may have to compute additional data? If so, I think the best way is to detect this inside RenderViewportWires (override that method) and if the component/parameter is drawing itself and you don't have the required data, expire your component at that time.
You still need to figure out how to not expire+recompute all your components serially, so basically it means expiring ALL your components that are now in a bad state and then starting a single new solution for all of them.
--
David Rutten
david@mcneel.com
Will you fix the bug?
I didn't put the calculation of the data into the RenderViewportWires because, as far as I understood this would be called again when I change the viewport?
That's true, you should be doing as little as possible inside RenderViewportXXX() methods as those methods are called for every redraw of ever viewport.
I've fixed the bug but I don't know when the next release will go out.
--
David Rutten
david@mcneel.com
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by