Page 1 of 1

Access InstrumentsPanel from .pem-script - Solved

Posted: Mon 30. May 2022, 08:44
by bkiepke
Hello,

I need to automate a complex task. For that I have designed an Instrument Panel using the Add-In.

I now need to access some ValueEdit-items from a .pem-script file, but I can't get access to it.

Here is what I have done so far.

Code: Select all

Sub GetInstrumentPanel()
	'DESCRIPTION: Find instrument panel

	PrintToOutputWindow "GetInstrumentPanel - start"

	Dim panel
	Dim panel2
	
	Set panel = Documents.Item("PanelTest1.ipf") ' This is the caption of the InstrumentsPanel created before.
	Set panel2 = Documents.Add(peDocumentKindInstrumentsPanel) ' This is an example from the help file "Instruments Panel Documentation"

	PrintToOutputWindow panel.Name
	PrintToOutputWindow panel.Kind
	PrintToOutputWindow panel.Type

	PrintToOutputWindow panel2.Name
	PrintToOutputWindow panel2.Kind ' prints {DFAFFAC0-2F50-428E-824C-B97089CD5F3F} - so it is an IntrumentsPanel - right?
	PrintToOutputWindow panel2.Type
	PrintToOutputWindow panel2.Scenes.Count ' throws exception: Das Objekt unterstützt dies Eigenschaft oder Methode nicht.: 'panel2.Scenes' - so it is not an InstrumentsPanel 

	PrintToOutputWindow "GetInstrumentPanel - finished"
End Sub
What am I doing wrong here?

EDIT:

I think I found it! Refactored code for reference

Code: Select all

Sub GetInstrumentPanel()
	'DESCRIPTION: Find instrument panel

	PrintToOutputWindow "GetInstrumentPanel - start"

	Dim doc
	Dim panel
	
	Set doc = Documents.Item("PanelTest1.ipf") ' This is the caption of the InstrumentsPanel created before.
  	Set panel = doc.ActiveWindow.Object ' This is doing the trick, without this you just have a doc-object instead of an IntrumentsPanel-object
  	Set scene = panel.ActiveScene
	
	PrintToOutputWindow doc.Name
	PrintToOutputWindow doc.Kind
	PrintToOutputWindow doc.Type
	PrintToOutputWindow "Scenes: " & panel.Scenes.Count
	
	PrintToOutputWindow "GetInstrumentPanel - finished"
End Sub
Any additions?

Re: Access InstrumentsPanel from .pem-script

Posted: Mon 30. May 2022, 09:06
by PEAK-Support
If you already have created a Panel, you need to get the reference to this panel and then you can add / change / control items for this panel.

Here some simple samples, which shows how to use the Panel from VBS

Shows the Value from a exsiting ValueEdit:

Code: Select all

Sub ValueEditCommand()
  Dim panel, valEdit
  Set panel = Documents("Panel.ipf").ActiveWindow.Object
  Set valEdit = panel.Scenes(1).Controls("ValueEdit1")
  MsgBox valEdit.Value
End Sub
or here how to create at runtime a ValueEdit Control on a existing Panel.
using panel "Test.ipf"

Code: Select all

Sub CreateValueEdit()
  ' Create a new ValueEdit, and add a real Signal and set the Value
  Dim panel, ve
  Set panel = Documents.Open("Test.ipf").ActiveWindow.Object
  Set ve = panel.ActiveScene.Controls.Add(peControlTypeValueEdit)
  Set ve.Signal = Signals("Test.TestMux.TestVar")
  ve.Value = "123"
  panel.RunMode = True
End Sub
and here a simpley way to hide / show controlls of a existing panel, accept the button which we use to run this function.
Panel Name "VisibleTest.ipf"

Code: Select all

Sub ToggleControlsVisible()
  Dim wnd, scene, controls, ctrl, button
  Set wnd = Documents("VisibleTest.ipf").ActiveWindow
  Set scene = wnd.Object.ActiveScene
  Set controls = scene.Controls
  Set button = controls("ToggleButton")
  
  scene.LockUpdate True
  For Each ctrl in controls
    If ctrl <> button Then _
      ctrl.IsVisible = not ctrl.IsVisible
  Next
  scene.LockUpdate False
End Sub
If you like, send us a short e-mail to support[at]peak-system.com, with your License Information of the used PE6, and we will send you the projects where we used this sample codes.