Modules and Namespaces

  • Thread starter Jelle Feringa / EZCT Architecture & Design Researc
  • Start date
J

Jelle Feringa / EZCT Architecture & Design Researc

##I'm sorry to stir up such a well discussed topic yet again, but namespaces
are a point of confusion to me...

I took the effort of organizing my Python code (scripting a cad program
calles Rhino) in well defined classes, which would be a terrific thing if I
didn't got stuck in namespace issues.

I have a module that launches the application I'm scripting via win32com;
rhino.load

from rhino import load
RS = load.RS

So the application, with all its methods are now available through the RS
(RhinoScript) object

from rhino import SRF # is where things get stuck

The RS object is the application scripted via COM, where all its method
reside.
In my module, SRF, I'm not importing anything, though it refers to the RS
object all the time.
Such as:

class srfBase:
'''Base class inherited by the srf* classes, binding general Rhino
surface functionality to a particular
surface generation method'''
def __init__(self):
self.id = 'self.id srfBase'
pass
def isBrep(self):
return RS.IsBrep(self.id)
def isPointInSurface(self, coord):
return RS.IsPointInSurface(self.id, coord)


How do I make the RS object available to the imported SRF module, such that
my module code and program code both refer to RS as the application object
being scripted?

Cheers,

Jelle.
 
L

Larry Bates

One way is to pass the RS object when you instantiate
an instance of srfBase, something like:

class srfBase:
'''Base class inherited by the srf* classes, binding general Rhino
surface functionality to a particular
surface generation method'''
def __init__(self, RS):
self.id = 'self.id srfBase'
self.RS=RS
return
def isBrep(self):
return self.RS.IsBrep(self.id)
def isPointInSurface(self, coord):
return self.RS.IsPointInSurface(self.id, coord)

This is how most of wxWindows seems to do things.

-Larry Bates
 
J

jelle

Dear Steve & Larry,

Both your methods worked flawless, thanks to both of you!
I have to say Larry's way wins on style points, doens't it?
What an awefull thing to get stuck on something that simple, what a
gorgeous solution, thanks so much!

-Jelle
 
J

jelle

Ooops, Larry, forgive me being to overhauled here:
Actually self.RS = RS does not make the RS object available in the
module, Steve's method does however.

-Jelle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top