I have some code that was performing the way I wanted it to but crashed a lot. Part of the code was creating objects inside of a while loop, which seems to be what was causing it to crash. I changed the code to create all of the objects outside of any loops, and this fixed the crashing but now the color assignment of the objects no longer works (I want the color to be dependent on whether or not an error is present in polled modbus data, so this needs to be evaluated inside of the while loop).
I've attached the 2 different versions of the code. The piece that used to control the color is called "Draw Tracker Position.vi" and is used in Tracker Decoder.vi.
Please let me know if you have any ideas of how I can make this work or if any other information would be helpful.
Solved! Go to Solution.
I looked at some of your code but couldn’t follow along very well. In the Draw Tracker Position VI, where is the error originating from? Once you have the error, you can use a case structure to change the functionality based on an error in. Below is a KB that talks about how to properly handle errors in LabVIEW. I also have included a KB about accessing an objects property’s.
Creating Properties and Methods
To be clear, I am not talking about LabVIEW errors -- I'm talking about errors on the modbus client that I'm polling. So I'm just monitoring a certain modbus register that reports errors and I want to control the color of the object based on the value in that register.
The concept is still the same and there are a couple ways to accomplish this. A case structure or a comparator node (select function) can handle the error from the polled Modbus data. You will need to know what is returned on an error and then present that in the appropriate way. For example, if the register returns 100, 200, and 300 as an error you can create those cases and change the object color in those cases. If the register returns (for example) the RPM of a motor, you can alter it with a simple select function if the RPM’s get too high. From there, you can follow the above instructions from the previous post to change the object properties. I am not familiar with the intricacies of your project, so if this is not a viable option more details would be needed to be provided. I have attached an example below.
Right, a case structure is how I had it working before. I have attached a screen shot of that case structure. The problem with this is that I have the color output of the case structure wired to CreateBox.vi, and it's inside a loop so it continues to create new boxes until it crashes. To solve this, I took the CreateBox.vi outside of the while loop.
I guess I over complicated my question with too much detail. My real question is: Is there a way to change the color of the box after the box has been created? Something that I can use inside a loop without causing it to crash.
I am sorry but I just am not understanding your question. I’m not sure what the “box” you are referring to is. Could you clarify this please? As I mentioned in my first post, you can alter the properties of an object with a property node or invoke node.
Creating Properties and Methods
I am not very familiar with boxes or objects, this is my first time using either. "Box" is not my term, the CreateBox.vi is in the 3D Picture Control menu under Geometries. This is just something that I somehow got working the way that I wanted it to based on trial and error and a few mildly related things I found on LabVIEW forums.
The graphic is just a very simple 2D graphic consisting of 3 "boxes". One is a black background, one is a thick line whose rotational position corresponds with the actual position of a solar tracker (this is the line whose color I want to control based on error status), and one is a thin line whose rotational position corresponds with the setpoint position of the solar tracker.
I am familiar with property nodes and invoke nodes, but those do not appear to be the answer here (at least with all of the clicking around I have done trying to get it to work). I would normally create a property node by right clicking the object on the front panel, but right clicking the graphic on the front panel does not allow me to select any of the components of the graphic individually and I don't see an appropriate property to control its color.
The same thing with invoke nodes: I'm using an invoke node to set the "drawable" ("box") for each object (again, I don't really know what I'm talking about here -- for some reason I got this working using 1 object and 1 "box" for each of the 3 components I mentioned -- background, thick line, thin line). I don't see any option in the invoke node that would allow me to control the color of the object.
I'll add a couple of screenshots that show the options I'm looking at for the invoke node as well as the the overall code I'm talking about where I'm setting up the 3 components, rotating the lines based on modbus values, and then combining the 3 components into a "scene". The code in the screenshots I'm attaching works exactly the way I want it to, but I need to figure out a way to preserve this functionality but move every instance of CreateBox.vi and CreateObject.vi outside of the main while loop so that it doesn't crash. Since the way I am currently setting the color of the thick line is an input to the CreateBox.vi, and the color of that line needs to be evaluated inside the loop, I don't know how to make that happen.
I hope this helps clarify things, I'm sorry I don't know enough about objects/boxes/scenes to communicate clearly here but thank you for sticking with me!
Oof, I just typed an eternal response and now it's gone. Sorry if you get multiple notifications.
"Box" is not my term, I am getting this from the 3D Picture Controls menu. The CreateBox.vi is under Geometries. This is my first time using boxes/objects/scenes and I don't know much about them, so I don't know how well I can explain my methodology here. It's just something that I somehow got working the way I wanted it to by trial and error and some things I found in mildly related threads on LabVIEW forums.
The graphic I want on the front panel has 3 components: (1) a black background, (2) a thick line whose rotational position reflects the actual position of a solar tracker and whose color reflects tracker error status (both of these parameters come from modbus data), and (3) a thin line whose rotational position reflects the setpoint position of the solar tracker. I was able to accomplish this by using a CreateBox.vi and a CreateObject.vi for each of these components and using an invoke node to set each box as a "drawable" for each object. The problem with doing it this way is that all of this code is inside the main while loop of the program and CreateBox.vi and CreateObject.vi run continuously taking up more and more memory until it crashes. If I move every instance of CreateBox.vi and CreateObject.vi outside of the main while loop and pass them through to the sub vis, it solves the crashing issue but I can no longer assign a color to the thick line because in my original version that color was an input to CreateBox.vi.
I am familiar with property nodes and invoke nodes, but those do not appear to be the answer here (as least as far as all of my clicking around trying to get it to work indicates). I would normally create a property node by right clicking on a front panel object. However, I don't believe there is a way to select a component of a graphic to apply a property node to. Right clicking on the graphic selects the entire graphic and the properties available are not appropriate for what I'm trying to do.
I am using an invoke node to set each box as a drawable for each object. When I wire the object to the invoke node, there is no option available that would allow me to control the color. I'll attach a screen shot of the options I'm looking at. If I could assign a color to an object with an invoke node, that would solve all of my problems.
I'll also include a screen shot of the entire subVI that I've been talking about -- this is what was in my original code that worked properly but crashed after a while. This is the code that evaluates error status in a case structure and outputs differerent color values, assigns that color to the thick line in the instance of CreateBox.vi for that line, and sets that line as a drawable in the object created for that line. It also creates an object and a box for each of the background and the thin line. Then it combines all 3 of these components into a scene. I want to preserve this functionality but move all instances of CreateBox.vi and CreateObject.vi outside of the main while loop. The problem with that is that the color must be evaluated inside of the while loop because it could change while the program is running, and the only way I have found to assign a color to a box is to do it when the box is created.
I hope this helps clarify things a bit, sorry I am only able to communicate as clearly as my very limited understanding of boxes/objects/scenes allows -- thank you for sticking with me! Please let me know if there is anything I can further clarify.
That was helpful in clarifying some confusion; thanks for that! I know of a couple examples and walkthroughs that should be of some help to you. You said that you normally right click the object on the front panel to create a property node – you can also pass a reference of the object into a property node in the block diagram (see example 2 & 3).
Invoke nodes are used for object methods and property nodes change properties. Since colors are properties, you would need a property node to change the color of the line. Hope the below examples get you moving in the right direction!
Changing Plot Color and Style of 3D Graph Using LabVIEW
Changing the Surface Appearance of a 3D Object
Creating Relationships between 3D Objects
Thank you! I think I'm really close here -- I was able to place a property node in my original version, wire the output of CreateBox.vi to it, and it allows me to control the color from there.
I'm still having a slight complication that I'm not sure how to address: it only works when the reference is to a box, not a drawable (and I really don't know what the difference is). However, when I moved CreateBox.vi outside of the subVI and made a control to wire in the reference, the control was made by right clicking on the input of the invoke node in the block diagram. This input expects a drawable, so now inside that subVI the reference is to a drawable, not a box. The property node for a drawable says that no properties are available. Is there a way to change the control to expect a reference to a box?
I also tried applying the property node to the object instead of the drawable and there is no color option there.
Links 2 and 3 are not working for me.
Edit in case someone reads this later: I added the property node with the quick drop menu (ctrl+space). That was what I didn't realize before that I could do.