Assign Custom Linetype to Curves with Python

Hello,
Is there a way I can assign a custom/default Linetype to a Curve, both created with RhinoCommon inside ghpython?

Thanks

Hi,

There is rhinoscriptsyntax method you can probably use as guidance:

def ObjectLinetype(object_ids, linetype=None):
    """Returns of modifies the linetype of an object
    Parameters:
      object_ids ({guid, ...]): identifiers of object(s)
      linetype (str, optional): name of an existing linetype. If omitted, the current
        linetype is returned. If object_ids is a list of identifiers, this parameter
        is required
    Returns:
      str: If a linetype is not specified, the object's current linetype
      str: If linetype is specified, the object's previous linetype
      number: If object_ids is a list, the number of objects modified
    Example:
      import rhinoscriptsyntax as rs
      obj = rs.GetObject("Select object")
      if obj: rs.ObjectLinetype(obj, "Continuous")
    See Also:
      ObjectLinetypeSource
    """
    id = rhutil.coerceguid(object_ids, False)
    if id:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        oldindex = scriptcontext.doc.Linetypes.LinetypeIndexForObject(rhino_object)
        if linetype:
            newindex = scriptcontext.doc.Linetypes.Find(linetype)
            rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject
            rhino_object.Attributes.LinetypeIndex = newindex
            rhino_object.CommitChanges()
            scriptcontext.doc.Views.Redraw()
        return scriptcontext.doc.Linetypes[oldindex].Name

    newindex = scriptcontext.doc.Linetypes.Find(linetype)
    if newindex<0: raise Exception("%s does not exist in LineTypes table"%linetype)
    for id in object_ids:
        rhino_object = rhutil.coercerhinoobject(id, True, True)
        rhino_object.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject
        rhino_object.Attributes.LinetypeIndex = newindex
        rhino_object.CommitChanges()
    scriptcontext.doc.Views.Redraw()
    return len(object_ids)

Does that help?

1 Like

Hi @Willem, thank you for the reply, and it definitely did help! I had a rough version of it working and after referring this, was able to do it better. I was also trying to preview the Line with a Pipeline. My script’s flow is like this(not the actual code)
β€˜β€™β€™
doc = Rhino.RhinoDoc.ActiveDoc
typeId = doc .Linetypes.Find(SomeLinetype, True)
Pattern = doc .Linetypes[typeId].PatternString(True)
DisplayPipeline.DrawPatternedLine(SomeLine, SomeColor, Pattern, LineThickness)
β€˜β€™β€™
I get the Pattern from the PatternString method. I’m trying to use this value for the Pipeline, but suppose I get the Pattern as 5.0,5.0;but the pipeline needs the pattern in this format

β€˜β€™ Pattern of the line (like 0x00001111 for dotted line).’’ , from -
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_DisplayPipeline_DrawPatternedLine.htm

Do you have any thoughts on I can preview with the Linetype I select or convert the Pattern String?

Thank you for the help!

1 Like

I’m afraid not. My experience with the display pipeline is not sufficient.

1 Like