Grasshopper

algorithmic modeling for Rhino

Hello everyone,

I've been building user components with clusters, but I want to learn more on Python to make custom tools in my workflows. As a start, I'm trying to make a component to offset multiple curves consistently using Python.

Can anyone give me some help in making this component?

Below is my logic that I'm thinking, but I'm not sure whether it'll work or not.

Inputs: crv(curves), offsetDim(float)

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

#Get Centroid of Curves

cen = rg.AreaMassProperties.Centroid (crv)

#Get Coordinates of Centroid

coord_centroid = rs.PointCoordinates (cen)

#Offset Curves

offsetCrv = rs.OffsetCurve (crv, coord_centroid, offsetDim)

In the very beginning, Get Centroid of Curves, I get an error message.

"Runtime error (ArgumentTypeException): getset_descriptor is not callable"

I hope someone can help me on this...

Thank you.

Dongyeop

 

Views: 1047

Replies to This Discussion

'Centroid' isn't a static property or function, so you need to create an instance of the AreaMassProperties type before you can get a value from it.

Try using 'AreaMassProperties.Compute(crv)' to create an AreaMassProperties object for the curve and then get the Centroid property from the result.

I think your next problem will be that you can't mix RhinoCommon and RhinoScriptSyntax in the way you're trying to there.  Look up the RhinoCommon offset method and use that instead.

Hi Paul, thanks a lot for your reply.

Is this what you're suggesting? I'm still not clear how to get centroid points from closed curves.

AMP = Rhino.Geometry.AreaMassProperties.Compute(crv)

centroid = Rhino.Geometry.AreaMassProperties.Centroid(AMP)

I'm sorry if it doesn't make sense at all, but I hope you can let me know the answer. 

The first line is right (probably - I haven't tested!), the second should just be:

centroid = AMP.Centroid

This is because 'Compute' is a static function on the AreaMassProperties class which will create an actual instance of that class, 'AMP'.  'Centroid' is a (non-static) property of the class, the value of which will be specific to that particular instance and must be accessed through an object of that type, rather than through the type itself.  (This is perhaps no clearer for you, but this is all fairly basic Object Orientated Programming theory and I'm using the technical terms so you'll have some keywords to google!)

I had a chance to learn about Class, but I didn't know about the term, Static.

I'm getting my feet wet in textual programming and it's great for me to get help in this forum thanks to people like you. I hope I can help others in return after sometime later.

The code below does work as I wanted!

  

#Get Centroid of Curves
AMP = rg.AreaMassProperties.Compute (crv)
cen = AMP.Centroid


#Offset Curves
offsetCrv = rs.OffsetCurve (crv, cen, offsetDim)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service