Need help with my python component

hi,

why doesn’t the circle made with my pythoncomponent show the same behavior like the circle made with the circle module.

I am planing to make different parametric closed curves working as profiles and want to orient them on a circle using perpframes, but that will make no sense when all curves stay in the xy-plane not like the circle.

Hi @schoenherr-schmuck,

Try this:

test_circle.gh (5.6 KB)

– Dale

not better

any other ideas?

What what am I looking at? Perhaps you need to provide a different plane as input?

– Dale

seems to work fine here…

the last one worked now.

many thx

hi again,

I made the pythonmodule like Gijs posted and it works fine now.

Than I transformed a curve-module that I allready made in the same way but now I have a new problem:

the same curve module worked before changing the name of the variable from 0 to x

I don’t understand why this will not work.

The error is quite clear, you’re feeding it a plane but I think you want to feed it an x-coordinate.

If you want it to feed the x coordinate of the plane use x.OriginX

See also Plane Structure

sorry for being stupid, but this scripting stuff is so new to me as I was only used to work with the Rhinofunction and never typed any kind of script. But now,… as I would like to create my own customized GH-Modules I am forced to work with python and rhino script since one week but the more I am trying to find out how it could work, the more I am getting confused.

I have read the GH Primer but most of it is just like a language that I don’t understand.

so I tried to learn by rebuilding tutorials from U-tube but that didn’t really help to really learn enough to make my own modules.

today I tried to construct a rectangle with a python-module and reached to create a simple rectangle with:
plane = x
a = rs.AddRectangle(plane, length, width)

which worked,… but when I tried to make the rectangle being constructed from the center with rs.AddRectangle_center i was doomed.

I wish there would be some Kind of manual that explains step by step how to construct rhino elements with python script as the help offered in the python module is way to short for me.

I understand that things are confusing in the beginning. Working your way through this in grasshopper makes it more difficult in a way.
I highly recommend going through this one as well if you haven’t yet:
https://wiki.mcneel.com/developer/python

Futhermore, while the rhinoscriptsyntax functions are handy, it also hides a lot of what’s happening in the functions. Most of the geometry stuff can be done better I think by using RhinoCommon directly especially if you are working inside grasshopper.

For example, making a rectangle using rhinoscriptsyntax : rs.AddRectangle(plane, width, height) will actually create a rectangle in RhinoCommon and then add it to your document. Rectangles in RhinoCommon can be found in the Geometry class and accessed this way:

myrectangle = Rhino.Geometry.Rectangle3d(plane, width, height)

now you’ve created a new rectangle ‘in memory’ that is not yet in the document. To add it to the document you have to import scriptcontext:

after that:
sc.doc.Objects.AddRectangle(myrectangle)

so the total script would look like this:

import Rhino
import scriptcontext as sc

width = 10
height = 20
plane = Rhino.Geometry.Plane.WorldXY

#creating a new rectangle 'in memory'
myrectangle = Rhino.Geometry.Rectangle3d(plane, width, height)

#add it to the Rhino document
sc.doc.Objects.AddRectangle(myrectangle)

#redraw the screen
sc.doc.Views.Redraw()

In grasshopper though you can just do it this way:

import Rhino

width = 10
height = 20
plane = Rhino.Geometry.Plane.WorldXY

#creating new rectangle in memory
myrectangle = Rhino.Geometry.Rectangle3d(plane, width, height)

#add rectangle to the gh doc
a = myrectangle

First off all I want to thank you again for your help and kindness.

Yes, I have tried to read the primer and also most of the tutorials which were referring to what I want to do in the moment, but I recognized that although I passed 13 years of school ( and that where not all the same classes) I am lost even at the first examples listed.

My problem is that by just showing a script that is working, I do not know what is exactly going on as in most cases they do not really explain what is doing what in the script lines. And so I do not really learn how to use the appropriate script for the geometry I need now.

This rectangle for ex is a good example as it makes a rectangle, but how do I get this rectangle being constructed from the center or from a specific point on a specific side.

To find out how this could be made, I looked what is rhino doing when I choose this variant in rhino and found that RHino is showing the command as

rectangle_center

But when I try to use this in my python module it will not work and while searching the internet, I did not really found what I needed to make it work.

One

your best help is this case to look at the RhinoCommon API and see which methods are available. Because Rhino can do certain things with commands and not everything is exposed to RhinoCommon.
Rhino Python is actually a way to communicate with Rhino through RhinoCommon, so you are bound to the limitations of RhinoCommon.

That being said there is a lot possible, and I’d say more than you can currently imagine.

In case of your rectangle from center, it’s a matter of a bit of math to make that work. For example:

from Rhino.Geometry import *

width = 10
height = 20
plane = Plane.WorldXY

#move plane origin
plane.OriginX = -width/2
plane.OriginY = -height/2

#creating new rectangle in memory
myrectangle = Rectangle3d(plane, width, height)

#add rectangle to the gh doc
a = myrectangle

Hello Gijs,

I followed your advice but I am stumbling by developping in the way I want to have it.

My aim is it to get a python-Module for a rectangle jewel-setting that should look like this:

and by adjusting the dimensions of the 3 rectangles also being transformed to this

But what would be a good strategy to build this in python/gh?

i thought about defining the points of the rectangles and than making lines and 3point arcs, but I am not sure what would be the best way to get a good closed volume in the end.

Also I am struggling to find the appropriate commands for that. For example when I want to make a closed curve from 4 points or a loft of the three rectangles and than all other surfaces to get a closed volume where can I fiend the appropriate commands I need for python / gh?

rgeards
S