Hi! My following script to split BREP faster worked in R7.
But when it open in R8, the line 21 furthest = max(distances) says ‘No method matches given arguments for Grasshopper1ScriptHelpers.Run’ Could you please give me some guidance?
The variable brep is a BREP and others is a list of BREP (I used correct type hints)
import rhinoscriptsyntax as rs
import ghpythonlib.parallel as ghpr
import ghpythonlib.components as ghcmp
import scriptcontext as sc
import Rhino
import clr
if not tolerance:
tolerance = sc.doc.ModelAbsoluteTolerance
def two_breps(actor):
outcome = ghcmp.SplitBrep(brep=brep, cutter=actor)
if len(outcome) <= 1:
return outcome
else:
_, actor_ctd = ghcmp.Volume(actor)
distances = []
for item in outcome:
_, centroid = ghcmp.Area(item)
distances.append(ghcmp.Distance(actor_ctd, centroid))
furthest = max(distances)
furthest_index = distances.index(furthest)
del outcome[furthest_index]
return outcome
a = ghpr.run(two_breps, others, flatten_results=True)
Thanks for your help Dale! Below is the script with internalized geometry: split_python.gh (37.4 KB)
The code (while working in R7) sadly did not increase speed at all.
The additional code was there because, they partially overcome the problem of invalid geometry from Split BREP Multiple (sometimes I get additional geometry with 0 area when it’s clear there should be only one)
Thanks a lot for your help Dale! I just got back to my R8 machine but, this file isn’t opening (it says C# script plugin is not installed–it’s similar to opening R8 GH file in R7), so, I get two white boxes I can’t click. If you have time, could you please share the code in text form?
The Python 3 method binder (the part that decides which dotnet method to call based on given arguments and their types) has a lot of issues similar to this. Over the past few weeks I have completely rewritten this method binder and it works much better now. This new binder is going to be in Rhino 8.5
I’m gonna test this specific example also to make sure it works.
Thanks for your reply Ehsan! I look forward to the new version!
For now, the (now branded ‘OLD’) R7 GH component was able to get by.
Also, I want to mention that (it seems) typing out the ‘(’ of a function no longer brings out documentation at the bottom like it used to. I can’t find documentation for what the function arguments (like grpythonlib.parallel.run) anywhere, so, coding got harder as a novice.
// Grasshopper Script Instance
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
public class Script_Instance : GH_ScriptInstance
{
/*
Members:
RhinoDoc RhinoDocument
GH_Document GrasshopperDocument
IGH_Component Component
int Iteration
Methods (Virtual & overridable):
Print(string text)
Print(string format, params object[] args)
Reflect(object obj)
Reflect(object obj, string method_name)
*/
private Brep[] SplitBrep(Brep brep, Brep cutter)
{
Brep[] rc = null;
if (null != brep && null != cutter)
rc = brep.Split(cutter, RhinoDocument.ModelAbsoluteTolerance);
return rc;
}
private void RunScript(Brep brep, IList<Brep> cutters, ref object a)
{
a = null;
if (null == brep)
return;
var bag = new ConcurrentBag<Brep>();
Parallel.ForEach(cutters, cutter =>
{
var pieces = SplitBrep(brep, cutter);
if (null != pieces)
{
foreach (var b in pieces)
bag.Add(b);
}
});
if (bag.Count > 0)
a = bag.ToArray();
}
}