DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

plot channel within script

Solved!
Go to solution

Hi Guys,

I have been using Diadem only for 1 month and I got great answers from this forum previously. This question may sound trivial but could someone tell me how to plot a channel by writing a script. So far I have this:

Call View.LoadLayout("view3") 
View.Sheets("Sheet 1").Areas("Area : 1").DisplayObjType = "CurveChart2D"
View.Sheets("Sheet 1").Cursor.Type = "Frame"
View.Sheets("Sheet 1").Cursor.Mode = "GraphPoints"

The only way I have found to import a channel to this area is to Call interactioOn(), import it manually then end the interaction. I would like to do this manually, I tried this but it would give errors:

View.Sheets("Sheet 1").Areas("Area : 1").DisplayObj.Curves.Add(1,3)

 Can anyone give me a hand?

 

Thanks

 

 

 

0 Kudos
Message 1 of 7
(8,689 Views)
Solution
Accepted by topic author Leillo

Hi Leillo,

 

Try this.

 

Call View.LoadLayout("view3") 
Set Sheet = View.Sheets(1)
Set Area = Sheet.Areas(1)
Area.DisplayObjType = "CurveChart2D" 
Set Graph = Area.DisplayObj
Call Graph.Curves.RemoveAll
Set Curve = Graph.Curves.Add(XChannelRef, YChannelRef)

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 2 of 7
(8,684 Views)

Hi Brad,

If I define previously "Sheet", "Area", "Graph" and "Curve" it works but now the rest of the script doesn't. After adding the channel there is an interaction where the user selects the part of the graph he want to keep using a band cursor, now that section is not working as when I end the interaction I get an empty channel. Could you please have a look at the script and let me know if you see the problem? I guess I have to change the way R4, R5, R6 & R7 are defined but I don't know how to do it. This script has the changes you told me to do and I comented the 3 lines of code that your solution replaces.

 

Thanks,

Leo

Option Explicit  'Forces the explicit declaration of all the variables in a script.
 
'-------------------------------------------------------------------------------
Call Data.Root.Clear() 'Clear the dataroot

'-------------------------------------------------------------------------------
'--------------- Loads Dialog box to select TDM file ---------------------------
'-------------------------------------------------------------------------------

Dim MyFileNames, iCount, Sheet, Area, Graph, Curve
Call FileNameGet("ANY", "FileRead", DataReadPath, "TDM data (*.tdm),*.tdm", "All.lst", True, "Data selection")
MyFileNames = Split(FileDlgFileName,"|")
For iCount = 0 To Ubound(MyFileNames)
  Call DataFileLoad(MyFileNames(iCount))
Next

Call View.LoadLayout("view3")
Set Sheet = View.Sheets(1)
Set Area = Sheet.Areas(1)
Area.DisplayObjType = "CurveChart2D"
Set Graph = Area.DisplayObj
Call Graph.Curves.RemoveAll
Set Curve = Graph.Curves.Add("time","velocity")
'View.Sheets("Sheet 1").Areas("Area : 1").DisplayObjType = "CurveChart2D"
'View.Sheets("Sheet 1").Cursor.Type = "Frame"
'View.Sheets("Sheet 1").Cursor.Mode = "GraphPoints"


'-------------------------------------------------------------------------------
' Shows View panel, allows customer interaction for choosing two Data channels - 
'---------------- and selecting two Frame cursor positions ---------------------
'-------------------------------------------------------------------------------

WndShow "View"

'-------------------------------------------------------------------------------
'- End interaction with File > End iteraction or by , or the appropriate button-
'- on the toolbar to disable the interaction mode (hand with red stop button) --
'-------------------------------------------------------------------------------

call msgboxdisp("Select Channel data and drag it onto the View panel")
call msgboxdisp("Select 2 cursor position leaving between the cursors the desired part")

Call InteractionOn()                            'Allows for customer interaction to load data & select two cursor positions

'-------------------------------------------------------------------------------
'------------------------- Calculates Cursor data ------------------------------
'-------------------------------------------------------------------------------

R4 = view.Sheets("Sheet 1").Cursor.X1           'Cursor 1 X position
R5 = view.Sheets("Sheet 1").Cursor.X2           'Cursor 2 X position
R6 = view.Sheets("Sheet 1").Cursor.Y1           'Cursor 1 Y position
R7 = view.Sheets("Sheet 1").Cursor.Y2           'Cursor 2 Y position

