Problem with not initiated linetypes

Hi there,

I have a problem with assigning one of the default linetypes to objects via either command or script - by default, apart from the "Continuous: linetype, a few more, inclding “Dots” are available. The problem is, I cannot assign “Dots” linetype unless it is somehow initiated first.

To explain: in a new empty file If I draw a line, select it and try:

Linetype name <By Layer>: Dots

I get this message:
Linetype not found

Same if I try to check via Script:
Rhino.Print Rhino.IsLinetype("Dots")
it returns False

As soon as I open Options dialog and at least look at linetypes in the file (“Dots” being there) or assign Dots linetype “by hand” to any geometry in the file, all of the above works fine, but until this is manually initiated, the command or scripts to assign this linetype do not work.

I need to be able to assign non-Continuous linetype via script (for example “Dots”) regardless if the user initiated it in the file or opened the Linetypes dialog.

Is there a way to “force” rhino to preload a particular linetype or all default linetypes in an empty file?



import Rhino
import scriptcontext
def SetLinetype():
  filter = Rhino.DocObjects.ObjectType.Curve
  rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects('Select curves', False, filter)
  if rc != Rhino.Commands.Result.Success: return rc
  if not objrefs: return Rhino.Commands.Result.Failure
  name = ''
  rc, name = Rhino.Input.RhinoGet.GetString('Linetype name', False, name)
  if rc != Rhino.Commands.Result.Success: return rc
  index = scriptcontext.doc.Linetypes.Find(name)
  if index == -1: return Rhino.Commands.Result.Failure
  for objref in objrefs:
    obj = objref.Object()
    obj.Attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromObject
    obj.Attributes.LinetypeIndex = index
  return Rhino.Commands.Result.Success
if __name__=="__main__":
  SetLinetype() (918 Bytes)

1 Like

Hi @Mahdiyar ,

thank you! - this works as expected via Python/RhinoCommon. And in fact even simpler way via RhinoScriptsyntax:

import rhinoscriptsyntax as rs
for objref in o:

The same code however using RhinoScript does not work (until the Linetypes are initiated in the file):

o = Rhino.SelectedObjects()(0)
Call Rhino.ObjectLinetypeSource(o, 1)
Call Rhino.ObjectLinetype(o, "Dots")

Which tells me RhinoScript and Rhino Commands are missing something that the Python code does automatically to load the default linetypes.
@dale - would you know why RhinoScripted way does not work and RhinoScriptSyntax of the same works OK, and any advice how to make it work via RhinoScript or by command macro (per my original post here, assigning Linetypes doesn’t work unless they were initiated in the file) ?



I can force this with RhinoScript by running a Python code snipped from within - then all works as expected:

Option Explicit

Call ForcePreloadLineTypes()

Sub ForcePreloadLineTypes()
	If Not Rhino.IsLinetype("Dots") Then
		Rhino.EnableRedraw False
		Dim s : s = ""
		s = s & "import rhinoscriptsyntax as rs" & vbCrLf
		s = s & "o = rs.AddCircle([0, 0, 0], 1)" & vbCrLf
		s = s & "rs.ObjectLinetypeSource(o, 1)" & vbCrLf
		s = s & "rs.ObjectLinetype(o, ""Dots"")" & vbCrLf
		s = s & "rs.DeleteObject(o)" & vbCrLf
		Call Rhino.Command("_-RunPythonScript (" & s & ")", False)
		Rhino.EnableRedraw True
	End If
End Sub