Changing ObjectPrintWidth of Object with 'AttributedGeometry'

I am trying to change the object print width of a Line/LineCurve object. My program creates the line segment, and then attempts to change the object’s print width through the suggested commands in this post: How to change display line width?

I have adapted it in the following way in my code:

def LineSeg(self, text, weight, lineX, lineY, lineZ, line_set):
            block = []
    
            for i in range(len(lineX)):

                # Draws line segment
                line = rs.AddLine((lineX[i][0], lineY[i][0], lineZ[i][0]), (lineX[i][1], lineY[i][1], lineZ[i][1]))
                pws = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject
                
                # Changes line width if corresponding element with same index in 'weight' list is greater than 0.0
                if weight[i] > 0.0:
                    #rs.ObjectPrintWidth(line, weight[i])
                    rh_obj = rs.coercerhinoobject(line, True, True)
                    rh_obj.Attributes.PlotWeightSource = pws
                    rh_obj.Attributes.PlotWeight = weight[i]
                    print (rh_obj)
                    rh_obj.CommitChanges()

                # Collects GUIDs of line segments
                block.append(line)
                
            scriptcontext.doc.Views.Redraw()
            return block 

I have also tried using the rs.ObjectPrintWidth command, but it returns the same error (pictured below)

How would I need to change the handling of the ‘line’ variable or its type, so that I can change the object print width? Is it possible to also change the object’s color through this method?

@Bianchi,

since you’re adding the line object to the document, you may want to set the attributes in that same moment like shown below:

import Rhino
import scriptcontext

def DoSomething():
    # line points
    p0 = Rhino.Geometry.Point3d(0,0,0)
    p1 = Rhino.Geometry.Point3d(5,5,0)
    # line geometry
    line = Rhino.Geometry.Line(p0, p1)
    # setup object attributes
    attr = Rhino.DocObjects.ObjectAttributes()
    pws = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject
    attr.PlotWeightSource = pws
    attr.PlotWeight = 2.0
    # add object with attributes to doc
    id = scriptcontext.doc.Objects.AddLine(line, attr)
    
DoSomething()

c.

Thanks for the suggestion, I’ll play around with it and see if it gives me a more efficient result than my current one. I spent some time figuring this out yesterday and came up with the following solution:

                line = rs.AddLine((lineX[i][0], lineY[i][0], lineZ[i][0]), (lineX[i][1], lineY[i][1], lineZ[i][1]))
                sc.doc = Rhino.RhinoDoc.ActiveDoc

                # Changes line width if any input
                if weight[i] > 0.0:
                    pws = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject
                    rh_obj = rs.coercerhinoobject(line, True, True)
                    rh_obj.Attributes.PlotWeightSource = pws
                    rh_obj.Attributes.PlotWeight = weight[i] * 2.0

                    rh_obj.CommitChanges()
                scriptcontext.doc.Views.Redraw()