Author Topic: Attaching the SetName to a directory  (Read 3345 times)

Offline Rob Archer

  • Posts: 163
  • Cookies: 545
  • New Frontier MKVI
Attaching the SetName to a directory
« on: August 29, 2006, 01:20:48 PM »
I know how to get the SetName Using the

pSet.GetName() command

but i want to use it to import the corosponding file from a directory.

Example of what ive tried:

Code: [Select]

        pPlayer = MissionLib.GetPlayer()
pSet = pPlayer.GetContainingSet()
sSetName = pSet.GetName()
print("Current Location: " + str(sSetName))
__import__ ("Custom.QBautostart.NFSystemDirectory." + sSetName)


So it will import  the name of the system i.e Belaruz4 and add it so it will

import Custom.QBautostart.NFSystemDirectory.Belaruz4

Ive had it working with the Print Command but i cant get it to acctually import the file can someone lend a hand.

Offline MLeo

  • Retired Staff
  • Posts: 3636
  • Cookies: 833
  • Software Simian
    • the Programming Pantheon
Attaching the SetName to a directory
« Reply #1 on: August 29, 2006, 02:07:15 PM »
For starters, there would need to be a file (or directory with __init__.py in it) called that way in scripts/Custom/QBautostart/NFSystemDirectory.
I still can't read peoples minds, nor can I read peoples computers, even worse, I can't combine the two to read what is going wrong with your BC install...

"It was filed under 'B' for blackmail." - Morse, Inspector Morse - The dead of Jericho.

Offline SimRex

  • Posts: 9
  • Cookies: 9
Re: Attaching the SetName to a directory
« Reply #2 on: August 29, 2006, 02:16:09 PM »
Quote from: Rob Archer
I know how to get the SetName Using the

pSet.GetName() command

but i want to use it to import the corosponding file from a directory.

Example of what ive tried:

Code: [Select]

        pPlayer = MissionLib.GetPlayer()
pSet = pPlayer.GetContainingSet()
sSetName = pSet.GetName()
print("Current Location: " + str(sSetName))
__import__ ("Custom.QBautostart.NFSystemDirectory." + sSetName)


So it will import  the name of the system i.e Belaruz4 and add it so it will

import Custom.QBautostart.NFSystemDirectory.Belaruz4

Ive had it working with the Print Command but i cant get it to acctually import the file can someone lend a hand.


I presume you know the __import__ command doesn't work quite like normal importing?

If you're trying to access variables or methods in the imported module, you need to do something like this:

Code: [Select]
mModule = __import__("stuff")
mModule.Whatever()

Offline Rob Archer

  • Posts: 163
  • Cookies: 545
  • New Frontier MKVI
Attaching the SetName to a directory
« Reply #3 on: August 29, 2006, 03:46:22 PM »
Thanks Guys

I figured it out in the end anyway and the system seems to be doing what i want

Thanks for the help.