簡體   English   中英

Solidworks&Excel C#引用設計表

[英]Solidworks & Excel C# Referencing the Design Table

打開遇到麻煩的行時,我無法修改設計表,原因是var sheet =(Excel._Worksheet)swDoc.GetDesignTable; 本質上,我要它執行的操作是打開窗口,並引用活動表“設計表”。 該API確實包括“ DesignTable”作為類型。 我被困了一段時間。 任何幫助表示贊賞。

        //Open Solidworks Design Table
        SldWorks swApp;
        swApp = null;
        swApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application"));

        ModelDoc2 swDoc = null;
        bool boolstatus = false;
        swDoc = ((ModelDoc2)(swApp.ActiveDoc));
        boolstatus = swDoc.Extension.SelectByID2("Design Table", "DESIGNTABLE", 0, 0, 0, false, 0, null, 0);
        swDoc.InsertFamilyTableEdit();
        var sheet = (Excel._Worksheet)swDoc.GetDesignTable;

        //Generate Linear Guide Support in Solidworks
        if (comboBox1.Text == "0")//No External Rails
        {
           sheet.Cells[6, 4] = "0"; //Cell Location [y-axis, x-axis]
        }

弄清楚了

   using Excel = Microsoft.Office.Interop.Excel; //Excel Reference 

   public virtual Object ActiveSheet { get; set; } //Gets ActiveSheet from Excel (MUST HAVE!!!)


     private void button15_Click(object sender, EventArgs e)
        {
        //Allows Access to Solidworks (without SDK add-in)
        SldWorks swApp;
        swApp = null;
        swApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application"));

        ModelDoc2 swDoc = null;
        bool boolstatus = false;
        swDoc = ((ModelDoc2)(swApp.ActiveDoc));
        boolstatus = swDoc.Extension.SelectByID2("Design Table", "DESIGNTABLE", 0, 0, 0, false, 0, null, 0);

        //Open Solidworks Design Table
        swDoc.InsertFamilyTableEdit();

        //Gets ActiveSheet to Modify
        Excel.Application oXL;
        Excel.Workbook oWB;
        Excel.Worksheet oSheet;

        //Start Excel and get Application object.
        oXL = (Excel.Application)Marshal.GetActiveObject("Excel.Application"); 
        oXL.Visible = true;
        oWB = (Excel.Workbook)oXL.ActiveWorkbook; 
        oSheet = (Excel.Worksheet)oWB.ActiveSheet;
        //Generate Linear Guide Support in Solidworks    
        if (comboBox1.Text == "0")//No External Rails    
        {    
         sheet.Cells[6, 4] = "0"; //Cell Location [y-axis, x-axis]    
        }    

        //Close Design Table
        swDoc.CloseFamilyTable();

        //Quit Excel
        oXL.Quit();
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM