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.
Goal
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.
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
doc.Views.ActiveView.Redraw()
# 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
obj.CommitChanges()
doc.Views.ActiveView.Redraw()