LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing type of array in a script

Solved!
Go to solution
I have a script which uses a template to generate its code. So far i have a refnum to an array of doubles (the default type of the array in the template). Now, i need to change the element types of the array. I tried the 'set array' vi in the VariantDataType utilities, but that doesn't work. How do i do this? Smiley Indifferent
0 Kudos
Message 1 of 7
(3,197 Views)
Solution
Accepted by topic author Gordal

Here is one way.

 

ChangeArrayRepresentation.png 

Message 2 of 7
(3,186 Views)

Get a reference to the array element, cast it to the more specific type numeric.  Write to its Representation property node.

 

Of course the array will have to be in a different VI then the one that is the script you are running because that property node can only be used on a VI that is in edit mode.

 

Edit:  Darin beat me to it.

 

Message Edited by Ravens Fan on 04-14-2010 11:04 PM
Message 3 of 7
(3,184 Views)
Woops, just realized that was the wrong thing. I actually wanted to change the array to an array of arbitrary type, not just numeric. And the 'type' should be retrieved from a gobject refnum of arbitrary type, which is the input of the vi script.
0 Kudos
Message 4 of 7
(3,156 Views)

You're not asking for much, are you?  Why do you want to do all this in scripting?

 

You can do an Invoke Node on the reference to the array element and use the Replace method.  (There is also a Replace No Attributes method.)  I don't know what is the best way you can handle the "arbitrary type" requirement.  There is a long list of items you can choose from for the Style input.  And the path input could let you choose your own typedef controls.

0 Kudos
Message 5 of 7
(3,149 Views)

A slightly different approach, I assume the GObject is a ControlTerminal, depends on the details of what you are doing.  This simply empties the array and puts the GObject into the array.  You may add Copy/Paste operation if you want to just duplicate the object instead of moving it.

 

ChangeArrayType.png 

0 Kudos
Message 6 of 7
(3,145 Views)

Thanks, i'll give this a shot.

The reason I want to do this is because ive been experimenting with xnodes and what i need to do is create a queue with a maximum length, basically i push something on and something pops off the end if its reached maximum length, otherwise it increases the size. I have everything working, have the template, type propagation, etc, but i just needed to figure out how to change the array type of the internal array which is the queue to match the users data type input. 

 

 

 

0 Kudos
Message 7 of 7
(3,127 Views)