NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

drag and drop to create a custom step

Solved!
Go to solution

Hi,

 

I have a custom insertion palette in my custom user-interface. I want to allow the user to drag the step from the custom insertion palette into the sequence designer, like the original insertion palette. The custom insertion palette is in WPF.

 

The data format for the drag and drop object is

e.Data.GetFormats()
  {string[1]}
    [0]: "SeqEditor New Step Binary"

 

The data is actually a MemoryStream:

e.Data.GetData(e.Data.GetFormats()[0])
  {System.IO.MemoryStream}
    base {System.IO.Stream}: {System.IO.MemoryStream}
    CanRead: true
    CanSeek: true
    CanWrite: true
    Capacity: 6936
    Length: 6936
    Position: 0

 

So it's actually some Unicode text if I read it with StreamReader:

new StreamReader((Stream)e.Data.GetData(e.Data.GetFormats()[0]),Encoding.Unicode).ReadToEnd()
"E@=3@JKZ100h\\L]JDYcLO7e9@FLU:h9iM]>5Uf16W>Hii091DHkYGJKJHMd[<...

 

What's the proper way for me to implement the drag and drop feature for my custom insertion palette? I'm thinking to create a similar MemoryStream but I can't understand the format of the data.

 

Thanks.

0 Kudos
Message 1 of 3
(2,820 Views)
Solution
Accepted by topic author ng chee meng

Please note that the clipboard format is not something we intend for users to create directly, and it might change in a future version of TestStand. So, if you do this, keep in mind it's possible it might not work in a future version of TestStand (i.e. we do not support creating clipboard items directly).

That said, it might be possible to get it to work in current versions of TestStand as follows (I haven't tried to do exactly what you are doing, but here is how our format is currently generated):

PropertyObject[] stepPropObjects = new PropertyObject[1];
Step newStep = templateOfStep.AsPropertyObject().Clone("", PropertyOptions.PropOption_CopyAllFlags | PropertyOptions.PropOption_DoNotShareProperties) as Step;
newStep.CreateNewUniqueStepId();
stepPropObjects[0] = newStep as PropertyObject;

DataObject dataObject = new DataObject();
DataFormats.Format stepFormat = DataFormats.GetFormat("SeqEditor New Step Binary");
string serializedPropertyObject = this.Engine.SerializeObjects(stepPropObjects, SerializationOptions.SerializationOption_UseBinary);
serializedPropertyObject += "F"; // False for isEditCut (thus unique ID's will be created on paste).
System.Text.UnicodeEncoding encodingForStrConv = new System.Text.UnicodeEncoding();
byte[] buffer = encodingForStrConv.GetBytes(serializedPropertyObject);
MemoryStream vvClipData = new MemoryStream(buffer);
dataObject.SetData(stepFormat.Name, false, vvClipData);

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 3
(2,814 Views)

Cool. The code is working good.

 

I understoof this is not an official feature. Thanks 🙂

0 Kudos
Message 3 of 3
(2,804 Views)