MissingMemberException: 'Rhino.Geometry' object has no attribute 'Rhino'

hey so i try to run this code but get always an error, the code is below and i tried changing line 24 to something else like : radians = angle * math.pi / 180 or import math then radians = math.radians(angle) but none of it works, i also tried in both rhino 7 and 8 same error:

import Rhino
import rhinoscriptsyntax as rs

Define circle parameters

radius = 5.0 # meters
num_pillars = 10

Calculate angular spacing

angle_spacing = 360.0 / num_pillars

Function to create a pillar object at a specific location

def create_pillar(x, y, height):
pt = Rhino.Geometry.Point3d(x, y, 0.0)
circle = Rhino.Geometry.Circle(pt, radius)
cylinder = Rhino.Geometry.Cylinder(circle, height)
rs.AddObject(cylinder)

Loop to place pillars

for i in range(num_pillars):
# Calculate angle for current pillar position
angle = i * angle_spacing

# Convert angle to radians for trigonometric functions
radians = Rhino.Geometry.DegreesToRadians(angle)

# Calculate x and y coordinates based on radius and angle
x = radius * math.cos(radians)
y = radius * math.sin(radians)

# Create the pillar object
create_pillar(x, y, 2.0)  # Adjust height as needed

Print completion message

print(“Created”, num_pillars, “pillars in a circular arrangement.”)

This might help (not how I would go about this, just trying to patch your code).

import Rhino
import math

cylinders = []

# Define circle parameters

radius = 5.0 # meters
num_pillars = 10

# Calculate angular spacing

angle_spacing = 360.0 / num_pillars

# Function to create a pillar object at a specific location

def create_pillar(x, y, height):
    pt = Rhino.Geometry.Point3d(x, y, 0.0)
    circle = Rhino.Geometry.Circle(pt, radius)
    cylinder = Rhino.Geometry.Cylinder(circle, height)
    cylinders.Add(cylinder)

# Loop to place pillars

for i in range(num_pillars):
    # Calculate angle for current pillar position
    angle = i * angle_spacing

    # Convert angle to radians for trigonometric functions
    radians = Rhino.RhinoMath.ToRadians(angle)

    # Calculate x and y coordinates based on radius and angle
    x = radius * math.cos(radians)
    y = radius * math.sin(radians)

    # Create the pillar object
    create_pillar(x, y, 2.0)  # Adjust height as needed

a = cylinders

240317a_python_exception.gh (5.7 KB)

-Kevin

thanks but what was the problem, could you tell me what the problem and what the solution is

Put your code in a GhPython Script component:

There is no Rhino.Geometry.DegreesToRadians() function.

Replaced line 28 with:

Rhino.RhinoMath.ToRadians(angle)

Next error:

You are calling functions from the math module and you have not imported it.

Added line 3:

import math

Next error:

There is no rs.AddObject() function.

When working with GhPython, I prefer using RhinoCommon to RhinoScript.

Added an array definition on line 5:

cylinders = []

Changed line 22 to:

    cylinders.Add(cylinder)

Added line 40 to assign the cylinders array to script output a:

a = cylinders

No longer using rhinoscriptsyntax so don’t need to import it (deleted line 2).

Final working code:

Here’s the code in the 4 states shown above:

240318a_python_exception.gh (11.8 KB)

To post properly formatted code in the forum, insert this line before your code:
format_tag1

And insert this line after your code:
format_tag2

Also helpful if you upload a python or grasshopper file with your post.

-Kevin

1 Like