algorithmic modeling for Rhino
Hi everyone,
I created a custom c# component and created a custom preview
like this
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
base.DrawViewportMeshes(args);
if (this.DisplayMeshCollection != null)
{
foreach (var collection in this.DisplayMeshCollection)
{
Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(this.MeshColors[collection.Item2]);
args.Display.DrawMeshShaded(collection.Item3, material);
}
}
}
If I turn the Preview off and on - it works as expected.
But if I disable the componente, from the preview on state, the meshes stay visible.
Any idea, how I can get this fixed?
Thanks.
- Martin
Tags:
Yea, thats confusing, isnt it ? I dunno how in C#, but I finally found yesterday (after few hours of searching) how to do it :
'Declare collection outside of solver instance (right before it) to have access to it over all your class
Dim listOfMyLines as new list(of line)
Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
'and now you need to CLEAR your list of lines
If (DA.Iteration = 0) Then
listOfMyLine.Clear()
End If
'here comes your components job
'job job job job
End sub
'here your components begins to draw
Public Overrides Sub DrawViewportWires(ByVal args As Grasshopper.Kernel.IGH_PreviewArgs)
MyBase.DrawViewportWires(args)
If (Hidden) Then Return
For i As Integer = 0 To listOfMyLines.Count - 1 Step 1
args.Display.DrawLine(listOfMyLines(i), Drawing.Color.MediumVioletRed, 2)
Next
End Sub
This is how i works with wires, but as far as i know meshes will do to (with DrawViewportMeshes). It is important to clear this list before, so old geometry will dissappear then.
Thank you Mateusz,
this sounds logical and I think it will work. My current problem though is the following line:
If (Hidden) Then Return
or in c#
if (Hidden) { return; }
For some reason, Hidden always stays "false" no matter if I enable or disable the component.
Anyone came across the same problem?
- Martin
Does your component have any geometry input or output ? if your output&inputs are non-previewable (boolean, string, double, integer etc.) then your component will be non-previewable. Iam not certain about it, but you may override its IsPreviewCapable property.
this is quotation from sdk, describing this property :
If a single parameter is PreviewCapable, so is the component. Override this property if you need special Preview flags.
public virtual bool IsPreviewCapable { get; }
Hi,
the component has integers as well polylines as a regular output.
In addition I filled the polylines with meshes (my custom preview)
Now: If I turn the preview on and off - Everything works fine. The debugger never reaches the "if (Hidden) { return; }" line.
If I have the Preview On and Disable the complete componente, the polylines from the output are not visible anymore, but the meshes are still there.
Maybe I missunderstand the "Hidden" Property. My understanding is that it is "false" if the component is "enabled" and "true" if it is "not enabled". But this seems not to be the case.
- Martin
P.S. I'm working on 0.9.006 - Don't know if this is important
Hi Martin,
I have same issue, trying to find a way to turn off the preview display when component is disabled.
like
if (Disabled) {return};
Did you find a way to solve this ?
thx
Hi David,
I have decided to put a question in this section as the problem I have is quite similar to the one that Martin has.
In my custom component I am overriding DrawViewportWires property.
Also I have all the conditions fullfilled:
- Override the ClippingBox property;
- Override the IsPreviewCapable property;
- Assigning new list as well as assigning box = BoundingBox.Empty when DA.Iteration=0;
- Using box.Union(myobj) for every object.
However, despite those I still have following problem:
If I supply some geometry as input parametr and use it for some further actions (ex. get intersection) and later disconnect the input - then resultive geometry (intersection curves) is still visible, however output is empty.
If I am not overriding DrawViewportWires - then everything works fine and if the input is disconnected - then intersection curves are also gone.
Thanks in advance,
Dmitriy
Hi David,
Can you still have a look in topic above?
Any suggestions why it happens?
Thanks,
Dmitriy
Please post the actual code (or a minimum version of the code that shows the problem without doing anything else if you don't want to make your source public).
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I think the problem is that the input is disconnected but it's not an optional input. Grasshopper will not even call the SolveInstance method in this case which means you never erase your display caches.
The best place to erase your caches is inside the ClearData() method. Override it, call the base class and then clear your display caches.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I have already noticed that after the data is disconnected - SolveInstance has not been called.
Please find the code enclosed.
I have tried to act according to your action list but seems that smth I have missed up.
Can you have a look?
Thanks in advance!
Dmitriy
I made some functional changes to the file and override the ClearData() method. It's all untested.
I also made some syntactic changes that reflect my own personal programming mantras. You do not have to subscribe to the same set of rules of course, but things I like to do when programming are:
If (Not x) Then Continue ForInstead of
If (x) Then
blahblahblah
End If
If (x = True) Thenshould be
If (x = False) Then
If (x) Then
If (Not x) Then
It also seems like the algorithm you're using is pretty sensitive. I'm not exactly certain what your input is supposed to look like, but I think it can be made more robust.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Perfect!
Thanks David, works like a charm!
I think - I will print your checklist to have it in front of me - very useful guidance, that you will not find in the book!
Thanks a lot!
Dmitriy
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