mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
load geometries from command line with python netgen executable
This commit is contained in:
parent
bac314a666
commit
6b36a2d9d8
@ -209,6 +209,12 @@ NGCORE_API_EXPORT void ExportSTL(py::module & m)
|
||||
}, py::arg("mp") = nullptr,
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
(meshingparameter_description + stlparameter_description).c_str())
|
||||
.def("Draw", FunctionPointer
|
||||
([] (shared_ptr<STLGeometry> self)
|
||||
{
|
||||
ng_geometry = self;
|
||||
})
|
||||
)
|
||||
;
|
||||
m.def("LoadSTLGeometry", [] (const string & filename)
|
||||
{
|
||||
|
@ -1,11 +1,41 @@
|
||||
import imp, threading, sys
|
||||
|
||||
def _py_handler(f):
|
||||
with open(f) as pyfile:
|
||||
imp.load_module('__main__', pyfile, f, (".py", "r", imp.PY_SOURCE))
|
||||
|
||||
def _geo_handler(f):
|
||||
from netgen.csg import CSGeometry
|
||||
print("load", f)
|
||||
geo = CSGeometry(f)
|
||||
geo.Draw()
|
||||
|
||||
def _step_handler(f):
|
||||
from netgen.occ import OCCGeometry
|
||||
print("load", f)
|
||||
geo = OCCGeometry(f)
|
||||
geo.Draw()
|
||||
|
||||
def _stl_handler(f):
|
||||
from netgen.stl import STLGeometry
|
||||
print("load", f)
|
||||
geo = STLGeometry(f)
|
||||
geo.Draw()
|
||||
|
||||
_file_handler = {}
|
||||
_file_handler['.py'] = _py_handler
|
||||
_file_handler['.geo'] = _geo_handler
|
||||
_file_handler['.step'] = _step_handler
|
||||
_file_handler['.stl'] = _stl_handler
|
||||
|
||||
def handle_arguments():
|
||||
import __main__
|
||||
import os.path
|
||||
argv = sys.argv
|
||||
if len(argv)>1 and argv[1].endswith(".py"):
|
||||
with open(argv[1]) as pyfile:
|
||||
imp.load_module('__main__', pyfile, argv[1], (".py", "r", imp.PY_SOURCE))
|
||||
if len(argv)>1:
|
||||
_, ext = os.path.splitext(argv[1])
|
||||
if ext in _file_handler:
|
||||
_file_handler[ext](argv[1])
|
||||
|
||||
def main():
|
||||
import netgen
|
||||
|
Loading…
Reference in New Issue
Block a user