FreeCADInit.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import FreeCAD
00035
00036
00037 def InitApplications():
00038 try:
00039 import sys,os
00040 except:
00041 FreeCAD.PrintError("\n\nSeems the python standard libs are not installed, bailing out!\n\n")
00042 raise
00043
00044 ModDir = FreeCAD.getHomePath()+'Mod'
00045 ModDir = os.path.realpath(ModDir)
00046 BinDir = FreeCAD.getHomePath()+'bin'
00047 BinDir = os.path.realpath(BinDir)
00048 LibDir = FreeCAD.getHomePath()+'lib'
00049 LibDir = os.path.realpath(LibDir)
00050 AddPath = FreeCAD.ConfigGet("AdditionalModulePaths").split(";")
00051 HomeMod = FreeCAD.ConfigGet("UserAppData")+"Mod"
00052 HomeMod = os.path.realpath(HomeMod)
00053 MacroMod = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro").GetString("MacroPath")+"/Mod"
00054 MacroMod = os.path.realpath(MacroMod)
00055 ModPar = FreeCAD.ParamGet("System parameter:Modules")
00056
00057
00058 if os.path.isdir(FreeCAD.getHomePath()+'src\\Tools'):
00059 sys.path.append(FreeCAD.getHomePath()+'src\\Tools')
00060
00061
00062 ModDict = {}
00063 if os.path.isdir(ModDir):
00064 ModDirs = os.listdir(ModDir)
00065 for i in ModDirs: ModDict[i.lower()] = os.path.join(ModDir,i)
00066 else:
00067 Wrn ("No modules found in " + ModDir + "\n")
00068
00069 if os.path.isdir(HomeMod):
00070 HomeMods = os.listdir(HomeMod)
00071 for i in HomeMods: ModDict[i.lower()] = os.path.join(HomeMod,i)
00072
00073 if os.path.isdir(MacroMod):
00074 MacroMods = os.listdir(MacroMod)
00075 for i in MacroMods: ModDict[i.lower()] = os.path.join(MacroMod,i)
00076
00077 for i in AddPath:
00078 if os.path.isdir(i): ModDict[i] = i
00079
00080
00081
00082
00083 PathExtension = BinDir + os.pathsep
00084
00085 Log('Init: Searching for modules...\n')
00086 FreeCAD.__path__ = ModDict.values()
00087 for Dir in ModDict.values():
00088 if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')):
00089 ModGrp = ModPar.GetGroup(Dir)
00090 sys.path.insert(0,Dir)
00091 PathExtension += Dir + os.pathsep
00092 InstallFile = os.path.join(Dir,"Init.py")
00093 if (os.path.exists(InstallFile)):
00094 try:
00095 execfile(InstallFile)
00096 except Exception, inst:
00097 Log('Init: Initializing ' + Dir + '... failed\n')
00098 Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n')
00099 else:
00100 Log('Init: Initializing ' + Dir + '... done\n')
00101 else:
00102 Log('Init: Initializing ' + Dir + '(Init.py not found)... ignore\n')
00103 sys.path.insert(0,LibDir)
00104 sys.path.insert(0,ModDir)
00105 Log("Using "+ModDir+" as module path!\n")
00106
00107 os.environ["PATH"] = PathExtension + os.environ["PATH"]
00108 path = os.environ["PATH"].split(os.pathsep)
00109 Log("System path after init:\n")
00110 for i in path:
00111 Log(" " + i + "\n")
00112
00113 import platform
00114 if len(platform.mac_ver()[0]) > 0:
00115 sys.path.append(os.path.expanduser('~/Library/Application Support/FreeCAD/Mod'))
00116
00117
00118 App = FreeCAD
00119 Log = FreeCAD.Console.PrintLog
00120 Msg = FreeCAD.Console.PrintMessage
00121 Err = FreeCAD.Console.PrintError
00122 Wrn = FreeCAD.Console.PrintWarning
00123
00124 Log ('Init: starting App::FreeCADInit.py\n')
00125
00126
00127 InitApplications()
00128
00129 FreeCAD.EndingAdd("FreeCAD document (*.FCStd)","FreeCAD")
00130
00131
00132 App.GuiUp = 0
00133
00134
00135 del(InitApplications)
00136
00137 Log ('Init: App::FreeCADInit.py done\n')
00138
00139
00140
00141