# How to Bind Line Width (a part of Stroke Style)?

**URL:** <https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194>\
**Category:** Ignition\
**Created:** [July 2, 2015, 2:20pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194 "2015-07-02T14:20:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cezipper](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cezipper](https://forum.inductiveautomation.com/u/cezipper)\
**Post date:** [July 2, 2015, 2:20pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/1 "2015-07-02T14:20:49Z")

</div>

I want to bind the line width to an integer. When I try to bind the style I get an error that Long is not assignment -compatible with the property type (Stroke). I can not find anything in help or on this forum on how to generate a stroke type (or modify just the pen width once I have one) in scripting or expressions.

I understand I can create a line with the stroke I want, make it invisible and then programmically copy that stroke style when needed, but is there another way?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 2, 2015, 8:45pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/2 "2015-07-02T20:45:23Z")

</div>

Hi!

The Stroke Style is a java.awt.BasicStroke construct. From the [docs.java.com](http://docs.oracle.com/javase/7/docs/api/java/awt/BasicStroke.html#createStrokedShape%28java.awt.Shape%29):

[This website](http://docstore.mik.ua/orelly/java-ent/jfc/ch04_05.htm) has a pretty fair explanation of the different style options.

I made up a window that illustrates all five methods. That way, you can decide case-by-case what will work best for you. 🙂  
[Stroke Styles Demo\_2018-11-05\_0746.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/895f3d53fe92ade1576c0f686ed3f22ea5af77f7.proj) (16.3 KB)

Project scripts for construction or inspection. Described in posts below.  
[stroke\_2017-08-01\_0533.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/72bf07d771e17779f42c4cfcc1564941de56bb1d.proj) (1.9 KB)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/85b88f3c3beb7c5dbf2299043299e8a59f86fed8.png)

EDIT: File re-uploaded… again… 😕

---

<div class="post-metadata">

**Author:** ![Chris\_Taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_taylor/32/3315_2.png) [@Chris\_Taylor](https://forum.inductiveautomation.com/u/Chris_Taylor)\
**Post date:** [July 3, 2015, 11:01am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/3 "2015-07-03T11:01:13Z")

</div>

Oooooh, I’m gonna need that on the next project, thanks Jorden

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 13, 2016, 10:13pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/4 "2016-03-13T22:13:52Z")

</div>

Hi,

The above posted project example is great for scripting, but i was hoping to just use a simple expression binding to change stroke style from solid line to dashed based on a simple case statement.

Are you able to explain how to do this in Ignitions Expression binding? Unfortunately you cant use the BasicStroke component in an expression script.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 14, 2016, 5:02am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/5 "2016-03-14T05:02:03Z")

</div>

[quote=“richardNZ15”]Are you able to explain how to do this in Ignitions Expression binding? Unfortunately you cant use the BasicStroke component in an expression script.[/quote]Put the code in a script module and call it from runScript().

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2016, 1:41pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/6 "2016-03-14T13:41:34Z")

</div>

[quote=“richardNZ15”]Hi,

The above posted project example is great for scripting, but i was hoping to just use a simple expression binding to change stroke style from solid line to dashed based on a simple case statement.

Are you able to explain how to do this in Ignitions Expression binding? Unfortunately you cant use the BasicStroke component in an expression script.[/quote]

You can’t. Not because it’s not a great idea, but because there is no Stroke datatype that is readily available (like in a custom property). This means you would need to construct the stroke through a script, and by the time you do that, you may as well write it to the style.

You can, however, bind the Stroke Styles of several components together, so that you would only need to change one to get them all.

Attached is a window closer to what you’re looking for. You can bind the “UseDash” property on the left-hand line to whatever you wish to turn the dashes on/off. The right-hand line has no custom properties, and binds its stroke style to that of the left-hand line. The heavy lifting is done by a propertyChange Script looking for a change in any of the custom properties. I present it this way to keep things all in one file.

