Rs.DocumentName() on unnamed document

The help says it should return None. In fact it returns an empty string…

import rhinoscriptsyntax as rs
filename=rs.DocumentName()
print "filename is of type: ", type(filename)
if filename==None:
    print "Filename is None"
elif filename=="":
    print "Filename is an empty string"
else:
    print "I have no idea"

So, which should it be returning? None or "" ?

–Mitch

Yes,Rs.DocumentName() return ""Rather than None

I know it does that, the question is whether it should and why…

From rhinoscriptsyntax :

def DocumentName():
    "Returns the name of the currently loaded Rhino document (3DM file)"
    return scriptcontext.doc.Name

It looks like the function simply returns the property

RhinoDoc.Name

which is a string, then I guess it could not return None

Well, it could also be written this way:

def DocumentName():
    "Returns the name of the currently loaded Rhino document (3DM file)"
    if scriptcontext.doc.Name != "" :  return scriptcontext.doc.Name
    return

Of course, that’s whole extra line… :stuck_out_tongue_winking_eye: --Mitch

Hehe … or trying to be terse :

def DocumentName():
    "Returns the name of the currently loaded Rhino document (3DM file)"
    return scriptcontext.doc.Name or None

… This language is fun … :smile:

Yeah, really… :smile_cat: