algorithmic modeling for Rhino
Some method overloads are not accessible in the typical pythonic way, and my lack of knowledge with C# is giving me some trouble here.
For example...
LayerTable.Add(string, color)
can't be easily accessed from Python. If one tries to use this overload in Python, you get an error saying that you've supplied the Add() method with too many arguments.
I've seen examples of accessing a C# method overload using the .Overload method of methods, but I've only seen examples of using this with single argument calls.
like this
ObjectTable.Select.Overloads[SCG.IEnumerable[System.Guid]](mySelection)
I can't figure out how to use the .Overload method of C# methods to grab overloads that take multiple arguments, and my attempts are getting some very strange results.
layerindex = doc.Layers.Add.Overloads[System.String](layername, layercolor)
Will give me the error:
Add() takes at least 2147483647 arguments (2 given)
Someone who knows C# might be able to tell me how to better use the .Overloads method. I assume all that I need to do is feed it an array of types, but I'm not all that sure how to build a C# Array of C# Types using IronPython. How would you build an array of types in C#?
Tags:
Tried this:
type_tuple = (System.String, System.Drawing.Color)based on the advice here:
doc.Layers.Add.Overloads[type_tuple](layername, layercolor)
explicitly specify which overload by accessing the .Overloads member of methods and indexing with a type, or tuple of typesbut I get the same weird error:
Runtime error (ArgumentTypeException): Add() takes at least 2147483647 arguments (2 given)
Sweet side note:
if you want to format code in this forum, just switch to the 'HTML' input and wrap your code with <pre></pre> tags. If only they would add syntax highlighting.
Also, this does not work, and gives the same error:
type_array = System.Array[System.Type]((System.String, System.Drawing.Color))Maybe there's a bug?
layerindex = doc.Layers.Add.Overloads[type_array](layername, layercolor)
RESOLVED
Apparently, the problem did not stem from the Add method nor the way I was calling Overloads.
it was because I was using a RhinoDoc-like object that wasn't fully formed.
For others who encounter this, here is what happened and how to solve it.
If I create a new File3dm like this
mydoc = Rhino.FileIO.File3dm()
... then I need to do this before I start editing the Layer tables and stuff
mydoc.Polish()
Now I'm good to go
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by