04-03-2018 03:29 PM
Would someone please help me get the channel length of Channel 1 and write that property into a new Channel 2? I can get it to come up in a message box but I really want to write it to a new channel.
This is what I did to write it to a message box.
A = ChnPropGet("[1]/ChannelA", "length")
Call MsgBoxDisp(A)
Seems this should be very easy but for some reason I cannot make it work!
Thank you!
04-03-2018 03:32 PM - edited 04-03-2018 03:36 PM
Hi Karen,
Have you looked at this example about add new properties to a channel : http://zone.ni.com/reference/en-XX/help/370858N-01/procauto/procauto/procauto_set_new_properties_val... ? If in doubt, you can do it manually first with the Recording Mode enabled so that the script is generated automatically 😉
I hope I did not misunderstand your problem. Do not hesitate to ask if something is unclear.
04-03-2018 03:38 PM
Thank you however this did not help me. I'm not that experienced in scripting so that may be why! If possible would someone just provide the lines of code? I have wasted a lot of time trying to figure this out looking at info in help and on this forum...
04-03-2018 03:52 PM
I guess that would be something like :
Data.Root.ChannelGroups(1).Channels(2).Properties.Add("New Property",MyPropertyValue,DataTypeString);
Replace MyPropertyValue by the variable you use to store the first channel length.
Once again, it is just a guess you may need to do some more edits according to the script you have.
If you do know how to use the script, learn step by step. Using the Recording Mode is a good way to get there : http://zone.ni.com/reference/en-XX/help/370858N-01/procscript/procscript/procscript_recording_autose...
😉
04-03-2018 04:28 PM
Well I can't get this to work either. I do use the recording mode a lot but for some things such as this it does not work for!
04-03-2018 05:25 PM
My questions :
I am unsure what you mean by "but for some things such as this it does not work for". I mean, I am pretty sure the Recording Mode works just fine when you add a new custom property to a Channel. Have you tried this ?
This method will create a new channel in the specified group and add a new property to that channel which will have the same value as "Length" in Channel1.
Does it do what you want ?
04-04-2018 01:36 AM
Use the API to create a new channel and use the "values" attribute of the channel object.
Option Explicit dim chO : set chO = data.Root.ChannelGroups(1).Channels.Add("channelLength",DataTypeFloat64) chO.Values(chO.Size + 1) = Data.Root.ChannelGroups(1).Channels("Time").Properties("length").Value
04-04-2018 09:58 AM
Andreas, Thank you so much this did exactly what I was looking for.
04-04-2018 10:01 AM
ML927,
Thank you for sticking with me! Your last thread did help however I didn't really want it in a custom property. Andreas's solution worked better because I need it to be a value rather than custom. Kudos to you both for your support!
04-04-2018 10:53 AM
Karen,
Sorry for understading your problem then 😉
Feel free to post again if you need help !