C# 二次开发rectangle代码架构

本文档详细介绍了如何使用C#进行SolidWorks二次开发,通过VS2015集成环境,实现SolidWorks 2017中新建零件并创建矩形模型的功能。在Button_Click事件中,首先验证输入数据,接着连接SolidWorks,然后最大化文档窗口,最后生成具有特定长度、宽度和高度的矩形模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Button_Click

Try
验证输入数据 VerificationInput()
获取值 Length、width、height
连接SolidWorks ConnectSw()
新建零件 NewPart()
文档框最大化 FrameMax()
生成矩形 GenerageModel(length, width, height);
Catch

private void VerificationInput()
        {
            string length = this.tbChangdu.Text;
            string width = this.tbKuandu.Text; 
            string height = this.tbGaodu.Text; 
            if (!VerificationIsDigital(length)) 
            {
                throw new Exception("长度值不是有效数字,请重新输入!");
            }
            if (!VerificationIsDigital(width)) 
            {
                throw new Exception("宽度值不是有效数字,请重新输入!");
            }

            if (!VerificationIsDigital(height)) 
            {
                throw new Exception("高度值不是有效数字,请重新输入!");
            }
        }
public void ConnectSw()

        {

            //尝试连接已打开的Solidworks

            if (swApp == null)

            {

                Process[] processArr = null;

                processArr = Process.GetProcessesByName("SLDWORKS");

                if (processArr.Length > 0)

                {

                    //通过SldWorks.Application方式

                    try

                    {

                        swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");

                    }

                    catch (Exception)

                    {



                    }

                    //通过SldWorks.Application.18方式,.18=2010版,.19=2011版,.20=2012版,.21=2013版,.22=2014版,.23=2015版

                    if (swApp == null)

                    {

                        for (int i = 18; i < 28; i++)

                        {

                            try

                            {

                                swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application." + i.ToString());

                                if (swApp != null)

                                {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值