It would be nice to be able to optionally reference other views via a relative path in the path prop. For example, in this image if we could reference ‘./Realistic’ instead of ‘Components/Pump/Symbol/Realistic’ I could then rename the folder or move everything to a different folder without breaking the references.
Hacky workaround:
Bind the path
property with a property binding on any property (you actually need access to the transform part of the binding).
Add a transform to the binding.
Supply the following script: return "/".join(self.view.id.split("/")[:-1]) + "/desiredViewName"
where “desiredViewName” is the name of the View you want a relative position of.
In this example, I bound against view.props.loading.mode
, but I don’t need that value - I just need the transform. Note the returned value in the binding dialog preview area.
With that binding in place, I was able to drag my something
directory around into different locations of my View directories and the references to other Views within the directory remained functional.
Perfect! I was attempting to implement a workaround like this and that self.view.id property is what I was looking for. That will get me going for now. Thanks!
I’ll suggest self.view.id[:self.view.id.rfind('/')]
, which avoids spliting and joining.
It might be less readable when dealing with this kind of variable, but this can easily be fixed by assigning the string to another var, which actually makes the whole thing more readable than the initial solution in my opinion:
Is this actually a bad solution ?
@pturmel, can the Integration Toolkit be used to execute this Python script?
"/".join(self.view.id.split("/")[:-1]) + "/desiredViewName"
where
is not a python keyword, and no amount of integration toolkit will change that.
What are you trying to do ?
I mean the .join.
The where was the comment which I mistakenly copy from original post.
So what you want is the expression equivalent of this python code ?
Sure, with objectScript
. But for best performance, I'd make a pure expression with groupConcat()
, where()
and split()
.
groupConcat(
transform(
forEach(
split({view.id}, '/'),
it()[0]
),
asPairs(
where(
value(),
idx() < (len(value())-1)
),
asList(
'desiredViewName'
)
)
),
'/'
)
That's what I meant. Perfect. Thanks, Phil. Of course, the only reason I ask for this is the performance.
I just realized this is probably faster:
groupConcat(
transform(
split({view.id} + "/desiredViewName", '/'),
where(
value(),
idx() != (len(value())-2)
)
),
0,
'/'
)
Hi guys,
Nice solution for the reference. Is there also a way to make this kind of binding default on the embedded view?
For example If i use the embedded view 10 times in my view, i always have to make this binding manually. It's ok for myself but for others who may not know this is required, they may forget to do this and then then you have a mix of relative bindings and direct bindings to the embedded view which can result in unwanted result if you think you can freely move the view.
Better should be that this relative binding can be set as default on the path.
There are no default bindings anywhere in Ignition. You can copy and paste them. Also, duplicating a component duplicates its bindings.