# Add or remove the Power Chart props.pens object by script

**URL:** <https://forum.inductiveautomation.com/t/add-or-remove-the-power-chart-props-pens-object-by-script/75498>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 24, 2023, 4:06pm UTC](https://forum.inductiveautomation.com/t/add-or-remove-the-power-chart-props-pens-object-by-script/75498 "2023-06-24T16:06:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cristian\_Gomez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cristian_gomez/32/49040_2.png) [@Cristian\_Gomez](https://forum.inductiveautomation.com/u/Cristian_Gomez)\
**Post date:** [June 24, 2023, 4:06pm UTC](https://forum.inductiveautomation.com/t/add-or-remove-the-power-chart-props-pens-object-by-script/75498/1 "2023-06-24T16:06:27Z")

</div>

Hi everyone  
I have a question about how is the syntax to execute the action to add or remove the props.pends object in a power chart from the script, I'm programming a button to add a path of history from a table already configured, what I need is to add this path to the pen, and likewise remove it, could you please give me an idea, is that so far I'm starting on this topic.  
Thank you very much

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [June 25, 2023, 3:01pm UTC](https://forum.inductiveautomation.com/t/add-or-remove-the-power-chart-props-pens-object-by-script/75498/2 "2023-06-25T15:01:18Z")

</div>

Adding a pen:

```auto
def runAction(self, event):
	history_provider = "QADB"
	tag_provider = "default"
	desired_name = "sine3"
	tag_path = "_symulation_/sine/sine3"
	desired_pen_color = "#00FF00"
    # Now, construct a historical source to refer to.
	source = "histprov:{0}:/drv:qa-robot:{1}:/tag:{2}".format(history_provider, tag_provider, tag_path)
	pen_shape = {
	  "visible": True,
	  "data": {
	    "aggregateMode": "default",
	    "source": source
	  },
	  "plot": 0,
	  "selectable": True,
	  "display": {
	    "interpolation": "curveLinear",
	    "breakLine": True,
	    "styles": {
	      "normal": {
	        "fill": {
	          "color": desired_pen_color,
	          "opacity": 0.8
	        },
	        "stroke": {
	          "color": desired_pen_color,
	          "width": 1,
	          "dashArray": 0,
	          "opacity": 0.8
	        }
	      },
	      "highlighted": {
	        "fill": {
	          "color": desired_pen_color,
	          "opacity": 1
	        },
	        "stroke": {
	          "color": desired_pen_color,
	          "width": 1,
	          "dashArray": 0,
	          "opacity": 1
	        }
	      },
	      "muted": {
	        "fill": {
	          "color": desired_pen_color,
	          "opacity": 0.4
	        },
	        "stroke": {
	          "color": desired_pen_color,
	          "width": 1,
	          "dashArray": 0,
	          "opacity": 0.4
	        }
	      },
	      "selected": {
	        "fill": {
	          "color": desired_pen_color,
	          "opacity": 1
	        },
	        "stroke": {
	          "color": desired_pen_color,
	          "width": 1,
	          "dashArray": 0,
	          "opacity": 1
	        }
	      }
	    },
	    "type": "line",
	    "radius": 3
	  },
	  "name": desired_name,
	  "axis": "",
	  "enabled": True
	}
	self.getSibling("PowerChart").props.pens.append(pen_shape)

```

Removing the pen:  
There are multiple ways to go about this, but essentially you'll want to remove whichever pen entry has the source you want to remove.

```auto
def runAction(self, event):
	history_provider = "QADB"
	tag_provider = "default"
	tag_path = "_symulation_/sine/sine3"
	source = "histprov:{0}:/drv:qa-robot:{1}:/tag:{2}".format(history_provider, tag_provider, tag_path)
	for i in range(len(self.getSibling("PowerChart").props.pens)):
		if self.getSibling("PowerChart").props.pens[i].data.source == source:
			del self.getSibling("PowerChart").props.pens[i]

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 20, 2023, 1:53am UTC](https://forum.inductiveautomation.com/t/add-or-remove-the-power-chart-props-pens-object-by-script/75498/3 "2023-08-20T01:53:25Z")

</div>

I would like to define different pen colors. I see some code examples that creates random colors...

```auto
from random import randint
colors = []

for i in range(10):
    colors.append('#%06X' % randint(0, 0xFFFFFF))
    
print colors

```

... but I was hoping for a consistent approach, where pen 1 is always a certain color, pen 10 is always a certain color, etc.

I know I could define a list and refer to that, but was wondering if a method already existed to do this automatically. Thoughts?
