Skip to content

Adding Process ID so PyAEDT can point to a specific instance of Electronics Desktop #1187

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 29 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5055c9c
Add a variable to the constructors of the classes needed to aim PyAED…
camuher May 16, 2022
d6a25c1
Merge branch 'main' of https://github.com/camuher/pyaedt
camuher May 16, 2022
2a806e7
Merge branch 'pyansys:main' into main
camuher May 17, 2022
7bc4230
added aedt_process_id to: circuit, emit, hfss3dlayout, icepak, maxwel…
camuher May 17, 2022
26affba
Merge branch 'pyansys:main' into main
camuher May 18, 2022
83f8860
Improves style compliance. Also adds aedt_process_id to RMxport ant …
camuher May 18, 2022
c725de2
Merge branch 'pyansys:main' into main
camuher May 19, 2022
4be49eb
Minor edits to match the style
camuher May 19, 2022
bdf938d
Merge branch 'main' of https://github.com/camuher/pyaedt
camuher May 19, 2022
c79d1fe
Update pyaedt/application/Analysis.py
camuher May 19, 2022
94b31d3
Update pyaedt/application/Analysis3D.py
camuher May 19, 2022
0e61189
Update pyaedt/application/Analysis3DLayout.py
camuher May 19, 2022
5e0a2e9
Update pyaedt/application/AnalysisMaxwellCircuit.py
camuher May 19, 2022
36d2aac
Update pyaedt/application/Design.py
camuher May 19, 2022
6d4d470
Update pyaedt/circuit.py
camuher May 19, 2022
25f8a98
Update pyaedt/desktop.py
camuher May 19, 2022
1404c94
Update pyaedt/emit.py
camuher May 19, 2022
e1880c5
Update pyaedt/hfss.py
camuher May 19, 2022
0d7612b
Update pyaedt/hfss3dlayout.py
camuher May 19, 2022
528cf88
Update pyaedt/icepak.py
camuher May 19, 2022
cd14eb7
Update pyaedt/maxwell.py
camuher May 19, 2022
21ed735
Update pyaedt/maxwell.py
camuher May 19, 2022
a49088c
Update pyaedt/maxwellcircuit.py
camuher May 19, 2022
4f2c46e
Update pyaedt/mechanical.py
camuher May 19, 2022
fb140da
Update pyaedt/q3d.py
camuher May 19, 2022
e1d5775
Update pyaedt/q3d.py
camuher May 19, 2022
6986c98
Update pyaedt/rmxprt.py
camuher May 19, 2022
8b34468
Update pyaedt/twinbuilder.py
camuher May 19, 2022
c125bf8
Merge branch 'pyansys:main' into main
camuher May 19, 2022
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
5 changes: 5 additions & 0 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class Analysis(Design, object):
Whether to release AEDT on exit.
student_version : bool
Whether to enable the student version of AEDT.
aedt_process_id : int, optional
Only used when new_desktop_session == False, specifies by process id which instance
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Only used when new_desktop_session == False, specifies by process id which instance
Only used when new_desktop_session = False, specifies by process id which instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MaxJPRey in my latest commit i've followed this style while addressing Massimo's comment.

of electronics desktop to point PyAEDT at.

"""

Expand All @@ -86,6 +89,7 @@ def __init__(
student_version,
machine="",
port=0,
aedt_process_id = None,
):
self.setups = []
Design.__init__(
Expand All @@ -101,6 +105,7 @@ def __init__(
student_version,
machine,
port,
aedt_process_id,
)
self.logger.info("Design Loaded")
self._setup = None
Expand Down
5 changes: 5 additions & 0 deletions pyaedt/application/Analysis3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class FieldAnalysis3D(Analysis, object):
student_version : bool, optional
Whether to enable the student version of AEDT. The default
is ``False``.
aedt_process_id : int, optional
Only used when new_desktop_session == False, specifies by process id which instance
of electronics desktop to point PyAEDT at.
"""

