Chris Davis Posted October 25, 2006 Report Share Posted October 25, 2006 I got interested in Labview scripting recently, but had lots of trouble getting started. After reading the FAQ and activating scripting on my LV 7 install, I was at a loss on what to do, and how to do it. I started figuring things out and thought that I would share my simple examples so that others might have an easier time getting started with scripting. I have attached one example (LV 7.0) of a VI that creates a new VI with a control and an indicator on it. This new VI simply passes through the connection from control to indicator. It also connects the control to the upper left (input) side of the (4x2x2x4) connector pane, and the indicator to the upper right (output) side of the (4x2x2x4) connector pane. I know this example may seem pretty simple (and it is), but it does gather some basics that one needs to get started in scripting. Warning, this VI's diagram is long (left to right), but I wanted to make it look good and document it as best I could. Teaching others is the best way to reinforce what you have learned. Enjoy :thumbup: EDIT: Added second example showing how to create a VI to multiply two numeric controls together and produce the result in a numeric indicator. In this case the two inputs (X and Y) are connected to the two upper left connectors of the (4x2x2x4) connector pane and the product is connected to the upper right connector of the (4x2x2x4) connector pane. Download File:post-2547-1161747922.vi Download File:post-2547-1161750384.vi Quote Link to comment
JDave Posted October 25, 2006 Report Share Posted October 25, 2006 That is a really nice example VI. :thumbup: I have found scripting to be fun and rewarding, but it is quite an undocumented jungle to deal with. This makes a nice path. David p.s. Yes, I know. Very droll. Quote Link to comment
Chris Davis Posted October 25, 2006 Report Share Posted October 25, 2006 Thanks David, I was hoping someone would get something out of this VI (now these VIs). It took me a couple of nights to get them right, and understand what was going on, so I thought I would document everything thus far, just to make it easier to pick it up, if I have to lay it down for a while. p.s. Yes, I know. Very droll. Took me a minute but, Quote Link to comment
Michael Aivaliotis Posted October 25, 2006 Report Share Posted October 25, 2006 Thanks David, I was hoping someone would get something out of this VI (now these VIs). It took me a couple of nights to get them right, and understand what was going on, so I thought I would document everything thus far, just to make it easier to pick it up, if I have to lay it down for a while.It's a pleasure to see a LAVA member comming forth and contributing tutorial\example type material. Hmm, perhaps we should open up a Scripting category in the Code Repository... :thumbup: . This code Should go there under an "examples" subcategory. Quote Link to comment
Ton Plomp Posted October 25, 2006 Report Share Posted October 25, 2006 It's a pleasure to see a LAVA member comming forth and contributing tutorial\example type material. Hmm, perhaps we should open up a Scripting category in the Code Repository... :thumbup: . This code Should go there under an "examples" subcategory. I thought this would be better for the Knowledge Base? Ton Quote Link to comment
crelf Posted October 25, 2006 Report Share Posted October 25, 2006 I thought this would be better for the Knowledge Base?Ton Yep - I'd love to see a bunch of KBs on scripting and, for several reasons, LAVA's the perfect place! Quote Link to comment
Chris Davis Posted October 25, 2006 Report Share Posted October 25, 2006 I'd like to make more examples, and posting them to a single place would be helpful in the future when we want to point someone to a complete consise example of how to get started with scripting. I know the code repository has methods to source code control. What about the knowledge base? Quote Link to comment
rpursley Posted October 25, 2006 Report Share Posted October 25, 2006 Here are two that I added to my project folder that allows you to highlight a broken wire and update the indicator to match the type on the other side of the broken wire and update an input to a subvi to match a broken wire. In the first one you highlight the broken wire. In the second one you highlight the subvi. They also keep the connection on the connector pane. It has been really useful for me in two situations. 1. When updating after making changes to a cluster. 2. When creating a new vi using an already created vi as a template They are for LV 8.20. Feel free to make suggestions and/or improvements to increase usability. Download File:post-1423-1161783353.vi Download File:post-1423-1161783380.vi Quote Link to comment
Mike Ashe Posted October 25, 2006 Report Share Posted October 25, 2006 :worship: Hey Chris, great examples! I heartily agree with the kudos others have been giving as well as the ideas for more. As a small incremental addition I came up with two small items to make the connector pane selection a little more intuitive and get rid of the need for the big graphic of the connector panes. This is a Connector Pane constant. The VI is below. If you add it into your paletes with the VI set with the merge option you will get the constant on your diagram. Click on the constant and you'll get the pattern menu as shown: (LV 7.1) Unfortunately the constant only goes from 0-35, so we need to add 4800 to the number as shown, so I made another simple VI to do that. Both VIs are in LabVIEW 7.1 Download File:post-45-1161803666.vi Download File:post-45-1161803706.vi Cheers Quote Link to comment
Chris Davis Posted October 25, 2006 Report Share Posted October 25, 2006 :worship: Hey Chris, great examples! I heartily agree with the kudos others have been giving as well as the ideas for more. Both VIs are in LabVIEW 7.1 Mike, Thanks for the addition, I'd like to add it to my VI's, but I need them saved as LV 7.0. I'm doing this work on a machine that only has LV 7 installed. I'll add them to my post and zip everything up to make it easier to download. Thanks, Chris Quote Link to comment
Mike Ashe Posted October 25, 2006 Report Share Posted October 25, 2006 I'd like to add it to my VI's, but I need them saved as LV 7.0. I'm doing this work on a machine that only has LV 7 installed. I'll add them to my post and zip everything up to make it easier to download. The machine I'm on only has 7.1 so I'll convert to 7.0 and 8.x later and substitute & add. Fine by me if you want to combine, but might I suggest that we consider moving/copying all this into the code repository later. One last note, your tutorial is great, but lets all keep the real goal in mind, which many of us have stated over and over: we want to end up with something that can eventually convert a VI to text and then recreate it from that text. Then again, I'm not sure how much work we want to put into this, I'd be pretty surprised if NI doesn't already have this in-house. Be a bummer to put in all the work and then have NI release it. Then again, NI might not release ... What do the rest of you think? Quote Link to comment
Chris Davis Posted October 25, 2006 Report Share Posted October 25, 2006 The machine I'm on only has 7.1 so I'll convert to 7.0 and 8.x later and substitute & add.Fine by me if you want to combine, but might I suggest that we consider moving/copying all this into the code repository later. One last note, your tutorial is great, but lets all keep the real goal in mind, which many of us have stated over and over: we want to end up with something that can eventually convert a VI to text and then recreate it from that text. Then again, I'm not sure how much work we want to put into this, I'd be pretty surprised if NI doesn't already have this in-house. Be a bummer to put in all the work and then have NI release it. Then again, NI might not release ... What do the rest of you think? I'm thinking that a code repository entry is needed with entries in the knowledge base referencing these examples for dicussion. Quote Link to comment
Mike Ashe Posted October 25, 2006 Report Share Posted October 25, 2006 I'm thinking that a code repository entry is needed with entries in the knowledge base referencing these examples for dicussion. Very good idea. Regarding my ConPane Constant and the graphic. Although I made it (in part) to get rid of the need for the big graphic of the panes I think you might want to leave the graphic in your examples as a teaching tool and also include another one from the forums here that also shows the pattern order of the conpane terminals. Can't seem to find it right now. Also you might want to include mballa's Picture Ring Control that also does the connector pattersn. That post is: here Quote Link to comment
Chris Davis Posted October 26, 2006 Report Share Posted October 26, 2006 One last note, your tutorial is great, but lets all keep the real goal in mind, which many of us have stated over and over: we want to end up with something that can eventually convert a VI to text and then recreate it from that text. I'd like to see this happen too, but I know it will take a long time to get right. It led me to start this thread and create the examples. Before a text->VI parser could be written, I thought some scripting examples would be needed, since those who might be good at the parsing might not be good at understanding the scripting side of LV. Quote Link to comment
Michael Aivaliotis Posted October 26, 2006 Report Share Posted October 26, 2006 I thought this would be better for the Knowledge Base?Knowledge base is for material that is in mostly text and tutorial oriented. It could also be white paper type material. The code attached in the knowledge base is there to supplant the article.Example code goes in the code repository. Yep - I'd love to see a bunch of KBs on scripting and, for several reasons, LAVA's the perfect place! There is already a scripting category here. The nice thing about knowledge base articles is that a single document can live and breath by many contributors. It's better than a forum thread because it evolves as one continuous stream of data-flow consciousness. . So all it takes is for someone to start an article and then others can augment it. It's like wiki because there is revision control of the article. If someone screws up I can go back to a previous revision.I'd like to make more examples, and posting them to a single place would be helpful in the future when we want to point someone to a complete concise example of how to get started with scripting. I know the code repository has methods to source code control. What about the knowledge base? Here is the single place for VI Scripting examples... Please upload your code there. For now, please prefix the submission name with the word: "Example - " Articles and write-up, how to's, should go in the knowledge base. I have added links to both KB and CR at the top of the VI scripting forum here. Hey, look out, I'm facilitating ova eea..! Then again, I'm not sure how much work we want to put into this, I'd be pretty surprised if NI doesn't already have this in-house. Be a bummer to put in all the work and then have NI release it. Then again, NI might not release ...What do the rest of you think? I think we have some very talented people here who are interested in being a part of something cool. Go with the flow.Thanks for the addition, I'd like to add it to my VI's, but I need them saved as LV 7.0. I'm doing this work on a machine that only has LV 7 installed. I'll add them to my post and zip everything up to make it easier to download.I think we should submit things individually for now. It makes it easier to reference specific examples with a link and is easier to search. The more resolution the better.I'm thinking that a code repository entry is needed with entries in the knowledge base referencing these examples for discussion.I agree. Also, to wrap up my input into this. In all instances, If you are just submitting code to LAVA to show people what you've done or just want others to use your stuff, I strongly recommend putting it in the code repository. Code submission within discussion threads should be limited to situations where you want to demonstrate a point, show your problem, bug reports etc. If you just want to submit code, please use the Code Repository. Every entry in the code repository Automatically gets a forum thread assigned to it anyway, so discussions on the code can continue there. Please make sure you follow the guidelines for submission, we like clean documented code here. This isn't the LabVIEW Zone you know... Quote Link to comment
Chris Davis Posted October 26, 2006 Report Share Posted October 26, 2006 I'll begin the process to submit my code to the code repository. Look for new code there. Thanks for setting this all up Michael! Quote Link to comment
Barrie Posted October 26, 2006 Author Report Share Posted October 26, 2006 I'd like to make more examples, and posting them to a single place would be helpful in the future when we want to point someone to a complete consise example of how to get started with scripting. I know the code repository has methods to source code control. What about the knowledge base? This is a great example for me because it shows that I am missing something fundamental. I have poked around scripting a bit, but never got very far. Now I think I know why. I have modified my .ini and can now see lots of new toys, but when I try to re-create Chris' vi, the Method "Create Constant or Control" is not exposed. It appears that I'm only getting part of the picture. I'm feeling kinda dumb right now, anyone care to enlighten me? Cheers! Quote Link to comment
Chris Davis Posted October 26, 2006 Report Share Posted October 26, 2006 If your user info is true and you are using 8.2 you may be out of luck. I think parts of scripting were closed after 7.1.x. I'm still using 7.0. You might try copying the create constant or control out of my example and pasting it in your code to see if it works. BTW, don't feel dumb. I wanted to know more, and so I had to devote some more time and effort. This is not a casually learned topic. Althought with my examples, I hope to make it easier to get started learning the basics. Quote Link to comment
Barrie Posted October 27, 2006 Author Report Share Posted October 27, 2006 If your user info is true and you are using 8.2 you may be out of luck. I think parts of scripting were closed after 7.1.x. I'm still using 7.0. You might try copying the create constant or control out of my example and pasting it in your code to see if it works.BTW, don't feel dumb. I wanted to know more, and so I had to devote some more time and effort. This is not a casually learned topic. Althought with my examples, I hope to make it easier to get started learning the basics. Thanks Chris! Just to confirm, your VI runs fine in 8.x and cut-and-paste does as well. Phew! I feel better now. I re-loaded both 7.0 and 7.1 and voila! everything is there. At first glance, there is a HUGE difference in what is exposed between 7.x and 8.x but there is also a big difference in VI server as well, so maybe there is a different paradigm. I think part of the change is the because "create constant or control" is no longer truly valid after the addition of the pane. I notice that that method is shown in red in 8.20, which means ???? deprecated??? Wiring a pane reference to "create constant or control" does NOT solve the problem. Makes you wonder if the shipped LV is different now from the NI internal dev version or if there are new functions not visible on the palette (like New VI Object) or if there is an new, better hidden .ini key or ???? Until these mysteries are revealed, I guess the only approach is to develop the functions in 7.x and then open them in 8.x to take advantage of other new features. As an aside, until now, the additional properties and methods were just a curiosity for me, but I see XControls as a really great feature that is fairly tedious to implement, particularly if you want to add a lot of properties or methods to the control. I think scripting could really simplify this. NI probably has this in the works, but that's the risk one takes. Cheers! Quote Link to comment
Mike Ashe Posted October 28, 2006 Report Share Posted October 28, 2006 If your user info is true and you are using 8.2 you may be out of luck. I think parts of scripting were closed after 7.1.x. I'm still using 7.0. You might try copying the create constant or control out of my example and pasting it in your code to see if it works.BTW, don't feel dumb. I wanted to know more, and so I had to devote some more time and effort. This is not a casually learned topic. Althought with my examples, I hope to make it easier to get started learning the basics. One option is to put a node alone on a VI, save, then set to merge in the paletes. We have discussed creating an open source paletes of the scripting nodes like this several times. OpenG has a couple, but not a lot. Maybe we could start that as part of this thread. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.