Grasshopper

algorithmic modeling for Rhino

Hi,

 

Is it possible to turn the previsualization from the components on and off with a script?

 

I was trying to make an animation from a slider that affected the visualization of different GH geometry?

 

Thanks!

Views: 2914

Replies to This Discussion

Hi Miguel,

 

I think so. You want to write a VB/C# script component that sets the Preview flags of other components right? How do you tell the script which components?

 

All objects on the canvas that draw preview geometry implement the IGH_PreviewObject interface. So all you have to do is see whether an object implements this interface, cast it to that interface, then call the Hidden property. For example:

 

Dim someObject As Object = GetComponentOrParameterOrWhateverFromSomewhere()

If (TypeOf someObject Is IGH_PreviewObject) Then

  Dim prvObject As IGH_PreviewObject = DirectCast(someObject, IGH_PreviewObject)

  prvObject.Hidden = True

End If

 

Does that do what you need/make sense?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Sure, David, exactly what I needed.

 

As it is not possible to tell the script which component, I understand I will have to pass the Geometry of each component into the script like I see in your code.

 

Thanks!

 

 

You can actually, you could pass in nicknames and as long as you've named your components in a special way you can figure it out. Or you could use a nickname convention. For example, assume all objects you want to control have a nickname ending in "?", then all you need to do:

 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

That´s great!

I hadn´t noticed that. And that´s exactly what I was looking for.

Many thanks :-)

Hi David,

 

I was trying to translate the code you posted to C# because I wanted to add it to a C# script and, as there´s no equivalent to vb´s DirectCast in C#, I didn´t manage to change the object preview.

 

I´m stuck in:


If (TypeOf obj Is IGH_PreviewObject) Then
          DirectCast (obj, IGH_PreviewObject).Hidden = Not Enable
End If

 

Could you please give me a hand?

Thanks!

Casting in C# requires you prefix the object with the typename in parenthesis:

 

IGH_PreviewObject prvObj = (IGH_PreviewObject)obj;

 

Or you could use the as keyword and do both the type test and cast in one line like:

 

IGH_PreviewObject prvObj = obj as IGH_PreviewObject;

if (prvObj != null) { prvObj.Hidden = !Enable; }

 

this second approach is similar to the VB TryCast statement.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks a lot, David. You were very helpful!

 

Just one more thing:

trying to make this work, I found

Rhino.DocObjects.ObjectMode

Does that function sets the preview mode in Rhino of the objects in Grasshopper? And, in that case, could you could select which objects to turn hidden or it sets the preview mode for all the objects?

Nope, this is located inside RhinoCommon and therefore cannot have anything to do with Grasshopper. 

 

Also, it's not a function. ObjectMode is an enumeration, meaning there probably exist functions and/or properties that require you to specify one of the constants inside of it.

 

The enumeration pertains only to objects inside a Rhino document.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Ok, I understand. Thanks for your explanation.

 

Cheers! :-)

You can also see some more syntax and comments on casting in C# here:

http://www.grasshopper3d.com/forum/topics/gettype-syntax

 

- Giulio
_____________

giulio@mcneel.com
McNeel Europe, Barcelona

thanks for the link, Giulio. very useful!

Hey David,

 

How did you get line 83 to be "......Enable as Object......."?

 

thanks.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service