Grasshopper

algorithmic modeling for Rhino

I'm planning to learn one of these two languages.

Which one of them has a better performance?

Views: 905

Replies to This Discussion

Hi Ian,

this is known to be a classic question on .Net forums. Here my 2 cents.
I believe the biggest difference in performance is going to come from the algorithms that are chosen and the way code is written. E.g., quicksort will be faster than insertion sort for large random sets. Also - most of the times literature suggests that code should be comprehensible and maintainable rather than over-optimized. C# and Vb.Net behave similarly on these grounds.

From a purely technical point of view, C# can be somewhat faster in tight loops because of one feature Vb.Net is missing: unsafe code. This is what makes C# similar to its inspiring languages C/C++ and should be employed when there is the certainty that other safer methods have already been exploited. But it works and it is known to be fast in specific cases.

http://msdn.microsoft.com/en-us/library/t2yzs44b%28VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/aa288474%28VS.71%29.aspx
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=351

The C# scripting component in Grasshopper does not allow to write unsafe code ("Unsafe code may only appear if compiling with /unsafe"), but you will be able to load add-ons that make use of it, in case the need will appear in the future.

Another thing is that you can turn on and off overflow checking in expressions and blocks in C#.

- Giulio
______________
giulio@mcneel.com
McNeel Europe, Barcelona
Thanks for the detailed help. It's greatly appreciated. I'm new to programming. All my programming experience is some MEL which is not stricly a programming language. I can just leave it here and get back later after I get through the fundamental stuff.

I'm gonna take up C#, and python. cuz python is supported by a lot 3D packages, such as Modo Maya Houdini... and python rhino is cross platform. I think python is gonna replace rhinoScript and MEL.
Noob question:
I'm not starting a new thread cuz it's a noob question.
I'm learning C# now, by writing some simple scripts in GH, and some console stuff.
Everything's fine until today, I encountered a problem when I tried to batch name something.
for example, I want to declare 10 points, which names are i1, i2, ... , i10.
in MEL, I can do something like:
int $n=1;
for(......){
string $p = "i"+$n;
locator -n $p;
}

or

locator -n ("i"+$n);

And, I can access their attr by:
float $xxx = `getAttr ($P+".x") `;

BUT, in C#, a OOP, everything is an object.
I'm confused.....how can I do similar thing in C#?
need help........
Hi Ian,

here a code sample in RhinoCommon, C#. Note that, normally, Grasshopper is not referencing the document, therefore it can save the user a lot of undos/redoes that otherwise would be used. By modifying the document in the first part of this script in the CommitChanges(), we are actually making changes (taking some undos away) every time the solution runs. This would be true in any normal scripting environment. Anyways, just a name change of a point isn't using that much memory.

//Return the table with all objects in the document
Rhino.Collections.ObjectTable table = RhinoDoc.ActiveDoc.Objects;

for(int i = 0; i < guids.Count; i++) //Loop through the Guids
{
Rhino.DocObjects.RhinoObject rho = table.Find(guids[i]);
rho.Attributes.Name = "Hello " + i.ToString(); //Sets the name
rho.CommitChanges();
}

//-------------------------------------------------------------

Rhino.DocObjects.ObjectEnumeratorSettings enumerator
= new Rhino.DocObjects.ObjectEnumeratorSettings();
enumerator.NameFilter = "Hello *";

//Setting here, for example, the lookup type (optional)
enumerator.ObjectTypeFilter =
Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve;

foreach(Rhino.DocObjects.RhinoObject obj in table.GetObjectList(enumerator))
{
Print(string.Format("Found an object with name: {0}", obj.Attributes.Name));
}
Attachments:

I know this is an old quesion, and my questions might have something to do with updates in Grasshopper etc.

I get an error message

            {0}
0. Error: The type or namespace name 'ObjectTable' does not exist in the namespace 'Rhino.Collections' (are you missing an assembly reference?) (line 72)

ObjectTable is the class that provides access to objects in a Rhino 3DM document. It is located in the Rhino.DocObjects.Tables namespace, not the Rhino.Collections namespace.

--

David Rutten

david@mcneel.com

Tirol, Austria

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