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

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?

Hi!

The Stroke Style is a java.awt.BasicStroke construct. From the docs.java.com:

This website 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. :slight_smile:
Stroke Styles Demo_2018-11-05_0746.proj (16.3 KB)

Project scripts for construction or inspection. Described in posts below.
stroke_2017-08-01_0533.proj (1.9 KB)

EDIT: File re-uploadedā€¦ againā€¦ :confused:

1 Like

Oooooh, Iā€™m gonna need that on the next project, thanks Jorden

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.

1 Like

[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().

[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

Wow. Meetings: where minutes are taken and hours are wastedā€¦ heh. :unamused:

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 (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,

Awesome replies, thank you! :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)

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.

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,

Should be similar to this thread, Iā€™m thinkinā€™.

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!

1 Like

Being a code pack-rat has its upsideā€¦ re-uploaded.

Thanks, @nminchin!

2 Likes