By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

Modules and Namespaces

P: n/a
##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.
Oct 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Jelle Feringa / EZCT Architecture & Design Research wrote:
##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.

Oct 20 '05 #2

P: n/a
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

Oct 20 '05 #3

P: n/a
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

Oct 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.