Karamba python

Hi, I’m trying to use python to write cross-section optimization, and I find a ref, however, it is written in C#, I have some difficulties in converting it into python, Do you know is there a way to write resource path and crosc path in python?

resourcePath is simply the folder where you’ve installed Karamba plugin.
For example:

import System

resourcePath = R'C:\Program Files\Rhino 6\Plug-ins\Karamba3D'
materialPath = System.IO.Path.Combine(resourcePath, 'MaterialProperties.csv')

Hi, Thanks!
I already solve the filepath problem, but another problem comes out

the original grasshopper component is like following

Do you know what’s wrong?

Hi @Xiujin_Liu ,
It is very difficult to help you, because you are not sharing your entire code. The error appears at line 132, and I have no idea what happens in those first 120 lines.
I perfectly understand that you want to keep the code for yourself, but then there is a high chance that the provided answer to the question - may not be sufficient.

Just by looking at these 15 posted lines, I think the problem is with ReadCossSectionTable method.
Try replacing it with:

info, croSecTable = k3d.CroSec.ReadCrossSectionTable(crosecPath)
inCroSecs_L = croSecTable.crosecs
inCroSecs_readOnlyL = inCroSecs_L.AsReadOnly()

model = k3d.Algorithms.OptiCroSec( model, inCroSecs_readOnlyL, MaxDisp, MaxUtil, clr.Reference[str]() )

python.gh (25.1 KB)
Hi, sorry the solution didn’t work, I already attached the file, please kindly download it.
Thanks for your help again!

Thank you @Xiujin_Liu . It requires latest version of Rhino, which I do not have.
On which line does the error appear? What is the text of the error?

What happens when you replace the upper line:

info, croSecTable = k3d.CroSec.ReadCrossSectionTable(crosecPath)


croSecTable, info = k3d.CroSec.ReadCrossSectionTable(crosecPath)

Hi, when I replace it, the problem is like this.

I already put the python code in txt file, feel free to take it

python.txt (7.1 KB)

Thank you once again. The issue is with Rhino - Karamba requires the latest version of it. So I can open your python.gh file and its code, but I can’t reference the Karamba libraries.
I don’t understand the error. Maybe @Karam can help.

Thanks for help!

1 Like

Hello @Xiujin_Liu,
in the Python script line 130 should be

croSecTable, info = k3d.CroSec.ReadCrossSectionTable(crosecPath)

With this change in place the OptiCroSec-method throws an exception. Try to use non-default cross sections for the initial model and select the corresponding cross section family from the cross-section table.

– Clemens