New linetype

Is it not possible to create new “linetype” using python?

Hi,
This seems to work … found by trial and error! (and a bit of inspect.getsource) and with this webpage
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_Linetype.htm

import Rhino
import scriptcontext as sc

l = Rhino.DocObjects.Linetype()
l.Default()
l.Name = "0904"
sc.doc.Linetypes.Add(l)

Thanks, @Dancergraham

that was what I needed :+1:

how can I insert patterns?

:slight_smile: It should be possible to add solid or gap segments with the AppendSegment method, e.g:

l.AppendSegment(1,True)
l.AppendSegment(1,False)

But although this code works, and I see the pattern when I run the _SetLinetype command in Rhino, I cant seem to apply that pattern visually to my line… I must be missing something :frowning:

great @Dancergraham works

I’m trying to modify existing segments or delete linetype
I can not make it, for me it is difficult to program in this language

the syntax examples are missing . . . .

Yes it’s a bit obscure - sometimes @dale adds developer samples where there is a need…?

l.RemoveSegment(0)

not by error, but it doesn’t work :persevere:

I guess you’re missing CommitChanges :

import Rhino
#adding a lineType to document
lineTypeName = "myLineType"
lineType = Rhino.DocObjects.Linetype()
lineType.Default()
lineType.Name = lineTypeName
Rhino.RhinoDoc.ActiveDoc.Linetypes.Add(lineType)
#editing a lineType by name
lineType = Rhino.RhinoDoc.ActiveDoc.Linetypes.FindName(lineTypeName)
lineType.AppendSegment(2.0, False)
lineType.AppendSegment(3.0, True)
lineType.AppendSegment(4.0, False)
lineType.RemoveSegment(0)
lineType.CommitChanges()

LineType.py (472 Bytes)

3 Likes

Thanks ! Doesnt work for me - maybe a Rhino 5 thing

Message: ‘LinetypeTable’ object has no attribute ‘FindName’

Hopefully this works OK for @0904

thaks @Mahdiyar for script

I apologize, use Rhino5
it doesn’t work for me
returns error to line 9

with version 5
can you delete a line?

import Rhino
#adding a lineType to document
lineTypeName = "myLineType"
lineType = Rhino.DocObjects.Linetype()
lineType.Default()
lineType.Name = lineTypeName
Rhino.RhinoDoc.ActiveDoc.Linetypes.Add(lineType)
#editing a lineType by name
lineTypeIndex = Rhino.RhinoDoc.ActiveDoc.Linetypes.Find(lineTypeName, True)
lineType = Rhino.RhinoDoc.ActiveDoc.Linetypes[lineTypeIndex]
lineType.AppendSegment(2.0, False)
lineType.AppendSegment(3.0, True)
lineType.AppendSegment(4.0, False)
lineType.CommitChanges()

LineType (Rhino5).py (514 Bytes)

2 Likes

now works thanks :+1:

but how could I delete a line?
or change segment length?

SetSegment

RemoveSegment

with SetSegment I succeeded :+1:

RemoveSegment delete all line?

lineType.AppendSegment(1.0, False)
lineType.AppendSegment(5.0, True)
lineType.AppendSegment(6.0, False)
lineType.RemoveSegment(0)
lineType.CommitChanges()
return:
5.0, 6.0

I’m not sure if I exactly got what you want, but for removing a linetype completely:

import Rhino
#removing a lineType by name
lineTypeIndex = Rhino.RhinoDoc.ActiveDoc.Linetypes.Find("Dashed", True)
lineType = Rhino.RhinoDoc.ActiveDoc.Linetypes[lineTypeIndex]
Rhino.RhinoDoc.ActiveDoc.Linetypes.Delete(lineType)

Removing linetype.py (230 Bytes)

1 Like

OK thanks @Mahdiyar now work :+1:

Rhino.RhinoDoc.ActiveDoc.Linetypes.Delete(0, True)

like the other example I had to put “True”
and then replace “Name” to “Index”

thanks @Dancergraham for first answer

strange:

property document “typeline” does not accept the first segment value as false