> For the complete documentation index, see [llms.txt](https://scripting.karamba3d.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scripting.karamba3d.com/2.-scripting-with-karamba3d-inside-grasshopper/2.8-the-python-3-component/2.8.4-how-to-modify-structural-models/2.8.4.2-activation-and-deactivation-of-elements.md).

# 2.8.4.2: Activation and Deactivation of Elements

The equivalent Python 3 code of the example in [section 2.4.2](/2.-scripting-with-karamba3d-inside-grasshopper/2.4-how-to-modify-structural-models/2.4.2-activation-and-deactivation-of-elements.md) looks like this:

{% code lineNumbers="true" %}

```
import Karamba.Models
import Karamba.CrossSections
import Karamba.Elements
import Karamba.Results
import KarambaCommon
from Karamba.Elements.States.Selectors import StateElement1DSelectorIndex
from Karamba.Geometry import *
from System.Collections.Generic import List
from System import String

model = Model_in
if not isinstance(model, Karamba.Models.Model):
      raise Exception("The input in 'Model_in' is not of type Karamba.Models.Model!")

# load case to consider for elimination of elements
lcName = "LC0";
lcNames = List[String]([lcName])
# get load-case combination
success, lcc = model.lcActivation.TryGetLoadCaseCombination(lcName)
# select load case 0 of load-case combination "LC0"
stateSelector = StateElement1DSelectorIndex(model, lcc, 0);

# clone the model and its list of elements to avoid side effects
model = model.Clone();
# clone its elements to avoid side effects
model.cloneElements();

k3d = KarambaCommon.Toolkit()

# do the iteration and remove elements with tensile axial forces
for iter in range(maxiter):
    # create a deform and response object for calculating and retrieving results
    model, max_disp, outForce, outEnergy, Warning = k3d.Algorithms.Analyze(model, lcNames)

    # check the normal force of each element and deactivate those under tension
    has_changed = False;
    for elem in model.elems:
        # retrieve resultant cross section forces
        N, V, M = elem.resultantCroSecForces(model, stateSelector, 0.3, 3)

        # check whether normal force is tensile
        if (N > 0):
            # set element inactive
            elem.set_is_active(model, False)
            has_changed = True

    # leave iteration loop if nothing changed
    if not has_changed:
        break

    # rebuild the C++ model
    model.buildFEModel()

# update model to its final state
model, max_disp, outForce, outEnergy, Warning = k3d.Algorithms.Analyze(model, lcNames)

# set up list of true/false values that corresponds to the elemment states
elem_activity = []
for elem in model.elems:
    elem_activity.append(elem.IsActive);


isActive = elem_activity;
maxDisp = max_disp;
Model_out = Karamba.GHopper.Models.GH_Model(model)

print("Everything OK");
```

{% endcode %}

{% file src="/files/qfg6gIUmyrhEmhuXfNg2" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://scripting.karamba3d.com/2.-scripting-with-karamba3d-inside-grasshopper/2.8-the-python-3-component/2.8.4-how-to-modify-structural-models/2.8.4.2-activation-and-deactivation-of-elements.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
