cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Adding Mathcad to TW

jsheehan
12-Amethyst

Adding Mathcad to TW

Mathcad is a windows executable (Like MS Word) but it has a COM based API callable from VB.NET, C#.Net, javascript, vbscript and more.

What would be the best way to create a TW service to launch Mathcad on the server.

 

example C# code to launch and load Mathcad, push and pull data

 

    private void Form1_Load(object sender, EventArgs e)

 

{

 

        {

 

 

            _mathcadPrimeApplication = new Ptc.MathcadPrime.Automation.ApplicationCreator();

 

 

 

 

 

        }

 

 

        private void openToolStripMenuItem_Click(object sender, EventArgs e)

 

 

 

        {

 

 

            string dirname;

 

            //lets find out where we are runing from and point our file open dialog to that directory.

 

            dirname = System.AppDomain.CurrentDomain.BaseDirectory;

 

 

 

            openFileDialog1.InitialDirectory = dirname;

 

            openFileDialog1.ShowDialog();

 

 

            try

 

 

 

            {

 

 

                _mathcadPrimeWorksheet = _mathcadPrimeApplication.Open(openFileDialog1.FileName) as IMathcadPrimeWorksheet3;

 

                _mathcadPrimeApplication.Visible = true;

 

 

 

                _mathcadPrimeInputs = _mathcadPrimeWorksheet.Inputs;

 

                _mathcadPrimeOutputs = _mathcadPrimeWorksheet.Outputs;

 

            }

 

 

            catch {

 

                MessageBox.Show("For some reason your Mathcad worksheet did not open \n Try again");

 

 

 

            }

 

           

 

 

            closeToolStripMenuItem.Enabled = true;

 

            textBox5.Enabled = true;

 

            textBox2.Enabled = true;

 

            textBox3.Enabled = true;

 

            textBox4.Enabled = true;

 

            button1.Enabled = true;

 

 

 

        }

 

 

        //Close the worksheet

 

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)

 

 

 

        {

 

 

            _mathcadPrimeWorksheet.Close(Ptc.MathcadPrime.Automation.SaveOption.spDiscardChanges)

 

 

 

 

 

 

            closeToolStripMenuItem.Enabled = false;

 

 

 

        }

 

 

        //Close the Mathcad Prime Application

 

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)

 

 

 

        {

 

 

            _mathcadPrimeApplication.Quit(Ptc.MathcadPrime.Automation.SaveOption.spDiscardChanges);

 

 

 

            Close();

 

        }

 

2 REPLIES 2

Hi John,

Considering you want to push/pull some data from a Mathcad worksheet, you have the following options:
1. Create a ThingWorx Extension (must be in JAVA), from which you instantiate the specific COM object there, OR, if you're more familiar with .NET, you can create a separate .NET DLL which does the logic, and then you use  JNI/JNA to call a from the JAVA the function from the .net DLL
2. You can even create a .NET implementation of the ThingWorx Edge Microserver, in which you do all your Mathcad logic. In this implementation you declare Properties and Remote Services, and then from the server you just call the Remote Function of the TWEMS or properties. You need to take care that this variant will produce basically an executable, which you'll need to run separately from the Tomcat instance where TW is running.

Not sure if this answers your question, but hope it's helpful !
Vladimir



Robert

Thanks for your reply. We took a slightly different approach. We built a web service running on IIS and talk to it in TWX as a service with REST API

TWX AEs have a prototype running in a Mashup...pretty cool

John

Announcements


Top Tags