Python get rhino name trouble

#1

I did this :

import rhinoscriptsyntax as rs

ghname = ghenv.LocalScope.ghdoc.Name
rhinoname = rs.DocumentName()
csvdate = “NC”
geodate = “NC”

perfect ! ghname = ghenv.LocalScope.ghdoc.Name get the .gh file nam !
but why did the rhinoname = rs.DocumentName() didn’t gave me the rhino document name but the grasshopper one… ?

I also need the creation date of some other file that are located and all named almost this way :
H:\0_ACAD\3_ABRA_BRANCHE\ACAD\A304_Branche_04\A304_ET_Branche_04.geo

any idea the python line I should wrote ?
I just don’t really know where to find a cool python library somewhere, if you can help to…

thanks everybody

(Chris Hanley) #2

when using rhinoscriptsyntax, within a ghpython component, you need to explicitly define the context, (scriptcontext), of where it should run. ie, if you run a rhinoscript function in grasshopper, it only knows to work in grasshopper…it doesn’t know anything about the active rhino document…unless you tell it to. This is a topic that we’ve seen come up a few times. It’s just part of learning the rules of operation.
In rhinoscriptsyntax, it would look something like this:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

if x:
    GHDocName = ghdoc.Name
    sc.doc = Rhino.RhinoDoc.ActiveDoc #set focus to Rhino Doc
    RhinoDocName = rs.DocumentName() #do something
    sc.doc = ghdoc #set focus back to GH

On the other hand, if you work directly in rhinocommon, you don’t have to deal with scriptcontext.

import Rhino

if x:
    GHDocName = ghdoc.Name
    RhinoDocName = Rhino.RhinoDoc.ActiveDoc.Name

1 Like
#3

thanks it Helps a lot !