Skip to content

Fixed a bug in object3d and removed print from Desktop.py #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ def __init__(
self._main.isoutsideDesktop = True
self.release_on_exit = True
self.logfile = None
self._logger = aedt_logger.AedtLogger(filename=self.logfile, level=logging.DEBUG)
self._logger.info("Logger Started")
self._main.aedt_logger = self._logger
if "oDesktop" in dir(): # pragma: no cover
self.release_on_exit = False
self._main.oDesktop = oDesktop
Expand All @@ -361,11 +364,11 @@ def __init__(
del self._main.oDesktop
self._main.student_version, version_key, version = self._set_version(specified_version, student_version)
if _com == "ironpython": # pragma: no cover
print("Launching PyAEDT outside AEDT with IronPython.")
self._logger.info("Launching PyAEDT outside AEDT with IronPython.")
self._init_ironpython(non_graphical, new_desktop_session, version)
elif _com == "pythonnet_v3":
if version_key < "2022.2" or not settings.use_grpc_api:
print("Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet")
self._logger.info("Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet")
self._init_cpython(
non_graphical,
new_desktop_session,
Expand All @@ -376,9 +379,6 @@ def __init__(
)
else:
self._init_cpython_new(non_graphical, new_desktop_session, version, self._main.student_version)
# print("Launching PyAEDT outside AEDT with CPython and Pythonnet.")
# self._init_cpython(non_graphical, new_desktop_session, version,
# self._main.student_version, version_key)
else:
oAnsoftApp = win32com.client.Dispatch(version)
self._main.oDesktop = oAnsoftApp.GetAppDesktop()
Expand Down Expand Up @@ -465,11 +465,11 @@ def current_version_student(self):
def _init_desktop(self):
self._main.AEDTVersion = self._main.oDesktop.GetVersion()[0:6]
self._main.oDesktop.RestoreWindow()
self._logger = aedt_logger.AedtLogger(filename=self.logfile, level=logging.DEBUG)
self._logger.info("Logger Started on %s", self.logfile)
self._main.aedt_logger = self._logger
self._main.sDesktopinstallDirectory = self._main.oDesktop.GetExeDir()
self._main.pyaedt_initialized = True
self._logger = aedt_logger.AedtLogger(filename=self.logfile, level=logging.DEBUG)
self._logger.info("Logger file %s in use.")
self._main.aedt_logger = self._logger

def _set_version(self, specified_version, student_version):
student_version_flag = False
Expand Down Expand Up @@ -569,14 +569,13 @@ def _init_cpython(
sys.path.append(base_path)
sys.path.append(os.path.join(base_path, "PythonFiles", "DesktopPlugin"))
launch_msg = "AEDT installation Path {}.".format(base_path)
print(launch_msg)
print("===================================================================================")
self.logger.info(launch_msg)
clr.AddReference("Ansys.Ansoft.CoreCOMScripting")
AnsoftCOMUtil = __import__("Ansys.Ansoft.CoreCOMScripting")
self.COMUtil = AnsoftCOMUtil.Ansoft.CoreCOMScripting.Util.COMUtil
self._main.COMUtil = self.COMUtil
StandalonePyScriptWrapper = AnsoftCOMUtil.Ansoft.CoreCOMScripting.COM.StandalonePyScriptWrapper
print("pyaedt info: Launching AEDT with module Pythonnet.")
self.logger.info("Launching AEDT with module Pythonnet.")
processID = []
if IsWindows:
processID = self._get_tasks_list_windows(student_version)
Expand All @@ -603,9 +602,9 @@ def _init_cpython(
self._dispatch_win32(version)
elif version_key >= "2021.2":
if student_version:
print("pyaedt info: {} Student version started with process ID {}.".format(version, proc[0]))
self.logger.info("{} Student version started with process ID {}.".format(version, proc[0]))
else:
print("pyaedt info: {} Started with process ID {}.".format(version, proc[0]))
self.logger.info("{} Started with process ID {}.".format(version, proc[0]))
context = pythoncom.CreateBindCtx(0)
running_coms = pythoncom.GetRunningObjectTable()
monikiers = running_coms.EnumRunning()
Expand All @@ -617,7 +616,7 @@ def _init_cpython(
self._main.oDesktop = win32com.client.Dispatch(obj.QueryInterface(pythoncom.IID_IDispatch))
break
else:
warnings.warn(
self.logger.warning(
"PyAEDT is not supported in AEDT versions older than 2021.2. Trying to launch PyAEDT with PyWin32."
)
self._dispatch_win32(version)
Expand All @@ -629,9 +628,8 @@ def _init_cpython_new(self, non_graphical, new_aedt_session, version, student_ve
import ScriptEnv

launch_msg = "AEDT installation Path {}".format(base_path)
print(launch_msg)
print("===================================================================================")
print("pyaedt info: Launching AEDT with PyDesktopPlugin.")
self.logger.info(launch_msg)
self.logger.info("Launching AEDT with PyDesktopPlugin.")
if new_aedt_session or not self.port:
self.port = _find_free_port()
self.machine = ""
Expand Down Expand Up @@ -662,12 +660,12 @@ def _init_cpython_new(self, non_graphical, new_aedt_session, version, student_ve
if non_graphical:
settings.enable_desktop_logs = False
if student_version:
print("pyaedt info: {} Student version started with process ID {}.".format(version, _proc))
self.logger.info("{} Student version started with process ID {}.".format(version, _proc))
else:
print("pyaedt info: {} Started with process ID {}.".format(version, _proc))
self.logger.info("{} Started with process ID {}.".format(version, _proc))

else:
warnings.warn("PyDesktopPlugin is not supported in AEDT versions older than 2022.2.")
self.logger.warning("PyDesktopPlugin is not supported in AEDT versions older than 2022.2.")

def _set_logger_file(self):
# Set up the log file in the AEDT project directory
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/generic/general_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def __init__(self):
self._non_graphical = False
self.aedt_version = None
self.remote_api = False
self._use_grpc_api = False
self._use_grpc_api = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxcapodi78 Is it expected to use gRPC API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. I'll revert

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect. Thanks

self.machine = ""
self.port = 0
self.formatter = None
Expand Down
10 changes: 5 additions & 5 deletions pyaedt/modeler/Object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2624,19 +2624,19 @@ def faces_by_area(self, area, area_filter="==", tolerance=1e-12):

faces = []
for face in self.faces:
if area_filter is "==":
if area_filter == "==":
if abs(face.area - area) < tolerance:
faces.append(face)
if area_filter is ">=":
if area_filter == ">=":
if (face.area - area) >= tolerance:
faces.append(face)
if area_filter is "<=":
if area_filter == "<=":
if (face.area - area) <= tolerance:
faces.append(face)
if area_filter is ">":
if area_filter == ">":
if (face.area - area) > tolerance:
faces.append(face)
if area_filter is "<":
if area_filter == "<":
if (face.area - area) < tolerance:
faces.append(face)

Expand Down