def __init__(
Expand All @@ -77,6 +80,7 @@ def __init__(
student_version=False,
machine="",
port=0,
aedt_process_id = None,
):
Analysis.__init__(
self,
Expand All @@ -92,6 +96,7 @@ def __init__(
student_version,
machine,
port,
aedt_process_id,
)
self._osolution = self._odesign.GetModule("Solutions")
self._oboundary = self._odesign.GetModule("BoundarySetup")
Expand Down
6 changes: 5 additions & 1 deletion pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ class Design(object):
student_version : bool, optional
Whether to enable the student version of AEDT. The default
is ``False``.
aedt_process_id : int, optional
Only used when new_desktop_session == False, specifies by process id which instance
of electronics desktop to point PyAEDT at.

"""

Expand Down Expand Up @@ -366,6 +369,7 @@ def __init__(
student_version=False,
machine="",
port=0,
aedt_process_id = None,
):
self._init_variables()
# Get Desktop from global Desktop Environment
Expand All @@ -378,7 +382,7 @@ def __init__(

if "pyaedt_initialized" not in dir(main_module):
desktop = Desktop(
specified_version, non_graphical, new_desktop_session, close_on_exit, student_version, machine, port
specified_version, non_graphical, new_desktop_session, close_on_exit, student_version, machine, port, aedt_process_id
)
self._logger = desktop.logger
self.release_on_exit = True
Expand Down
19 changes: 14 additions & 5 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class Desktop:
Port number of which start the oDesktop communication on already existing server.
This parameter is ignored in new server creation. It works only on 2022R2.
Remote Server must be up and running with command `"ansysedt.exe -grpcsrv portnum"`.
aedt_process_id : int, optional
Only used when new_desktop_session == False, specifies by process id which instance
of electronics desktop to point PyAEDT at.

Examples
--------
Expand Down Expand Up @@ -321,6 +324,7 @@ def __init__(
student_version=False,
machine="",
port=0,
aedt_process_id = None,
):
"""Initialize desktop."""
self._main = sys.modules["__main__"]
Expand All @@ -332,6 +336,7 @@ def __init__(
self._main.student_version = student_version
self.machine = machine
self.port = port
self.aedt_process_id = aedt_process_id
if is_ironpython:
self._main.isoutsideDesktop = False
else:
Expand Down Expand Up @@ -363,7 +368,7 @@ def __init__(
if StrictVersion(version_key) < StrictVersion("2022.2.0") or not settings.use_grpc_api:
print("Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print("Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet")
print("Launching PyAEDT outside Electronics Desktop with CPython and Python.Net.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @PipKat , while I don't mind committing the small change to this print statement, it is outside the scope of changes I contributed to the code. I'd appreciate the (somewhat redundant) affirmation that it is ok to proceed with this commit.

self._init_cpython(
non_graphical, new_desktop_session, version, self._main.student_version, version_key
non_graphical, new_desktop_session, version, self._main.student_version, version_key, aedt_process_id
)
else:
self._init_cpython_new(non_graphical, new_desktop_session, version, self._main.student_version)
Expand All @@ -382,6 +387,7 @@ def __init__(
settings.aedt_version = self.odesktop.GetVersion()[0:6]
settings.machine = self.machine
settings.port = self.port
self.aedt_process_id = self.odesktop.GetProcessID() #bit of cleanup for consistency if used in future

if _com == "ironpython":
sys.path.append(
Expand Down Expand Up @@ -545,7 +551,8 @@ def _dispatch_win32(self, version):
self._main.oDesktop = o_ansoft_app.GetAppDesktop()
self._main.isoutsideDesktop = True

def _init_cpython(self, non_graphical, new_aedt_session, version, student_version, version_key):
def _init_cpython(self, non_graphical, new_aedt_session, version, student_version, version_key,aedt_process_id = None):

base_path = self._main.sDesktopinstallDirectory
sys.path.append(base_path)
sys.path.append(os.path.join(base_path, "PythonFiles", "DesktopPlugin"))
Expand All @@ -561,7 +568,7 @@ def _init_cpython(self, non_graphical, new_aedt_session, version, student_versio
processID = []
if IsWindows:
processID = self._get_tasks_list_windows(student_version)
if student_version and not processID:
if student_version and not processID: #Opens an instance if processID is an empty list
self._run_student()
elif non_graphical or new_aedt_session or not processID:
# Force new object if no non-graphical instance is running or if there is not an already existing process.
Expand All @@ -573,8 +580,10 @@ def _init_cpython(self, non_graphical, new_aedt_session, version, student_versio
processID2 = []
if IsWindows:
processID2 = self._get_tasks_list_windows(student_version)
proc = [i for i in processID2 if i not in processID]
if not proc:
proc = [i for i in processID2 if i not in processID] #Looking for the "new" process
if not proc and (not new_aedt_session) and aedt_process_id: #if it isn't a new aedt session and a process ID is given
proc = [aedt_process_id]
elif not proc:
proc = processID2
if proc == processID2 and len(processID2) > 1:
self._dispatch_win32(version)
Expand Down
5 changes: 5 additions & 0 deletions pyaedt/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Hfss(FieldAnalysis3D, object):
Port number of which start the oDesktop communication on already existing server.
This parameter is ignored in new server creation. It works only on 2022R2.
Remote Server must be up and running with command `"ansysedt.exe -grpcsrv portnum"`.
aedt_process_id : int, optional
Only used when new_desktop_session == False, specifies by process id which instance
of electronics desktop to point PyAEDT at.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@camuher I like this approach. Anyway you should add the aedt_process_id to any of the tools (q2d, q3d, maxwell3d etc...) otherwise you will be able to initialize the app using process id only from Hfss

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxcapodi78 thank you for the quick reply. As specified in my latest commit I've added it to almost all the tools(and parent classes as needed) which makes for a uniform variable across the board. The only one I couldn't add it to was siwave whose init differs significantly from the structure used by the other tools. I hope this is sufficient to address your request.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@camuher
you have to ignore siwave
it is different approach.
Please merge from main to get a fix on UT and then I can approve the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxcapodi78 I've merged to be up to date with main now. I also addressed the error that caused the UT for rmxport and twinbuilder to fail. I hadn't added the variable to their parent classes. There were also miscellaneous edits to make the code more uniform with the style.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@camuher I still see some style error. I suggest to install pre-commit on your environment.
pip install pre-commit
pre-commit install

It will automatically fix style errors on commit.

PS can you ping me on Teams? I'd like to know who you are :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this last commit should correct the remaining edits and (if I'm interpreting the output correctly on the pre-commit) passes the style check
image


Examples
--------
Expand Down Expand Up @@ -150,6 +153,7 @@ def __init__(
student_version=False,
machine="",
port=0,
aedt_process_id = None,
):
FieldAnalysis3D.__init__(
self,
Expand All @@ -165,6 +169,7 @@ def __init__(
student_version,
machine,
port,
aedt_process_id,
)
self.field_setups = self._get_rad_fields()

Expand Down