Grasshopper

algorithmic modeling for Rhino

Is there a way to extract individual coordinate elements from the Curve Start/End Points component?

Would there be a way or process or component that lets me extract the individual elements (i.e. float numbers) from the output of the Curve Start/End Points component? I'm developing a sort of component for Grasshopper that needs the individual (x, y, z) coordinates of the start and end points of each line segment/curve. It would be good to know if this is feasible with Python and/or the GH scripting language.

Views: 5522

Replies to This Discussion

Yes, you can either use the [Deconstruct Point] component which splits a point into three numbers, or you can use a script and just access the .X, .Y or .Z properties of any point you input.

Would this only work on points, or would it work in general with point-like objects (i.e. starts and ends of line segments extracted using the Curve Start/End Component)?

Curve Ends component does output proper points, what do you mean by point like objects? 

For the component I am making, it would require the individual (x, y, z) coordinates of each point. So, for example, this is how I would initialize a point in the database of geometry I'm making:

point3D(x, y, z)

where x, y, and z are individual float numbers, not lists, i.e. (x, y, z) = (1.0, 0.0, 0.0)

Does using the .X, .Y, .Z properties of the points do this already, or is there another way to extract each individual number from the XYZ coordinates returned by Deconstruct Point?

I am building it using Python. The 'point3D' class I'm making here is from another library unrelated to the Rhino object command.

So far, I've tried inputting the coordinate lists themselves as input, and this seems to give me the result I want, i.e.:

def extract_lineSeg(start_x, start_y, start_z, end_x, end_y, end_z):

     v1 = vector3D(start_x, start_y, start_z)
     v2 = vector3D(end_x, end_y, end_z)
     lineSort = sort.register['rhino_shapes']
     lineSegments = lineSegment3D(lineSort, v1, v2)

     return lineSegments

start_x, start_y, start_z, end_x, end_y, and end_z are all obtained from the GH Component 'Deconstruct Point'. This is what my GH window looks like.

Thanks! I've adapted this to work for my package. On a side note, is there a way to extract the 'thickness'/line width of the line segment using Grasshopper as well? i.e. like extracting the X, Y, Z coordinates from the rhino object here. What function or attribute would I need to call?

I'm having some trouble with accessing ObjectAttributes, but what you've described is similar to what I aim to do. Right now, I'm handling per object, i.e. 

weight = obj.ObjectAttributes.PlotWeight

Where obj is an individual LineCurve object. What libraries do I have to import/what is the correct function to call to access the plot weight of a LineCurve Rhino Object? obj.Attributes.PlotWeight does not appear to work on my end, so I might be missing something. I've tried the following:

ObjectAttribute

ObjectAttributes

Attribute

So from what I've read up and could understand, to access the curves I specifically need, I'd need to look for them as they are included in a RhinoObject rather than accessing them as individual Line Curve objects? 

So, say that I could collect the GUIDs of the LineCurves. Would it be possible for me to search for them specifically in the RhinoObject and get the plot weights from there?

Yeahp, this works, but I need to set the type hint to GUID instead of 'No Type Hint'. Unfortunately, when I use this method with the type hint as GUID, I can find the weight of what were Line Curve objects when the type hint is set to 'No Type Hint', but I cannot use rs.coercecurve or rs.CurveStartPoint or PointAtStart to get the coordinates of the line segment object. What would be the best way to extract the line segment start and end coordinates if I'd be handling GUID objects instead of LineCurve objects?

Yeahp, this works. Just posting my final solution for anyone who's interested; the type hint is GUID, with list access:

def ghToCoords(self):
   # self.objs is a list of GUIDs pertaining to the objects in the Rhino Window
   for obj in self.objs:      rhObj = rhdoc.Objects.Find(obj) # finds the object in the Rhino data set using its GUID

      if type(rhObj.Geometry) == rg.LineCurve and self.lineSeg[0] == True:
         line = []
         pt = []
         weight = None

         # Extracts coordinates from underlying Rhino Object geometry
         line.append(self.Point3d_to_Pt3(rhObj.Geometry.PointAtStart)) 
         line.append(self.Point3d_to_Pt3(rhObj.Geometry.PointAtEnd))

         if self.lineSeg[1] == True:
            weight = rhObj.Attributes.PlotWeight # Extracts weight from Rhino Object

            line.append(weight)

            self.lines.append(line)

        if type(rhObj.Geometry) == rg.Point and self.point == True:
            point = rs.PointCoordinates(rhObj.Geometry)
            self.pts.append(rs.PointCoordinates(rhObj.Geometry))

    return [self.pts,self.lines]

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service