Home / Python script / Python Femtet Utility Package Method
Python Femtet Utility Package Method
Notes
- The method allows you to activate Femtet and other applications with Python script.
- The name of Femtet interface class is defined. It is useful for creating an instance.
How to Use Method
- Prepare operating environment for Python
- Import the Python Femtet utility package with Python script.
Example: from femtetutils import util, const - Use methods with Python script.
Example: util.auto_execute_femtet()
Log Output from Methods
- Methods can generate logs as output. To stop the output from methods, execute the following procedures.
- In the script file where the method is called, add the following process.
from logging import disable
if __name__ == '__main__':
disable() # Does not output the log from the Femtet utility package method.
Process ID and Window Handle
- When macro runs, the value other than 0 will be set to the hWnd property of CFemtet Class, the window handle of Femtet.
- By specifying the window handle with the close_femtet() method, Femtet where the macro has run can be closed.
- By specifying the window handle with the get_process_id_from_hwnd() method, the process ID can be obtained.
- When a process is activated, an ID is assigned to the process.
- The process can be closed with the vclose_process() method.
Method List
| Name | Overview |
| auto_execute_femtet | Activates Femtet.exe (if there is no unused Femtet) |
| execute_femtet | Activates Femtet.exe |
| close_femtet | Closes Femtet.exe of the specified window handle. |
| get_last_executed_femtet_process_id | Gets the process ID of the most recently activated Femtet.exe. |
| get_femtet_exe_path | Gets the Path of Femtet.exe. |
| is_femtet_active | Determines whether Femtet.exe is activated. |
| execute_process | Activate a process. |
| close_process | Close the process of the specified process ID (Forced Termination) |
| get_last_executed_process_id | Gets the process ID of the most recently activated process. |
| get_process_id_from_hwnd | Gets a process ID |
auto_execute_femtet(wait_second=60)
[Overview] Activates Femtet.exe (if there is no unused Femtet)
[Details] Activates Femtet if no Femtet is activated or all of activated Femtet are used.
[Parameter] wait_second: Before activation, standby for the specified time (second).
[Type of Parameter] wait_second: Int (second)
[Return] True: Unused Femtet is activated or Femtet is newly activated. False: Fail to activate Femtet.
[Return Type] bool
[Example]
from femtetutils import util, const util.auto_execute_femtet()
close_femtet(hwnd, wait_second=60, isTerminate=True)
[Overview] Closes Femtet.exe of the specified window handle.
[Details] Specifies a window handle as a parameter and closes Femtet.exe of the target. Unlike the Femtet.Exit() method, Femtet can be terminated forcibly.
[Parameter] hwnd: Window Handle of Femtet
Note: The window handle associated with a macro by CFemtet.hWnd can be obtained.
[Type of Parameter] hwnd: int
[Parameter 2] wait_second: Maximum standby time before closing (second)
[Type of Parameter 2] wait_second: int (second)
[Parameter 3] isTerminate: If cannot be closed, whether to forcibly terminate or not. True: Terminate forcibly, False: Does not terminate forcibly.
[Type of Parameter 3] isTerminate: bool
[Return] True: Femtet is closed, False: Femtet cannot be closed within the time.
[Return Type] bool
[Example]
import sys from femtetutils import util, const from win32com.client import Dispatch, constants util.auto_execute_femtet() Femtet = Dispatch(const.CFemtet) if Femtet.OpenNewProject() == False:
print(Femtet.LastErrorMsg)
sys.exit() util.close_femtet(Femtet.hWnd)
close_process(process_id)
[Overview] Close the process of the specified process ID (Forced Termination)
[Details] Specifies a process ID to close the process of target (Forced Termination).
[Parameter] process_id: Process ID
[Type of Parameter] process_id: int
[Return] True: The process has been terminated forcibly, False: An error occurred during the forced termination process.
[Return Type] bool
[Example]
import time from femtetutils import util, const ret, code = util.execute_process("notepad.exe") time.sleep(10) util.close_process(util.get_last_executed_process_id())
execute_femtet()
[Overview] Activate Femtet.exe
[Details] Activates Femtet.exe.
[Retrun] True: Process is activated False: Process cannot be activated.
[Return Type] bool
[Example]
from femtetutils import util, const util.execute_femtet()
execute_process(command, timeout_second=None)
[Overview] Activates a process
[Details] Activates the specified process.
- If the time is not specified with parameters, the process will be performed asynchronously.
- If the time is specified with parameters, standby until the process terminates.
If the process does not terminate beyond the standby time, an error occurs.
[Parameter] command: Path of the process of the target for activation
Example: "notepad.exe"
[Type of Parameter] command: str
[Parameter] timeout_second: Wait for the process termination until the specified time (second).
[Type of Parameter] timeout_second: Int (second)
[Retrun] True: Process is activated False: Process cannot be activated.
[Return Type] bool
[Return 2] [Success in Activation] Exit code from the process
[Error] -1: Timeout -2: Exception error occurred during the process.
[Type of Return 2] int
[Example]
from femtetutils import util, const ret, code = util.execute_process("notepad.exe")
get_femtet_exe_path()
[Overview] Gets Path of Femtet.exe.
[Details] Method to get the path of Femtet.exe from the registration information.
[Return] Path of Femtet.exe
Example: "C:¥Program Files¥Femtet_Ver2023_64bit¥Program¥Femtet.exe"
[Type of Return] str
[Example]
from femtetutils import util, const femtetpath = util.get_femtet_exe_path() print(femtetpath)
get_last_executed_femtet_process_id
[Overview] Gets the process ID of the most recently activated Femtet.exe.
[Details] Gets the process ID activated with execute_femtet().
* Only the most recently activated process is applicable.
[Return] Process ID (If process does not exist, return 0)
[Type of Return] int
[Example]
import time from femtetutils import util, const if util.execute_femtet() == True:
procid = util.get_last_executed_femtet_process_id()
time.sleep(20)
print(procid)
get_last_executed_process_id()
[Overview] Gets the process ID of the most recently activated process
[Details] Gets the process ID activated with execute_process().
* Only the most recently activated process is applicable.
[Return] Process ID (If process does not exist, return 0)
[Type of Return] int
[Example]
import time from femtetutils import util, const ret, code = util.execute_process("notepad.exe") time.sleep(10) util.close_process(util.get_last_executed_process_id())
get_process_id_from_hwnd(hwnd)
[Overview] Get the process ID
[Details] Gets the process ID from the specified window handle.
[Parameter] hwnd: Sets CFemtet.hWnd property.
[Type of Parameter] hwnd: int
[Return] Process ID (If it cannot be obtained, return 0)
[Type of Return] int
[Example]
import sys from femtetutils import util, const from win32com.client import Dispatch, constants util.auto_execute_femtet() Femtet = Dispatch(const.CFemtet) if Femtet.OpenNewProject() == False:
print(Femtet.LastErrorMsg)
sys.exit() procid = util.get_process_id_from_hwnd(Femtet.hWnd) print(procid)
is_femtet_active()
[Overview] Determines whether Femtet.exe is activated.
[Details] Determines whether Femtet.exe is activated.
[Return] True: Activated, False: Not activated
[Return Type] bool
[Example]
from femtetutils import util, const print(util.is_femtet_active())


