From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

3D surface plot image handled by IronPython as a batch operation

Solved!
Go to solution

Hi, All

 

I wrote a data acquisition package based on the Measuresurement Studio 2012. In the package the data can be interactively displayed in 3D graphics (not intensity image) by CW3DGraph activeX component. Because we are doing a process and take images every 5 second, so the whole process will have a few thousand images. I implemented IronPython im my C# application (Measurement Studio in C#), and trying to use the IronPython script to handle files in batch mode. However, when I try to create the class from the script, error message shows like:

 

"ActiveX control '2afa9f10-0b6a-11d2-a250-00a024d8324d' cannot be instantiated because the current thread is not in a single-threaded apartment."

 

Here are the class:

public class plr3DImage

{

public plr3DImage()

{

Initialize();

}

[STAThread]

private void Initialize()

{

#error msg at the following line

AxCW3DGraphLib.AxCWGraph3D graph3D = new AxCW3DGraphLib.AxCWGraph3D();

graph3D.CreateControl();

}

}

 

 

please note that I have already add a [STAThread] before the method to inform the enviroment will be Single Thread Appartment.

 

Anybody can tell me how to get around the problem? Thank you in advance.

 

Dufei

0 Kudos
Message 1 of 4
(3,361 Views)
Solution
Accepted by topic author dffang

Thank you for your quick response. I came cross these web pages. In fact, the answers to the qestion in the first web page, helped me out, and it worked around the problem. Here are the skeleton of the code.

 

using System.Threading;

 

public class My3DImage

{

   private Thread T;

   # some other private variables

   public My3DImage()

   {

         #some component initiate, execept the CWGraph3D ActiveX component.

   }

   public void SetParameters( #some other parameters in order to generate the 3D image)

{

      #this public method mainly used to transfer the parameters. There might be    some other good ways to pass the parameters

}

   private void Create3DImage()

  {

       AxCW3DGraphLib.AxCWGraph3D graph3D = new AxCW3DGraphLib.AxCWGraph3D();
       graph3D = new AxCW3DGraphLib.AxCWGraph3D();
       graph3D.CreateControl();
       graph3D.BeginInit();
       //set up 3D graph display
       graph3D.Size = new System.Drawing.Size(iwidth, iheight);
       graph3D.EndInit();  

       ...

       ...  # do the real data plotting job

       ...

       graph3D.ControlImage().Save(FullFileName, ImageFormat);

  }

  public void Save3DImage()

{

       T = new Thread(Create3DImage);

       T.SetApartmentState(ApartmentState.STA);

       T.Start();

       T.Join();

}

}

 

Then in the loop of file handling in IronPython script, we call SetParameters(...) first and then Save3DImage, it will do the job.

 

Thank you again!

0 Kudos
Message 3 of 4
(3,312 Views)

Sorry in my previous email the line in the code

 

graph3D = new AxCW3DGraphLib.AxCWGraph3D();

 

is not necessary and it is wrong.

0 Kudos
Message 4 of 4
(3,311 Views)