Solidworks 与Excel C# 引用系列零件设计表

发布于 2024-12-04 18:30:07 字数 888 浏览 1 评论 0原文

打开时我无法修改设计表,我遇到的问题是 varsheet = (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]
        }

I can't get my design table to modify when opened the line I am having the trouble is var sheet = (Excel._Worksheet)swDoc.GetDesignTable; . Essentially what I want it to do is open the window and reference the active sheet which is the "Design Table". The API does include "DesignTable" as type. I have been stuck for a while. Any help is appreciated.

        //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]
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞笑我太脆弱 2024-12-11 18:30:07

想通了

   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();
        }

Figured it out

   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();
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文