Adding attributes to a rhino3dm.Point3d

Using rhino3dm in python 3.7 I am trying to find a way to add attributes to a Point3d or find a work around since the point doesn’t have a way to add attribute from the rhino3dm.ObjectAttributes class.


  • add a point to specific layer, for example: model.Layers.AddLayer(‘low_stress’, (190, 255, 72, 255))

I have instantiate an ObjectAttributes Class with the hopes of placing all the attributes under this value:
low_stress_attr = rhino3dm.ObjectAttributes()

I am running through my point list to find specific points that have a stress load associated and based in the code below:

    for i in range(len(pts)):     
        if stress[i] < 50:
            pt = rhino3dm.Point3d(pts[i][0], pts[i][1], pts[i][2])
            new_pt = model.Objects.AddPoint(pt)

The problem

  • trying to add an attribute to the point so that its display color is a value or if I can take all the points in new_pt and add it to a specific layer that I can denote.

Any guidance would be helpful

see if these examples help

import System
from Rhino import *

# Create a new point with custom attrs.
doc = RhinoDoc.ActiveDoc;
attrs = DocObjects.ObjectAttributes()
attrs.LayerIndex = doc.Layers.FindName('Layer 01').Index # assuming you have a 'Layer 01'
attrs.ColorSource = DocObjects.ObjectColorSource.ColorFromObject
attrs.ObjectColor = System.Drawing.Color.Red
pt_id = doc.Objects.AddPoint(Geometry.Point3d(1.0, 2.0, 3.0), attrs) # note this overload, which takes object attrs in the second parameter

# Get the existing point and modify its attrs.
obj = doc.Objects.Find(pt_id) # we have this ID from above, otherwise you would need some other way of getting it
attrs2 = obj.Attributes
attrs2.ColorSource = DocObjects.ObjectColorSource.ColorFromLayer

This worked for me:

        Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
        gs.SetCommandPrompt("Name of curve: ");

        ObjectAttributes objAtt = new ObjectAttributes();
        objAtt.Name = gs.StringResult();

        doc.Objects.AddCurve(iso_curve, objAtt);

Awesome thanks, thats what I was looking for. The **import *** didn’t bring in the librarys so I used:

    from Rhino import RhinoDoc
    from Rhino import DocObjects
    from Rhino import Geometry

and it seemed to work fine in Python 3 with rhino.inside python using these packages:

    import rhinoinside

I also replaced doc = RhinoDoc.ActiveDoc; with:

doc = RhinoDoc.CreateHeadless("")

to instantiate a defult document

and to write the file I just used:


Thanks, it took a while but I got the result that I was looking for.

1 Like