Grasshopper

algorithmic modeling for Rhino

Dear, David...

I found how to make Custom parameter with C# which you replied before.

But It was not easy for me to convert it into VB.net.

Would you help me? please?

c# -------------------

public class PointIndexGHData : GH_Goo<PointIndexData>

{
  public override IGH_Goo Duplicate()
  {

    PointIndexGHData dup = new PointIndexGHData();
    dup.Value = Value;
    return dup;
  }


  public override bool IsValid
  {
    get { return Value.Index >= 0; }
  }

 public override string ToString()
  {
    return string.Format("{0} [{1}]", Value.Point, Value.Index);
  }

   public override string TypeDescription
  {
    get { return "Points and Integers, living in perfect harmony"; }
  }


  public override string TypeName
  {
    get { return "IndexPoint"; }
  }
}

VB.net ? ????

pulbic structure myob

   public num as integer

   public pt as point3d

end structure

Public Class myob     Inherits Grasshopper.Kernel.Types.GH_Goo(Of myob)

    Public Overrides Function Duplicate() As Grasshopper.Kernel.Types.IGH_Goo

????????

    End Function

    Public Overrides ReadOnly Property IsValid As Boolean

        Get

???????

        End Get

    End Property

    Public Overrides Function ToString() As String

???????

    End Function

    Public Overrides ReadOnly Property TypeDescription As String

        Get

???????

        End Get

    End Property

    Public Overrides ReadOnly Property TypeName As String

        Get

???????

        End Get

    End Property

End Class

Views: 841

Replies to This Discussion

LMGTFY

--

David Rutten

david@mcneel.com

Poprad, Slovakia

By the way - how reliable this translator is ? Will vb.net code run properly after converting it from c# ? (please, just don't paste another lmgtfy link).

For simple stuff is 100% reliable I think. VB and C# have a huge overlap so only if you use language specific features (such as the unsafe keyword or the Like operator) do you get an error.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I'm so pleased I'm not the only one to follow Micheal's lead :)

Thank you David,

I converted the C# code into VB.net

...

And..I found one more problem,

I couldn't find something I made(PointIndexData) in 'pManager'....

such as,,,

pManager.AddPointParameter("Point", "pt", "discriptions...", GH_ParamAccess.list)

 

Would you help me again? please?

 

pManager exposes methods for adding input and output parameters of standard types. Only the data types that ship with Grasshopper core are available here. If you've developed your own data type then you will also need to write a parameter for that type and then use the generic AddParameter() method.

For example the Twisted Box data type is not defined in Grasshopper core. It is only available within the Transform.GHA assembly. So when I need to use a twisted box parameter, I have to do something like this:

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
  Parameter_TwistedBox param_box = new Parameter_TwistedBox();
  pManager.AddParameter(param_box, "Twisted Box", "B", "Twisted box connecting all corners", GH_ParamAccess.item);
}

Is that what you're after?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Dear, David

I followed as you teach, but there are still errors.

.."can not cast~"

So, I added my vb code.

I can not fix it....

Would you write complete code for custom parameter? please!

Attachments:

Ok, let's have a close look at the actual error message:

It is indeed a casting error and no amount of Option Strict Off and CType will save you here. The function you're calling needs an IGH_Param. You're giving it ptidx which is a List(Of PointIndexGHData()).

These are not the same thing. An IGH_Param represents an actual parameter which may maintain its own datatree of PointIndexGHData, but the container is not the same as the contained.

You need to either use a Generic parameter and then try and cast your data in SolveInstance to PointIndexGHData, or you need to provide a dedicated parameter for your custom data type.

There is already a complete example in the SDK documentation for writing a simple parameter.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Public Class PointIndexGHData

    Inherits GH_Goo(Of PointIndexData)

Public Overrides Function Duplicate() As IGH_Goo

Dim dup As New PointIndexGHData()

        dup.Value = Value

        Return dup

    End Function

Public Overrides ReadOnly Property IsValid() As Boolean

        Get

            Return Value.index >= 0

        End Get    

End Property

Public Overrides Function ToString() As String

        Return String.Format("{0} [{1}]", Value.point, Value.index)    

End Function

Public Overrides ReadOnly Property TypeDescription() As String

        Get

            Return "Points and Integers, living in perfect harmony"    '=I may change I think...

        End Get    

End Property

Public Overrides ReadOnly Property TypeName() As String

        Get

            Return "IndexPoint"

        End Get    

End Property

End Class

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service