##  [PyAEDT Client Library Cheat Sheet](/blog/pyaedt-client-library-cheat-sheet) 

This is a quick-reference guide for the [PyAEDT Client Library](https://aedt.docs.pyansys.com/version/stable/). You can jump to a section of your choosing by using these links:

[Launching PyAEDT](#launch) | [Variable Class](#variable) | [Material Class](#material) | [Geometry Creation](#geometry) | [Creating boundaries](#boundaries) | [Port definitions](#ports) | [Setup Class](#setup) | [Mesh Class](#meshclass) | [Analysis Class](#analysis) | [Post-Processing Class](#postclass) | [Calling AEDT Client Library with PyAEDT](#pyaedt)

### <a name="launch"></a>Launching PyAEDT

To launch HFSS instance locally and exit it

```Python
# To launch an instance 
import pyaedt


hfss = pyaedt.Hfss(
    specified_version="2023.1",
    non_graphical=False,
    new_desktop_session=True,
    projectname="Project_name",
    designname="Design_name"
)

# To exit the instance 
hfss.release_desktop() 

```

### <a name="variable"></a>Variable Class 

Creating a local and global variable in HFSS

```Python
hfss["dim"] = "1mm"   # design variable 
hfss["$dim"] = "1mm"   # project variable 

```

`hfss.variable_manager` is the class which handles all the variables. It contains properties and methods useful for variable handling.

### <a name="material"></a>Material Class

hfss.materialsclass is used to access the material library. A new material is added in HFSS as:

```Python
my_mat = hfss.materials.add_material("myMat")
my_mat.permittivity = 3.5
my_mat.conductivity = 450000
my_mat.permeability = 1.5 

```

### <a name="geometry"></a>Geometry Creation

hfss.modeler contains all properties and methods needed to edit a modeler, including primitives methods and properties. A box is drawn at `(x_pos, y_pos, z_pos)` position with `(x_dim, y_dim, z_dim)` dimensions as:

```Python
box = hfss.modeler.create_box([x_pos, y_pos, z_pos], [x_dim, y_dim, z_dim], name="airbox", matname="air")

```

A spiral geometry made of "copper" is created as follows:

```Python
ind = hfss.modeler.create_spiral(
    internal_radius=rin,
    width=width,
    spacing=spacing,
    turns=Nr,
    faces=Np,
    thickness=thickness,
    material="copper",
    name="Inductor1"
)

```

`box`, `ind` are the Object3d objects, containing properties and methods related to that object including faces, vertices, colors, and materials.

### <a name="boundaries"></a>Creating boundaries

In AEDT, open region is created as: ```Python
hfss.create_open_region(Frequency="1GHz")

```

Assigning the radiation boundary to a box is as follows:

```Python
hfss.assign_radiation_boundary_to_objects("airbox") 

```

### <a name="ports"></a>Port definitions

Common port types in HFSS are Lumped-port and Waveguide-port. The Pythonic way of defining thelumped-port is:

```Python
box1 = hfss.modeler.create_box([0,0,50], [10,10,5], " Box1", "copper") 
box2 = hfss.modeler.create_box([0,0,60], [10,10,5], " Box2", "copper") 
port_L = hfss.lumped_port(
    signal="Box1",
    reference=" Box2",
    integration_line=hfss.AxisDir.XNeg,
    impedance=50,name="LumpedPort",
    renormalize=True ,
    deembed=False
) 

```

The Pythonic way of defining Waveguide-port is:

```Python
port_W = hfss.wave_port("Box1", "Box2", name="WavePort", integration_line=1) 

```

### <a name="setup"></a>Setup Class

Setup class is used to define the solution setup in PyAEDT

```Python
setup = hfss.create_setup("MySetup")
setup.props["Frequency"] = "50MHz" 
setup["MaximumPasses"] = 10 
hfss.create_linear_count_sweep(
    setupname="any",
    unit=" MHz",
    freqstart=0.1,
    freqstop=100,
    num_of_freq_points=100,
    sweepname="sweep1",
    sweep_type="Interpolating",
    save_fields=False
) 

```

Parametric sweep and optimizations are accessed using the following classes:

```Python
# returns the ParametericsSetups Class
hfss.parametrics 

# returns the OptimizationSetups Class 
hfss.optimizations 

```

### <a name="meshclass"></a>Mesh Class

Mesh module manages the mesh functions in PyAEDT ```Python
# setting the slider level to 6 
hfss.mesh.assign_initial_mesh_from_slider(level=6) 

# assign model resolutions 
hfss.mesh.assign_model_resolution(names=[object1.name, object2.name], defeature_length=None) 

# assigning the mesh length to the object1 faces 
hfss.mesh.assign_length_mesh(names=object1.faces, isinside=False, maxlength=1, maxel=2000) 

```

### <a name="analysis"></a>Analysis Class

The solution setup (mysetup) in HFSS design is analyzed by calling the following Python command: ```Python
hfss.analyze_setup("mysetup") 

```

### <a name="postclass"></a>Post-processing Class

Post-processing class has modules for creating and editing plots in AEDT. They are accessible through the post library.

```Python
# This call returns a FieldPlot object
plotf = hfss.post.create_fieldplot_volume(
    object_list,
    quantityname,
    setup_name,
    intrinsic_dict
)
 
# This call returns a Solution Data object 
my_data = hfss.post.get_solution_data(expression=trace_names)

# This call returns a new standard report object 
standard_report = hfss.post.report_by_category.standard("db(S(1,1))")

# This call creates a report 
standard_report.create()
solution_data = standard_report.get_solution_data() 

```

### <a name="pyaedt"></a>Calling the AEDT Client Libary with PyAEDT

Most of the critical functionalities are captured in PyAEDT. However, the missing features from the AEDT Client Library method can be converted to the PyAEDT method.

Example: AEDT Client Library module (Optimetrics), is accessible in PyAEDT as:

```Python
omodule = hfss.odesign.GetModule("Optimetrics")

```

#### References from PyAEDT Documentation

- [Getting Started](https://aedt.docs.pyansys.com/version/stable/Getting_started/index.html)
- [User Guide](https://aedt.docs.pyansys.com/version/stable/User_guide/index.html)
- [API Reference](https://aedt.docs.pyansys.com/version/stable/API/index.html)