Twisted box trough ghpython script

Hi. How can I get a twisted box into a python script and output it?

In the attached example I just try to pipe some twisted boxes through a ghpython component but can not get it to work.

The datatype seems to be missing in ghpython. What I am trying to do is to just use these two commands (SurfBox & BoxMorph) in a python script. The problem is that BoxMorph is not able to identify the Twisted box that SurfBox outputs just one line above.

How can one use Twisted boxes in a Ghpython script at all with that limitation?

twisted.gh (24.4 KB)

Twisted Boxes don’t work in those editors, the input always interprets them as Point3dList. From my finding, Twisted Boxes don’t work well because they are not a part of the api for rhino common or Gh, the script editors only know that they are Point3dList. They are defined directly in Grasshoppers Transform.Gha. Only way I was able to use them in a stable way was to reflect them in Visual Studio and compile C#. This was a large basis of Pufferfish (See the Twisted Box tab).

In a script editor you can get the twisted boxes by defining the point 3dList as TwistedBox, First you will have to reference the Transform.gha assembly from Grasshopper. Then do the this -

var tBox = new GH_TwistedBox((Point3dList) TB);

That is written in C#, I don’t know the Python equivalent. The other issue that I could not overcome in the script editors is that the outputs always seem to make a twisted box of the input twisted box’s bounding box. That is why I went to Visual Studio instead where I can explicitly say what type of thing should output.

Lastly, these two methods ( SurfBox & BoxMorph) do not exist in rhinocommon, Gh Api, or python script. They are also in the Transform.Gha, or I guess you could use node-in-code.

Thank you Michael for that superfast reply! Actually I was trying the very same thing with your (amazing) Pufferfish addon. I was not able to get any Pufferfish TB output to the BoxMorph component within a script.

I dont nessecarily need to get the TB out or in the Python component. All I want is to get a Twisted Box that is created on one line of the script into the input of a boxMorph component on the next line of the script. Is there any way of getting this rather simple plan to work?

Do you know any alternative to the Boxmorph component that does not need a twisted box as input?

I was not able to get any Pufferfish TB output to the BoxMorph component within a script.

Well yes that makes sense, they are the same twisted box Grasshopper makes :smiley:

I don’t know any alternative but as long as you reference the Transform.Gha (or Xform.Gha in R6 I think) as an assembly in the python component, you should then be able create Twisted Boxes in the script, or input Twisted Boxes by converting Point3dLIst to Twisted Box like I showed in the previous comment.

Thank you! That sounds promising. For know I have found the XformComponents.gha component and referenced it via clr. The last thing to figure out is the proper name to import. I tried GH_TwistedBox but no success. Is there a way to see the modules of the reference somehow?

Hi Info
You need to import the namespace.like this


my gh file:
TwistedBox.gh (14.6 KB)

2 Likes

That is it! Thank you guys. It works like a charm now.

Hi Naruto,

I wonder, :thinking:
Why do you clr importing .gha instead of using virtual components?
Is it somehow benefitial doing it this way?

Because Ghpython calls “Twisted Box component” will report an error,Like Michael Pryor said “because they are not a part of the api for rhino common or Gh, the script editors only know that they are Point3dList. They are defined directly in Grasshoppers Transform.Gha.”

1 Like