Phil’s suggestion is great when you have a lot of different objects you need to affect in a lot of different places. More on that in a bit, as I have a meting to run to.

EDIT: Re-uploaded files

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2016, 7:22pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/7 "2016-03-14T19:22:34Z")

</div>

Wow. Meetings: where minutes are taken and hours are wasted… heh. 😒

Now, going back to Phil’s suggestion about using a script module:

Here’s a script set you can use to construct and inspect strokes:  
[stroke\_2017-08-01\_0533.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/72bf07d771e17779f42c4cfcc1564941de56bb1d.proj) (1.9 KB)

Let’s say you import this into a project. The scripts will be called project.stroke.construct() and project.stroke.inspect()

project.stroke.construct([lineWidth, [cap, join, [miterLimit, [dashPatern, dashPhase]]]])

This will check the number of arguments given and act according to the BasicStroke docs.

A note about dashPattern: This must be a string representation of a tuple. Example: ‘(5,5,15,5)’ with quotes.

To use this with runScript(), an example may look something like:

`switch(toInt({Root Container.CheckBox.selected}),
       0,1,
       runScript("project.stroke.construct()"),
       runscript("project.stroke.construct",0,3,0,0,10,'(5,5)',0),
       runScript("project.stroke.construct()")
       )`

If you look at the second runScript instance, you see there’s an extra argument. This is because runScript uses the first argument for polling, if needed, followed by the arguments for the stroke style.

A lot of information coming in a relatively short time, but the possibilities are there!

EDIT re-uploaded files

Regards,

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 17, 2016, 12:52am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/8 "2016-03-17T00:52:02Z")

</div>

Awesome replies, thank you! ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:") I’ll have a look through those demos, but seems like that will all work just fine.

It’s funny the things I come across in Ignition that you just cant do (easily) that you would expect you could. (such as setting X,Y and size properties of some components)

---

<div class="post-metadata">

**Author:** ![cezipper](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cezipper](https://forum.inductiveautomation.com/u/cezipper)\
**Post date:** [August 28, 2016, 9:01am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/9 "2016-08-28T09:01:54Z")

</div>

Okay, I understand (with the help of the BasicStroke document) how to control stoke details in script. Now I want to do a similar thing for the fill paint with multiple gradient settings. Do you have the details on how I can build the data type:

com.inductiveautomation.ignition.client.util.gui.paints.RelativeLinearGradientPaint

I can get the color array and the fractions array but I can not modify them as they are read only. I can make a java.awt.GradientPaint, but that is not as flexible.

---

<div class="post-metadata">

**Author:** ![cezipper](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cezipper](https://forum.inductiveautomation.com/u/cezipper)\
**Post date:** [August 28, 2016, 10:16am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/10 "2016-08-28T10:16:13Z")

</div>

okay, I thought I could use java.awt.GradientPaint. It worked great in designer, until I went to save it. It could not save the shape with a fill of type “GradientPaint”. I was so close! I spent hours on it before I realized it could not be saved. Please help me find a way to do this.

Please give me some way to make a com.inductiveautomation.ignition.client.util.gui.paints.RelativeLinearGradientPaint

Actually, it doesn’t have to be scripting. I am fine with binding, but I can’t figure out how to define the colors by binding in a gradient.

Thanks,

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 29, 2016, 12:34pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/11 "2016-08-29T12:34:16Z")

</div>

Should be similar to [this thread](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=13260), I’m thinkin’.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 1, 2017, 4:46am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/12 "2017-08-01T04:46:15Z")

</div>

Any chance you could re-post this attachment for the construct and inspect scripts? All attachments pre-new forum interface seem to have been culled…  
Cheers!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 1, 2017, 9:37am UTC](https://forum.inductiveautomation.com/t/how-to-bind-line-width-a-part-of-stroke-style/10194/13 "2017-08-01T09:37:15Z")

</div>

Being a code pack-rat has its upside… re-uploaded.

Thanks, @nminchin!
