Grasshopper

algorithmic modeling for Rhino

Custom Component Custom Preview stays when disabeling the component

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

Views: 2519

Replies to This Discussion

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

Attachments:

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:

  • Declare variables as late as possible. Don't put them all at the top, but put them on the line above the first line that uses them.
  • Give variables understandable names. "curves" is to be preferred to "crvs" or "c".
  • Don't nest conditional structures too deep. If there's no way around it, move inner loops into their own functions. A great way to reduce too much indentation is to write:
    If (Not x) Then Continue For
    Instead of
    If (x) Then 
      blahblahblah
    End If
  • Always check for null/Nothing if you get a reference type from some process.
  • Always check for empty arrays.
  • Use ReadOnly class level variables whenever possible.
  • Import few namespaces. Basically, don't import any unless you have to specifically refer to a namespace, say, more than 5 times.
  • Use #Regions to combine properties, constructors/destructors and other closely related methods.
  • Prefix class level variables with m_. This is in fact an archaic rule borrowed from Hungarian notation which is not recommended by the .NET style guide any more, but I like it.
  • Don't compare booleans to True or False in conditionals, i.e.
    If (x = True) Then
    If (x = False) Then
    should be
    If (x) Then
    If (Not x) Then
  • Put the conditional statements in If blocks in brackets.
  • Use AndAlso and OrElse instead of And and Or whenever possible.
  • Use String.Format() instead of &'s to combine strings.
  • Use constants like String.Empty and Vector3d.XAxis instead of "" and New Vector3d(1,0,0)
  • When comparing strings, use the .Equals() method with the proper StringComparison instead of =.

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

Attachments:

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

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service