Grasshopper

algorithmic modeling for Rhino

 Hello,
I would like one of my input parameters to be optional, with nothing as a default but a brep list if connected. I see that I can specify a default value for string parameters  like "test" below. Is their something similiar for geometry. When the component is compiled I get a runtime warning "failed to collect data" unless I attach a Brep.

Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)

        pManager.Register_StringParam("Variant Name", "Variant", "Variant name, "test", GH_ParamAccess.item)
        pManager.Register_BRepParam("Geometry 2", "Geo2", "List of Breps", GH_ParamAccess.list)    

Views: 4050

Replies to This Discussion

After you've registered the parameter you can then change things about it by accessing it directly through the pManager. Something like this will work....

pManager.Register_StringParam("Variant Name", "Variant", "Variant name, "test", GH_ParamAccess.item)
pManager.Register_BRepParam("Geometry 2", "Geo2", "List of Breps", GH_ParamAccess.list)

'the Brep param is index 1
pManager(1).Optional = True
Thanks Damien, works perfectly.

Register_XXXXParam methods have been replaced by AddXXXXParameter in some recent version.

Making parameters optional is done with:

pManager(2).Optional = True

in case the third input has to be optional.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

You do this in RegisterInputParams() right?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

That is very strange. Which exact error do you get:

  • Parameter failed to collect data
  • Input parameter <nickname> failed to collect data
  • Floating parameter <nickname> failed to collect data
  • Parameter <nickname> of unknown type failed to collect data

Can you post a screenshot of the component with the error and your RegisterInputParams code?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Sorry Hans but I simply cannot repeat that.

I pasted your code into a blank component and it works as expected:

Public Class testcomponent
Inherits GH_Component
Public Sub New()
MyBase.New("Bla", "Blah", "yada yada", "cat", "sub")
End Sub
Public Overrides ReadOnly Property ComponentGuid As System.Guid
Get
Return Guid.NewGuid
End Get
End Property
Protected Overrides Sub RegisterInputParams(pManager As Kernel.GH_Component.GH_InputParamManager)
pManager.AddBooleanParameter("Boolean", "B", "Turn the component on or off", GH_ParamAccess.item)
pManager.AddTextParameter("String", "N", "New Parameters", GH_ParamAccess.item)
pManager.AddTextParameter("String", "I", "Input file path", GH_ParamAccess.item)
pManager.AddTextParameter("String", "L", "Local copy path", GH_ParamAccess.item)
pManager.AddTextParameter("String", "U", "User Name", GH_ParamAccess.item)
pManager(2).Optional = True 'this doesn't work
pManager(3).Optional = True
End Sub
Protected Overrides Sub RegisterOutputParams(pManager As Kernel.GH_Component.GH_OutputParamManager)

End Sub
Protected Overrides Sub SolveInstance(DA As Kernel.IGH_DataAccess)

End Sub
End Class

Could it perhaps be that the component you're writing is not the same one that GH is loading? It's the only idea I have left at this point.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Just in case. For C# this is 

pManager[2].Optional = true;

Posted in 2020

Very late, but maybe it helps somebody;

To make it work in C# you need to write

pManager[1].Optional = true;

Important is to use square brackets instead of parenthesis around the number!

Good luck!

Roman

Thanks Roman, 

Better late than never ;)

Thanks!

This saved my life... Two fixed from the above posted fix.

-Use square brackets in C#

-And use lowercase in true

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