'-------------------------------------------------------------------------------
'--------------- Stores Cursor data into the new channel groups ----------------
'-------------------------------------------------------------------------------

Dim Chlength,Chnumb,i
Chlength=CL(1)'CL calculates the channel lenght 
'call msgboxdisp(Chlength,"MB_OK", "MsgTypeWarning",, 4)
Chnumb= ChnNoMax'Calculates the number of channels
For i=1 to Chnumb
  if R5>R4 then
    Call DataBlDel(i,R5,Chlength)
    Call DataBlDel(i,1,R4)
  else
    Call DataBlDel(i,R4,Chlength)
    Call DataBlDel(i,1,R5)
  end if
Next


'-------------------------------------------------------------------------------
'-------------- Loads Dialog box for saving TDM file ---------------------------
'-------------------------------------------------------------------------------

scriptInclude("Save_File")

 

0 Kudos
Message 3 of 7
(8,665 Views)

Hi Leillo,

 

You're using X values in the ChnDelete() function, which operates using row numbers (integers only).  Try this instead:

 

R4 = MinV(Sheet.Cursor.X1, Sheet.Cursor.X2)
R5 = MaxV(Sheet.Cursor.X1, Sheet.Cursor.X2)
R6 = MinV(Sheet.Cursor.Y1, Sheet.Cursor.Y2)
R7 = MaxV(Sheet.Cursor.Y1, Sheet.Cursor.Y2)

'-------------------------------------------------------------------------------
'--------------- Deletes unwanted data selected by VIEW cursors ----------------
'-------------------------------------------------------------------------------

Dim Chlength,Chnumb,i
Chlength=CL(1)'CL calculates the channel lenght 
'call msgboxdisp(Chlength,"MB_OK", "MsgTypeWarning",, 4)
Chnumb= ChnNoMax'Calculates the number of channels
For i=1 to Chnumb
  L4 = PNo(i, R4)
  L5 = PNo(i, R5)
  Call DataBlDel(i,L5, Chlength)
  Call DataBlDel(i, 1, L4)
Next

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 7
(8,654 Views)

Hi Brad,

 

When I do this I loose all the channels except the one I set on the X axis when I did "Set Curve = Graph.Curves.Add". I have more than 20 channel, from a log I took during a car maneuver. So I started logging just before the maneuver and stop just after. The purpose of this script is plot 2 channels, in this case Speed Vs. Time (Although before contacting you I just dragged the Speed into the plot) to help me to decide which part of the log in am interested in, but I want to keep every channel, not just the one on the X axis.

 

I have tried different combinations using your code but I haven't managed to get what I need. I think the problem is on the the way the plotting area has been defined but I have no idea how to solve it.

 

Do you have any other suggestions?

 

Thank you very much for your help and support.

 

Leo  

0 Kudos
Message 5 of 7
(8,633 Views)

Hi Leo,

 

I'm not making any sense out of your latest post.  The code I most recently sent you corrected the way you were deleting all data points outside the VIEW band cursor-defined time window, in all channels in the Data Portal.  The code I most recently sent you has nothing to do with which curves are plotted on the VIEW area.

 

What do you mean by "I loose all the channels except the one I set..."?  Do you mean that existing curves on the graph are removed from the configuration, or that the curves are still in the configuration and the channels are either gone from the Data Portal or empty of data values?

 

In a previous answer I sent you code to add a Spped vs. Time curve to a 2D Graph Area in VIEW, yet you say, "The purpose of this script is plot 2 channels, in this case Speed Vs. Time".

 

Please describe clearly what you want to achieve and what is currently missing.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 6 of 7
(8,622 Views)

Hi Brad,

 

I have just solved it. The problem was that I didn't know how to use "Set Curve = Graph.Curves.Add()" with just one channel (Speed on the Y axis and nothing on the X axis). R4 and R5 had to refer to the position of the value withing the channel and not to a value from another channel placed on the X axis in order to delete from the other channels their values from and to a given position and not from and to a given value from another channel.

 

Sorry I didn't expressed it correctly from the beginning. And when I read "XChannelRef" in "Set Curve = Graph.Curves.Add(XChannelRef, YChannelRef)" I didn't know how to use the function without leaving the XChannelRef in blank

 

Thanks for your help and sorry for my mistake

 

Regards,

Leo

0 Kudos
Message 7 of 7
(8,609 Views)