Grasshopper

algorithmic modeling for Rhino

Good morning everybody
i want too use c++ in GH because a measurment sensor provides only a c++ sdk.

so i set up a c++ cli project as a small exampel.
i'm very new in using Rhino and GH, so now i have serveral questions:
the first thing is in c++ i have to implement more methods than in my c# test project.

they are:

int MyGhComponent::MasterParameterIndex::get()
{
return 0;
}
void MyGhComponent::MasterParameterIndex::set(int index)
{

}
bool MyGhComponent::IsValidMasterParameterIndex::get()
{
return 1;
}

i found no hint for the implementation of that interfaces. could someone tell me that is correct ?
OK, it works, but is it well writen ? What is the MasterParameterIndex?

the second "bigger" problem is, i want to have an output of an pointlist.
X y Z
1.2 1.3 1.1
2.1 5.2 9.2
...

my first approch was to use a

void MyGhComponent::RegisterOutputParams(GH_Component::GH_OutputParamManager^ pManager)
{
pManager->Register_PointParam("Coordinate", "XYZ", "Node-Coordinate");
}

and

void MyGhComponent::SolveInstance(IGH_DataAccess^ DA)
{
Collections::Generic::List<GH_IO::Types::GH_Point3D>^ pnt = gcnew Collections::Generic::List<GH_IO::Types::GH_Point3D>();
for (int i = 0; i < 10; i++)
{
GH_IO::Types::GH_Point3D^ point = gcnew GH_IO::Types::GH_Point3D(i, i, i);
pnt->Add(i);
}
DA->SetDataList(3, pnt);
}

but this exampel doesn't work...
i wirte a small workaround and use the following

pManager->Register_DoubleParam("X-Koordinate", "X", "X");
pManager->Register_DoubleParam("Y-Koordinate", "Y", "Y");
pManager->Register_DoubleParam("Z-Koordinate", "Z", "Z");

Collections::Generic::List<double>^ pntx= gcnew Collections::Generic::List<double>();
Collections::Generic::List<double>^ pnty= gcnew Collections::Generic::List<double>();
Collections::Generic::List<double>^ pntz= gcnew Collections::Generic::List<double>();

... add .. ect.

this workaround do the job, but i want a better soulution. and i know somewhere out there sould be a better solution.
i want to use 3D Points directly in GH without list conversation.

so somebody a familiar with c++ / cli ? and could give me some tipps or a soulution ?

the first thing is: what is the right RegisterOutputParams ?

and witch data type is the right ?
Point3d doesn't work. so i try GH_IO::Types::GH_Point3D and Rhino::Geometry::Point3d ...

br
Friedrich

Views: 373

Replies to This Discussion

Rhino::Geometry::Point3d is the correct one.

Incidentally, we really really don't recommend using C++/CLI. We used it for our previous .NET SDK and it was a nightmare. Instead we recommend creating a C++ and a C# project, and pinvoking from one to the other. Heck, you might even be able to pinvoke directly into the existing sensor API... If you want to know more about this solution you can ask on our discourse forum, where all the SDK programmers hang out.

I don't really speak C++, and I certainly don't speak C++/CLI, so getting help will be arduous if you go down this route. 

You really shouldn't have to implement MasterParameterIndex and IsValidMasterParameterIndex. These methods are implemented in the GH_Component abstract base class. If you're implementing IGH_Component from scratch, I highly recommend reconsidering and instead deriving from GH_Component. It does most of the difficult stuff for you.

Also these methods are obsolete:

pManager->Register_DoubleParam("X-Koordinate", "X", "X");
pManager->Register_DoubleParam("Y-Koordinate", "Y", "Y");
pManager->Register_DoubleParam("Z-Koordinate", "Z", "Z");

the methods you should be using are in the form:

pManager->AddXXXXParameter();

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