![]() | Frequently Asked Questions |
This section contains troubleshooting tips and best practices for EMC Plus and Charge Plus API development.
This topic contains the following sections:
This page will continuously be updated with information and fixes for frequently asked questions and simple troubleshooting methods for issues encountered unrelated to syntax.
The EMC Plus API may throw errors when attempting to import the relative path reference. This can be caused by multiple installations of EMC Plus overwriting the PATH variable necessary for the Discovery Scripting Interface to allow for relative module import.
# Import EMA API dll import clr apipath = "ema3d.Api.V25.dll" clr.AddReferenceToFileAndPath(apipath)
To resolve this issue, replace the simple import code block, which should resemble the above code block, with the following. This will add the correct paths and references.
import clr, os _refs, _refcount = clr.References, 0 _install_path = os.environ.get("EMA2025R1_DIR") # Change this to your local EMC Plus install directory. _api_path = "ema3d.Api.V25.dll" # This should be the name of your EMC Plus API DLL. for _ref in _refs: # Check list of references, see how many EMC Plus API references are currently added. if "ema3d.Api" in _ref.FullName: _refcount += 1 if _refcount == 0: # No references, add absolute reference clr.AddReferenceToFileAndPath(os.path.join(_install_path,_api_path)) _refcount += 1 if _refcount == 1: # 1 reference, add relative reference clr.AddReferenceToFileAndPath(_api_path)
Note: Encountering unexpected type errors, such as "Expected Document got Document", or EMC Plus scripts returning empty values may also be a result of this issue. Implementing the above fix is a recommended first step for any unexpected script behavior.
Some EMC Plus API properties that implement custom types may not reflect changes in the UI when set directly via a chain of getter/setter properties. For example, setting the MatchDomainType of a probe's TStep property. The following snippet shows examples of calls that are unlikely to update the relevant property and calls that will update the property.
# Example field probe object probe = Core.Probes.PointFieldProbe.Create(document, curve_point) # This WILL NOT set the probe's TStep.MatchDomainType property probe.TStep.MatchDomainType = Core.MatchDomainType.None # This WILL set the probe's TStep.MatchDomainType property _tstep = probe.TStep _tstep.MatchDomainType = Core.MatchDomainType.None probe.TStep = _tstep
As shown above, this often consists of creating a 'local' copy of the non-primitive property, modifying the local copy, and working backwards through the getter/setter chain to ensure each property is correctly set and updated.
Some API functionality will fail when ran via the command line if the "--headless" argument is used, most often those that start processes or open a progress bar during execution through the GUI. This can be remedied by using the "--script-async" command line argument as well. The following snippets show an example of an API call that would fail without the additional argument and an example command line call.
from ema3d.Api.V25.Core.Meshing import FDMeshEngine document = Window.ActiveWindow.Document # Mesh the geometry in the current document. FDMeshEngine.Create(document).Mesh()
"C:\Program Files\ANSYS Inc\v252\Discovery\Discovery.exe" --brand "C:\Program Files\EMA\2025R2\Framework.xml" -c modeling -p ema_gui --script-api 252 --run-script script_name.py --headless --script-async