Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have to use this code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;


namespace ROD_PISTON1
{
    public partial class Form1 : Form
    {
        private static Microsoft.Office.Interop.Excel.Workbook mWorkBook;
        private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
        private static Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
        private static Microsoft.Office.Interop.Excel.Application oXL;
        private static Microsoft.Office.Interop.Excel.Worksheet mWSheet2;
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = @"C:\Users\Dhaval\Desktop\BOOK1.xlsx";

            oXL = new Microsoft.Office.Interop.Excel.Application();

            oXL.Visible = false;

            oXL.DisplayAlerts = false;

            mWorkBook = oXL.Workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

            //Get all the sheets in the workbook

            mWorkSheets = mWorkBook.Worksheets;

            //Get the allready exists sheet

            mWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("INPUT");

            // Microsoft.Office.Interop.Excel.Range range = mWSheet1.UsedRange;
            //mWSheet1.Cells[3, 3] = comboBox1.Text;
            //mWSheet1.Cells[4, 3] = comboBox2.Text;
            //mWSheet1.Cells[5, 3] = textBox3.Text;
            //mWSheet1.Cells[6, 3] = textBox4.Text;
            //mWSheet1.Cells[7, 3] = textBox5.Text;
            //mWSheet1.Cells[8, 3] = textBox6.Text;
            //mWSheet1.Cells[9, 3] = textBox7.Text;
            //mWSheet1.Cells[10, 3] = textBox8.Text;
            //mWSheet1.Cells[11, 3] = textBox9.Text;
            //mWSheet1.Cells[12, 3] = textBox10.Text;
            //mWSheet1.Cells[13, 3] = comboBox3.Text;
            //("textBox"+i.ToString()).Text;

            mWSheet2 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("OUTPUT");

            Microsoft.Office.Interop.Excel.Range range = mWSheet2.UsedRange;

            double i = (mWSheet2.Cells[3, 3].Value2);
            textBox12.Text = i.ToString();

            double j = (mWSheet2.Cells[4, 3].Value2);
            textBox13.Text = j.ToString();

            double k = (mWSheet2.Cells[5, 3].Value2);
            textBox14.Text = k.ToString();
            mWorkBook.Save();
            mWorkBook.Close();
            Process p = new Process();
            p.StartInfo.FileName = "C:\\Users\\Dhaval\\Desktop\\ug\\rod.prt";
            p.Start();

        }
    }
}


now i have required to add below code


using System;
using NXOpen;

internal static class tmp
{
public static void Main()
{
Session s = Session.GetSession;
Part wp = s.Parts.Work;

foreach (Expression exp in wp.Expressions)
{
if (exp.Equation.Contains("ug_excel_read"))
{
var valeur = exp.Value;


echo("Expression: " + exp.Name + " has been unreferenced from external Spreedsheet, and is now equal to " + valeur);
}
}

}
public static void echo(string message)
{
ListingWindow lw = Session.GetSession.ListingWindow;
lw.Open();
lw.WriteLine(message);
}
public static int GetUnloadOption(string dummy)
{
return NXOpen.Session.LibraryUnloadOption.Immediately;
}
}

please give me suggestion how to add this code


Posted
Comments
karthik Udhayakumar 27-Jan-14 4:46am    
Can you explain where you want to add the code?
dhaval082 27-Jan-14 4:54am    
i add to button1_Click event

1 solution

You can't.
They aren't compatible at all: the code you have at the moment is WinForms, the code you want to add is web based.

WinForms applications do not have a Session, and your add-in code appears to use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900