@@ -44,16 +44,15 @@ class RhinoClient(object):
4444 """
4545
4646 def __init__ (self , delay_start = False ):
47- self .app = None
48- self .rsm = None
49- self .rsi = None
47+ self .Rhino = None
48+ self .rs = None
5049 if not delay_start :
5150 self .start ()
52- self .wait ()
51+ # self.wait()
5352
5453 def __getattr__ (self , name ):
55- if self .rsi :
56- method = getattr (self .rsi , name )
54+ if self .rs :
55+ method = getattr (self .rs , name )
5756
5857 def wrapper (* args , ** kwargs ):
5958 return method (* args , ** kwargs )
@@ -63,48 +62,30 @@ def wrapper(*args, **kwargs):
6362 raise RhinoClientError ()
6463
6564 def start (self ):
66- # self.rsm = GetModule(['{75B1E1B4-8CAA-43C3-975E-373504024FDB}', 1, 0])
67- # self.rsm = GetModule(['{1C7A3523-9A8F-4CEC-A8E0-310F580536A7}', 1, 0])
68- # self.rsm = GetModule(['{814d908a-e25c-493d-97e9-ee3861957f49}', 1, 0])
69- # self.rsm = GetModule(['{8ABB4303-8057-47AD-BAEB-263965E5565D}', 1, 0])
70- # self.rsm = GetModule(['{75B1E1B4-8CAA-43C3-975E-373504024FDB}', 1, 0])
71- R = GetModule (r"C:\Program Files\Rhinoceros 5\System\Rhino5.tlb" )
72- RS = GetModule (r"C:\Program Files\Rhinoceros 5\Plug-ins\RhinoScript.tlb" )
73-
74- print (dir (R ))
75- print (dir (RS ))
76-
77- print ('loading script interface...' )
78-
79- attempts = 20
80-
81- self .app = CreateObject ('Rhino5x64.Application' )
82-
83- while attempts :
84- try :
85- print ('attempt %s' % attempts )
86- # self.rsi = self.app.GetScriptObject.QueryInterface(self.rsm.IRhinoScript)
87- # self.rsi = self.app.QueryInterface(self.rsm.IRhino5x64Application).GetScriptObject()
88- o = self .app .QueryInterface (R .IRhino5x64Interface ).GetScriptObject ()
89- self .rsi = o .QueryInterface (RS .IRhinoScript )
90- break
91- except Exception as e :
92- print (e )
93- time .sleep (0.5 )
94- attempts -= 1
95- if self .rsi is None :
96- raise Exception ('error loading script interface...' )
97- print ('script interface loaded!' )
65+ Rhino_tlb = GetModule ("C:/Program Files/Rhinoceros 5/System/Rhino5.tlb" )
66+ RhinoScript_tlb = GetModule ("C:/Program Files/Rhinoceros 5/Plug-ins/RhinoScript.tlb" )
67+ self .Rhino = CreateObject ('Rhino5x64.Application' ).QueryInterface (Rhino_tlb .IRhino5x64Application )
68+ while not self .Rhino .IsInitialized ():
69+ print ('Initialising Rhino...' )
70+ time .sleep (0.5 )
71+ print ('Rhino initialised!' )
72+ self .rs = self .Rhino .GetScriptObject ().QueryInterface (RhinoScript_tlb .IRhinoScript )
9873
9974 def stop (self ):
10075 raise NotImplementedError
10176
102- def show (self , flag = 1 ):
103- self .app .Visible = flag
77+ def show (self ):
78+ self .Rhino .Visible = True
10479
105- def wait (self ):
106- self .rsi .GetString ('Press enter to exit...' , 'exit' )
107- self .rsi .Command ('_Exit' )
80+ def hide (self ):
81+ self .Rhino .Visible = False
82+
83+ def top (self ):
84+ self .Rhino .BringToTop ()
85+
86+ # def wait(self):
87+ # self.rs.GetString('Press enter to exit...', 'exit')
88+ # self.rs.Command('_Exit')
10889
10990
11091# ==============================================================================
@@ -113,5 +94,9 @@ def wait(self):
11394
11495if __name__ == "__main__" :
11596
116- client = RhinoClient ()
117- client .rsi .AddPoint ([0 , 0 , 0 ])
97+ Rhino = RhinoClient ()
98+
99+ Rhino .show ()
100+ Rhino .top ()
101+
102+ Rhino .rs .AddPoint ([0 , 0 , 0 ])
0 commit comments