C# SolidWorks 二次开发 API — 修改全局变量的值

今天来简单讲一下如何修改方程式中的一些数据,有时候一些简单的模型我们就可以利用这个全局变量来控制模型.

如下图: 我设定了零件的高度方程式与全局变量h相等.

等到我们需要更新高度时,就可以直接修改这个全局变量,做到更简单的参数化方式,这个全局变量可以是上级装配体中的信息.

 下面来具体演示下如何找api:

打开api帮助文件,搜索关键字 globalvariable,就会发现右侧的实例,是一个获取信息的.

This example shows how to get the values of equations.

//-----------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\api\partequations.sldprt.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Gets each equation's value and index and whether the 
//    equation is a global variable. 
// 2. Examine the Immediate window.
//------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace Macro1CSharp.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            EquationMgr swEqnMgr = default(EquationMgr);
            int i = 0;
            int nCount = 0;
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swEqnMgr = (EquationMgr)swModel.GetEquationMgr();
            Debug.Print("File = " + swModel.GetPathName());
            nCount = swEqnMgr.GetCount();
            for (i = 0; i < nCount; i++)
            {
                Debug.Print("  Equation(" + i + ")  = " + swEqnMgr.get_Equation(i));
                Debug.Print("    Value = " + swEqnMgr.get_Value(i));
                Debug.Print("    Index = " + swEqnMgr.Status);
                Debug.Print("    Global variable? " + swEqnMgr.get_GlobalVariable(i));
            }
 
        }
 
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}

我们参考这段代码来完成方程式信息的读取: 增加按钮写代码.

 参照帮助文件写完的版本大概为:

运行一下:

 

下面我们来做修改:

private void butGlobalVariables_Click(object sender, EventArgs e)
        {
            //连接solidworks
            ISldWorks swApp = Utility.ConnectToSolidWorks();

            if (swApp != null)
            {
                //获取当前模型
                ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;
                //定义方程式管理器
                EquationMgr swEqnMgr = default(EquationMgr);

                int i = 0;
                int nCount = 0;

                if (swModel != null)
                {
                    swEqnMgr = (EquationMgr)swModel.GetEquationMgr();
                    // nCount = swEqnMgr.GetCount();
                    //for (i = 0; i < nCount; i++)
                    //{
                    //    Debug.Print("  Equation(" + i + ")  = " + swEqnMgr.get_Equation(i));
                    //    Debug.Print("    Value = " + swEqnMgr.get_Value(i));
                    //    Debug.Print("    Index = " + swEqnMgr.Status);
                    //    Debug.Print("    Global variable? " + swEqnMgr.get_GlobalVariable(i));
                    //}

                    //修改高度为60

                    if (SetEquationValue(swEqnMgr, "h", 60))
                    {
                        swModel.ForceRebuild3(true);
                    }
                    else
                    {
                        MessageBox.Show("没有找到这个值!");
                    }
                }
            }
        }

        #region 修改全局变量所用到的方法

        public bool SetEquationValue(EquationMgr eqMgr, string name, double newValue)
        {
            int index = GetEquationIndexByName(eqMgr, name);

            if (index != -1)
            {
                eqMgr.Equation[index] = "\"" + name + "\"=" + newValue;

                return true;
            }
            else
            {
                return false;
            }
        }

        //通过名字找方程式的位置
        private int GetEquationIndexByName(EquationMgr eqMgr, string name)
        {
            int i;
            for (i = 0; i <= eqMgr.GetCount() - 1; i++)
            {
                var eqName = eqMgr.Equation[i].Split('=')[0].Replace("=", "");

                eqName = eqName.Substring(1, eqName.Length - 2); // removing the "" symbols from the name

                if (eqName.ToUpper() == name.ToUpper())
                {
                    return i;
                }
            }

            return -1;
        }

        #endregion 修改全局变量所用到的方法

到此,零件高度变成了60, 这一节先讲这么多吧.

最终代码请到码云或者github上下载.

C# SolidWorks 二次开发 API —获取预览图

最近有网友问到如何在界面上简单的显示一个预览图,就类似于资源管理器中显示的图片。
今天来带大家找一找,首先在我共享的中文翻译中搜索一下:“预览

我们找到了几个有用的。
先看这一个: 第一列是Web 帮助的地址,当然也可以去本地api帮助中查看。


vba中还有个例 子
问题是这帮助写的只能是进程内使用,像exe还不行。
继续看下面的,有另一个方法:

这个方法看描述好像可以使用:
Gets the specified preview bitmap of a document and saves it as a Windows bitmap file (.bmp) using the specified filename.

写上代码:

ISldWorks swApp = Utility.ConnectToSolidWorks();

            //此处路径请自己确保存在。
            string fileName = @"D:\09_Study\CSharpAndSolidWorks\CSharpAndSolidWorks\TemplateModel\bodies.sldasm";

            string configName = "Default";

            string bitmapPathName = @"D:\09_Study\CSharpAndSolidWorks\CSharpAndSolidWorks\TemplateModel\bodies.bmp";

            var status = swApp.GetPreviewBitmapFile(fileName, configName, bitmapPathName);

            if (System.IO.File.Exists(bitmapPathName))
            {
                swApp.SendMsgToUser("预览图获取完成。");
            }

结果出来的颜色有点怪,不理想。

到这里想了下,我们可以直接获取系统资源管理器的预览图,而不需要利用solidworks来处理。
这个就直接百度,找一找资源就行了。
我找了个类,直接调用 ,就可以获取到文件了,后缀是.li ,很奇怪的格式。

找到文件,复制到当前零件的文件夹。改后缀为.bmp,ok了。

这是利用系统的api的获取的,如果只是单配置零件也比较完美了。这种好像不能获取不同配置的预览图。

在查询api帮助的时候发现,在Document Manager API 中也提供了获取预览图的功能。
注意,这里需要一个key, 正版用户请找对应的代理商获取,每一个版本的key都不一样,并且带公司名称。


里面还有实例,那我们就来试试吧:
测试时发现,document mgr从2018开始,只支持64位程序。所以测试时大家要把编译的选项改成x64位的,不然一直会报无法创建dll的实例。

 			const string sLicenseKey = "your_license_key"; //这个不好公开。请下载代码 

            string sDocFileName = fileName;

            SwDMClassFactory swClassFact = default(SwDMClassFactory);
            SwDMApplication swDocMgr = default(SwDMApplication);
            SwDMDocument swDoc = default(SwDMDocument);
            SwDMDocument10 swDoc10 = default(SwDMDocument10);
            SwDmDocumentType nDocType = 0;
            SwDmDocumentOpenError nRetVal = 0;
            SwDmPreviewError nError = 0;

            // Determine type of SOLIDWORKS file based on file extension
            if (sDocFileName.EndsWith("sldprt"))
            {
                nDocType = SwDmDocumentType.swDmDocumentPart;
            }
            else if (sDocFileName.EndsWith("sldasm"))
            {
                nDocType = SwDmDocumentType.swDmDocumentAssembly;
            }
            else if (sDocFileName.EndsWith("slddrw"))
            {
                nDocType = SwDmDocumentType.swDmDocumentDrawing;
            }
            else
            {
                // Probably not a SOLIDWORKS file,
                // so cannot open
                nDocType = SwDmDocumentType.swDmDocumentUnknown;
                return;
            }

            swClassFact = new SwDMClassFactory();
            swDocMgr = (SwDMApplication)swClassFact.GetApplication(sLicenseKey);
            swDoc = (SwDMDocument)swDocMgr.GetDocument(sDocFileName, nDocType, true, out nRetVal);
            Debug.Print("File = " + swDoc.FullName);
            Debug.Print(" Version = " + swDoc.GetVersion());
            Debug.Print(" Author = " + swDoc.Author);
            Debug.Print(" Comments = " + swDoc.Comments);
            Debug.Print(" CreationDate = " + swDoc.CreationDate);
            Debug.Print(" Keywords = " + swDoc.Keywords);
            Debug.Print(" LastSavedBy = " + swDoc.LastSavedBy);
            Debug.Print(" LastSavedDate = " + swDoc.LastSavedDate);
            Debug.Print(" Subject = " + swDoc.Subject);
            Debug.Print(" Title = " + swDoc.Title);

            swDoc10 = (SwDMDocument10)swDoc;
            // SwDMDocument10::GetPreviewBitmap throws an unmanaged COM exception
            // for out-of-process C# console applications
            // Use the following code in SOLIDWORKS C# macros and add-ins
            object objBitMap = swDoc10.GetPreviewBitmap(out nError);
            System.Drawing.Image imgPreview = PictureDispConverter.Convert(objBitMap);
            imgPreview.Save(bitmapPathName, System.Drawing.Imaging.ImageFormat.Bmp);
            imgPreview.Dispose();

            Debug.Print(" Preview stream = " + swDoc10.PreviewStreamName);

执行成功之后 ,我们颜色不对的预览图就被替换成功了。

当然 ,现在也还是只是获取了最后保存的那个配置的缩略图。
如何获取别的配置的呢?
这个方法的备注里面有说明: 需要用别的方法:

里面有个实例:
Get PNG Preview Bitmap and Stream for Configuration Example (C#)
核心就在这里,需要去遍历配置。当然 ,如果知道配置名称,就不需要遍历一次了。
下面的代码我没有测试哈

 swCfgMgr = swDoc.ConfigurationManager;
 
                Debug.Print("File = " + swDoc.FullName);
                Debug.Print("Active configuration name = " + swCfgMgr.GetActiveConfigurationName());
                vCfgNameArr = (string[])swCfgMgr.GetConfigurationNames();
 
                foreach (string vCfgName in vCfgNameArr)
                {
 
                    swCfg = (SwDMConfiguration7)swCfgMgr.GetConfigurationByName(vCfgName);
                    // SwDMConfiguration7::GetPreviewPNGBitmap throws an unmanaged COM exception 
                    // for out-of-process C# console applications
                    // Use the following code in SOLIDWORKS C# macros and add-ins 
                    object objBitMap = swCfg.GetPreviewPNGBitmap(out nError);
                    System.Drawing.Image imgPreview = PictureDispConverter.Convert(objBitMap);
                    imgPreview.Save("C:\\temp\\" + vCfgName + ".PNG", System.Drawing.Imaging.ImageFormat.Png);
                    imgPreview.Dispose();
 
                    Debug.Print(" " + vCfgName);
                    Debug.Print(" PNG preview stream = " + swCfg.PreviewPNGStreamName);
 
                    Debug.Print(" ");
                }

C# SolidWorks 二次开发 API — 实例:屏幕上1:1显示零件

这个功能很多年前就有人提过,这只是其中一个: https://forum.solidworks.com/message/878652

因为现在的屏幕越来越大,设计好的零件可能 需要按照料模型实际尺寸,投影到屏幕上。

做这个功能是很早之前有人有这种需求,问我能不能做到,因为他们需要在一个超大的电视上显示实际的产品大小,用来介绍产品,经过我的研究,solidworks中显示有个内置比例,并且当solidworks窗口大小不一样的时候,要想1:1显示也是要调整的,而不是一次性的。

解决这个问题的思路:先得到屏幕的实际物理尺寸,然后利用solidworks中的设计尺寸,与在屏幕外用卡尺测量出来的实际尺寸之前的比例关系,可以得到当前状态下solidworks显示模型在1:1时的比例关系。

我们要的效果就是如下:

      测量尺寸和零件的实体尺寸是一致的:

 先点击自动校准,然后点右侧的1:1就可以实物显示了。 在不改窗口大小的情况,不需要再次校准。

 

 

代码就不贴了,自已去下载吧。

C# SolidWorks 二次开发 API — 2018版 中文翻译 ModelDocExtension 方法

AddAngularRunningDim Method (IModelDocExtension) 为选定实体添加指定的角度运行标注。
AddComment Method (IModelDocExtension) 将注释添加到此文档的注释文件夹中。
AddDecal Method (IModelDocExtension) 向模型添加贴花。
AddDefaultRenderMaterial Method (IModelDocExtension) solidworks 2011及以后版本不支持,也不被取代。
AddDimension Method (IModelDocExtension) 在选定实体的指定位置创建显示维度。
AddDisplayStateSpecificRenderMaterial Method (IModelDocExtension) 将指定的外观添加到活动配置中的指定显示状态,并返回分配给该外观的ID。
AddOrdinateDimension Method (IModelDocExtension) 插入坐标标注。
AddOrUpdateSearchData Method (IModelDocExtension) 向模型文档添加或更新solidworks搜索、第三方、应用程序关键字和值。
AddPathLengthDim Method (IModelDocExtension) 在选定路径的指定坐标处插入路径长度标注。
AddRenderMaterial Method (IModelDocExtension) solidworks 2011及更高版本不支持。被imodeldocextension::addDisplayStateSpecificRenderMaterial和imodeldocextension::iaddDisplayStateSpecificRenderMaterial取代。
AddSpecificDimension Method (IModelDocExtension) 在选定实体的指定位置创建指定的显示维度。
AddSymmetricDimension Method (IModelDocExtension) 在选定实体的指定位置创建完全对称的角度标注。
AlignDimensions Method (IModelDocExtension) 对齐工程图文档中选定的尺寸。
AlignRunningDimension Method (IModelDocExtension) 对齐所有角度标注的尺寸界线,使其距中心的距离与角度运行标注集中的基线标注(0_)相同。
ApplyFormatPainterToAll Method (IModelDocExtension) 将格式刷应用于活动文档中的所有维度和批注。
BreakAllExternalFileReferences2 Method (IModelDocExtension) 打断所有外部参照,并允许您插入原始零件的特征(如果外部参照已打断)。
Capture3DView Method (IModelDocExtension) 捕获此零件或部件的三维视图。
ChangeSketchPlane Method (IModelDocExtension) 通过将选定草图移动到指定配置中的选定平面来更改草图使用的平面。
Compare3DPMI Method (IModelDocExtension) 比较同一零件文档的不同版本之间的dimxpert注释、参考尺寸和其他注释。
CopyDraftingStandard Method (IModelDocExtension) 复制当前的自定义绘图标准。
Create3DBoundingBox Method (IModelDocExtension) 为焊接件零件中的剪切列表项创建三维边界框。
CreateAdvancedHoleElementData Method (IModelDocExtension) 创建指定类型的高级孔元素数据对象。
CreateBalloonOptions Method (IModelDocExtension) 创建存储bom气球选项的对象。
CreateCallout Method (IModelDocExtension) 创建独立于选定内容的标注。
CreateDecal Method (IModelDocExtension) 为此模型创建贴花。
CreateMassProperty Method (IModelDocExtension) 创建imassproperty对象。
CreateMeasure Method (IModelDocExtension) 创建测量工具。
CreateOLEObject Method (IModelDocExtension) 在活动文档上创建OLE对象。
CreateRenderMaterial Method (IModelDocExtension) 创建此模型的外观。
CreateStackedBalloonOptions Method (IModelDocExtension) 创建存储堆叠引出序号选项的对象。
CreateTexture Method (IModelDocExtension) 创建纹理。
DeleteAllDecals Method (IModelDocExtension) 删除此模型上的所有贴花。
DeleteAttachment Method (IModelDocExtension) 删除FeatureManager设计树中“附件”文件夹中的指定文件。
DeleteDecal Method (IModelDocExtension) 从此模型中删除指定的贴花。
DeleteDisplayStateSpecificRenderMaterial Method (IModelDocExtension) 使用外观的ID从活动配置中删除指定的外观。
DeleteDraftingStandard Method (IModelDocExtension) 删除当前的自定义绘图标准。
DeleteFeatureMgrViewx64 Method (IModelDocExtension) 删除64位应用程序中FeatureManager设计树中的指定选项卡。
DeleteRenderMaterial Method (IModelDocExtension) solidworks 2011及更高版本不支持。已被imodelDocExtension::deleteDisplayStateSpecificRenderMaterial和imodelDocExtension::ideleteDisplayStateSpecificRenderMaterial取代。
DeleteScene Method (IModelDocExtension) 删除应用于此模型的场景。
DeleteSearchData Method (IModelDocExtension) 从模型文档中删除指定的SolidWorks搜索第三方关键字。
DeleteSelection2 Method (IModelDocExtension) 删除选定的项,可以选择删除吸收的特征、子特征或同时删除这两个特征。
EditBalloonProperties2 Method (IModelDocExtension) 编辑选定引出序号的特性。
EditDimensionProperties Method (IModelDocExtension) 编辑选定的维度。
EditRebuildAll Method (IModelDocExtension) 仅重建所有配置中需要重建的功能,而不激活每个配置。
FindTrackedObjects Method (IModelDocExtension) 查找分配给此文档中实体的跟踪ID。
FinishRecordingUndoObject2 Method (IModelDocExtension) 以指定的名称和可见性结束solidworks撤消对象的录制。
ForceRebuildAll Method (IModelDocExtension) 强制重新生成所有配置中的所有功能,而不激活每个配置。
Get3DView Method (IModelDocExtension) 获取具有此零件或部件的指定名称的三维视图。
Get3DViewCount Method (IModelDocExtension) 获取此零件或部件中的三维视图数。
Get3DViewNames Method (IModelDocExtension) 获取此零件或部件中三维视图的名称。
Get3DViews Method (IModelDocExtension) 获取此零件或部件的三维视图。
GetActivePropertyManagerPage Method (IModelDocExtension) 获取活动属性管理器页的名称。
GetAdvancedSpotLightProperties Method (IModelDocExtension) 获取此模型中指定的SolidWorks聚光灯的衰减相关高级属性。
GetAnnotationCount Method (IModelDocExtension) 获取此部件上的批注数。
GetAnnotations Method (IModelDocExtension) 获取此部件上的批注。
GetAppearanceSetting Method (IModelDocExtension) 获取此文档的外观设置。
GetAttachmentCount Method (IModelDocExtension) 获取此文档的附件数。
GetAttachments Method (IModelDocExtension) 获取此文档的附件。
GetCalloutVariableString Method (IModelDocExtension) 获取指定callout变量的字符串。
GetCameraById Method (IModelDocExtension) 获取使用指定相机ID的相机。
GetCameraCount Method (IModelDocExtension) 获取文档中的相机数。
GetCameraDefinition Method (IModelDocExtension) 获取相机,但不将新创建的相机添加到模型中。
GetCommandTabs Method (IModelDocExtension) 获取此文档中的所有solidworks commandmanager选项卡名称。
GetCoordinateSystemTransformByName Method (IModelDocExtension) 获取指定坐标系的转换。
GetCorresponding2 Method (IModelDocExtension) 获取与此工程视图或部件中的指定输入对象相对应的基础零件或部件文档中的对象。
GetCorrespondingEntity2 Method (IModelDocExtension) 获取与此部件或工程视图中的指定实体相对应的基础零件或子部件中的实体。
GetCostingManager Method (IModelDocExtension) 获取SolidWorks成本核算API的入口点接口,并获取成本核算管理器。
GetDecal Method (IModelDocExtension) 获取此模型中指定的贴花。
GetDecals Method (IModelDocExtension) 获取应用于模型的贴花。
GetDecalsCount Method (IModelDocExtension) 获取应用于此模型的贴花数。
GetDependencies Method (IModelDocExtension) 获取此模型的所有依赖项。
GetDisplayStateSetting Method (IModelDocExtension) 获取指定作用域的显示状态设置。
GetDraftingStandardNames Method (IModelDocExtension) 获取所有当前可用绘图标准的名称。
GetFlattenSheetMetalPersistReference Method (IModelDocExtension) 获取扁平钣金零件中指定实体(面、边或顶点)的持久引用ID的字节数组。
GetGeneralTableAnnotation Method (IModelDocExtension) 为solidworks mbd 3d pdf创建常规表格注释。
GetKeepLightInRenderScene Method (IModelDocExtension) 获取场景更改时是否保留灯光。
GetLastFeatureAdded Method (IModelDocExtension) 获取添加到模型的最后一个功能。
GetLicenseType Method (IModelDocExtension) 获取创建模型时使用的SolidWorks许可证的类型。
GetLightEnabledInRender Method (IModelDocExtension) 获取此模型中是否亮起灯。
GetMassProperties2 Method (IModelDocExtension) 获取模型中组件在指定精度下的实际质量属性。
GetMaterial Method (IModelDocExtension) 获取此模型文档中指定配置中指定外观ID的外观。
GetMaterialPropertyValues Method (IModelDocExtension) 获取此模型文档的材质属性。
GetMBD3DPdfData Method (IModelDocExtension) 获取solidworks mbd 3d pdf数据对象。
GetModelBreakViewNames Method (IModelDocExtension) 获取活动模型的当前配置中模型中断视图的名称和编号。
GetModelViewCount Method (IModelDocExtension) 获取此文档中的模型视图数。
GetModelViews Method (IModelDocExtension) 获取此文档中的模型视图。
GetMotionStudyManager Method (IModelDocExtension) 获取SolidWorks运动研究的MotionManager。
GetNamedViewRotation Method (IModelDocExtension) 获取相对于前视图的指定命名视图方向矩阵。
GetObjectByPersistReference3 Method (IModelDocExtension) 获取分配给指定的持久引用ID的对象。
GetObjectId Method (IModelDocExtension) 获取指定批注的对象ID。
GetOLEObjectCount Method (IModelDocExtension) 获取OLE对象的数目。
GetOLEObjects Method (IModelDocExtension) 获取OLE对象。
GetPackAndGo Method (IModelDocExtension) 获取打包对象。
GetPersistReference3 Method (IModelDocExtension) 获取此模型文档中指定对象的永久引用ID。
GetPersistReferenceCount3 Method (IModelDocExtension) 获取分配给此模型文档中选定对象的持久引用ID的大小。
GetPrint3DDialog Method (IModelDocExtension) 获取IPrint3DDialog对象。
GetPrintSpecification Method (IModelDocExtension) 获取此文档的IPrintSpecification对象。
GetRenderCustomReferences Method (IModelDocExtension) 获取此模型的自定义渲染引用。
GetRenderMaterials2 Method (IModelDocExtension) 获取在指定显示状态下应用于此模型文档的外观。
GetRenderMaterialsCount2 Method (IModelDocExtension) 获取在指定显示状态下应用于此模型文档的外观数。
GetRenderStockReferences Method (IModelDocExtension) 获取此模型的SolidWorks提供(库存)呈现引用。
GetRoutingComponentManager Method (IModelDocExtension) 获取路由组件管理器。
GetScanto3D Method (IModelDocExtension) 获取此文档的iscanto3d对象。
GetSceneBkgDIBx64 Method (IModelDocExtension) 在64位应用程序中获取作为dibsection的背景图像。
GetSearchData Method (IModelDocExtension) 从模型文档中获取solidworks搜索、第三方、应用程序关键字。
GetSearchDataCount Method (IModelDocExtension) 获取以前添加到此模型文档中的指定第三方应用程序的SolidWorks搜索关键字数。
GetSectionProperties2 Method (IModelDocExtension) 获取以下类型选定项的截面特性:截面平面上任意文档面中的平面模型面在工程图中截面视图中的剖面线截面面草图
GetSheetMetalObjectsByPersistReference Method (IModelDocExtension) 获取折叠钣金零件中与展开钣金零件中实体的持久引用ID的字节数组相对应的对象。
GetStream Method (IModelDocExtension) 获取指定流的句柄。
GetSunLightAdvancedPropertyValues Method (IModelDocExtension) 获取指定的日光高级属性。
GetSunLightSourcePropertyValues Method (IModelDocExtension) 获取阳光源的属性值。
GetSustainability Method (IModelDocExtension) 获取SolidWorks可持续性API的入口点接口。
GetTemplateSheetMetal Method (IModelDocExtension) 从在SolidWorks 2013或更高版本中创建的此钣金模型中获取钣金文件夹功能。
GetTexture Method (IModelDocExtension) 获取应用于指定配置的纹理。
GetUserPreferenceDouble Method (IModelDocExtension) 获取文档默认用户首选项值。此方法用于double类型的用户首选项。
GetUserPreferenceDoubleValueRange Method (IModelDocExtension) 获取当前文档默认用户首选项值和最小和最大有效文档用户偏好值。
GetUserPreferenceInteger Method (IModelDocExtension) 设置文档默认用户首选项值。此方法用于Integer类型的用户首选项。
GetUserPreferenceString Method (IModelDocExtension) 获取文档默认用户首选项值。此方法用于字符串类型的用户首选项。
GetUserPreferenceTextFormat Method (IModelDocExtension) 获取文档默认用户首选项值。此方法用于获取详细的文本格式。
GetUserPreferenceToggle Method (IModelDocExtension) 获取文档默认用户首选项值。此方法用于可切换的用户首选项。
GetVisibleBox Method (IModelDocExtension) 获取由IModelDocExtension::SetVisibleBox为部件或程序集设置的可见边界框。
GetWhatsWrong Method (IModelDocExtension) 获取此模型文档的错误对话框信息。
GetWhatsWrongCount Method (IModelDocExtension) 获取“错误”对话框中的项目数。
HasDesignTable Method (IModelDocExtension) 获取文档是否具有设计表。
HasMaterialPropertyValues Method (IModelDocExtension) 获取此模型是否具有外观。
HasRenamedDocuments Method (IModelDocExtension) 获取文档是否已重命名文件。
HideDecal Method (IModelDocExtension) 隐藏或显示应用于此模型的指定贴花。
HideFeatureManager Method (IModelDocExtension) 隐藏或显示管理器窗格。
IAddDisplayStateSpecificRenderMaterial Method (IModelDocExtension) 将指定的材质添加到活动配置中的指定显示状态,并返回指定给该材质的ID。
IChangeSketchPlane Method (IModelDocExtension) 通过将选定草图移动到指定配置中的选定平面来更改草图使用的平面。
ICreateOLEObject Method (IModelDocExtension) 在活动文档上创建OLE对象。
IDeleteDisplayStateSpecificRenderMaterial Method (IModelDocExtension) 使用材质的ID从活动配置中删除指定的材质。
IEditDimensionProperties Method (IModelDocExtension) 编辑选定的维度。
IGet3rdPartyStorageStore Method (IModelDocExtension) 获取此模型文档中的第三方IStorage接口。
IGetAnnotations Method (IModelDocExtension) 获取此模型上的批注。
IGetAnnotationViews Method (IModelDocExtension) 获取此零件或部件文档中的批注视图。
IGetAttachments Method (IModelDocExtension) 获取此文档的附件。
IGetDecals Method (IModelDocExtension) 获取应用于模型的贴花。
IGetFlattenSheetMetalPersistReference Method (IModelDocExtension) 获取扁平钣金零件中指定实体(面、边或顶点)的持久引用ID的字节数组。
IGetMaterialPropertyValues Method (IModelDocExtension) 获取此模型的材质属性。
IGetModelViews Method (IModelDocExtension) 获取此文档中的模型视图。
IGetNamedViewRotation Method (IModelDocExtension) 获取相对于前视图的指定命名视图方向矩阵。
IGetObjectByPersistReference3 Method (IModelDocExtension) 获取分配给指定的持久引用ID的对象。
IGetOLEObjects Method (IModelDocExtension) 获取OLE对象。
IGetPersistReference3 Method (IModelDocExtension) 获取此模型文档中指定对象的永久引用ID。
IGetSearchData Method (IModelDocExtension) 从模型文档中获取solidworks搜索、第三方、应用程序关键字。
IGetSectionProperties2 Method (IModelDocExtension) 获取以下类型选定项的截面特性:截面平面上任意文档面中的平面模型面在工程图中截面视图中的剖面线截面面草图
IGetSheetMetalObjectsByPersistReference Method (IModelDocExtension) 获取折叠钣金零件中的一个或多个对象,该折叠钣金零件对应于展开钣金零件中实体的永久引用ID的字节数组。
IListExternalFileReferences Method (IModelDocExtension) 获取部件上外部文件引用的名称和状态。
InsertAnnotationFavorite Method (IModelDocExtension) 在指定位置插入指定收藏夹文件中的批注。
InsertAnnotationView Method (IModelDocExtension) 在此零件或部件文档中插入注释视图。
InsertAttachment Method (IModelDocExtension) 将文件作为附件插入到此文档。
InsertBOMBalloon2 Method (IModelDocExtension) 为选定项插入一个bom气球。
InsertBomTable3 Method (IModelDocExtension) 在零件或部件文档中插入物料清单(bom)表。
InsertCamera Method (IModelDocExtension) 在此文档中插入相机。
InsertDatumTargetSymbol3 Method (IModelDocExtension) 创建基准目标符号。
InsertDeleteFace Method (IModelDocExtension) 插入删除面特征。
InsertGeneralTableAnnotation Method (IModelDocExtension) 在此模型文档中插入通用表批注。
InsertGeneralToleranceTableAnnotation Method (IModelDocExtension) 在此模型文档中插入通用公差表注释。
InsertObjectFromFile Method (IModelDocExtension) 从文件中插入OLE对象。
InsertScene Method (IModelDocExtension) 将指定的场景应用于模型。
InsertStackedBalloon2 Method (IModelDocExtension) 为选定项插入一组引出序号。
InsertSurfaceFinishSymbol3 Method (IModelDocExtension) 基于上次选择创建表面光洁度符号。
InsertTitleBlockTable Method (IModelDocExtension) 在零件或部件文档中插入标题栏表格。
InstallModelColorizer Method (IModelDocExtension) 安装iswcolorcontour接口的实现接口。
IRelease3rdPartyStorageStore Method (IModelDocExtension) 从此模型文档中发布第三方iStorage接口。
IRemoveMaterialProperty Method (IModelDocExtension) 从此模型中删除材质特性值。
IsAbbreviatedViewActive Method (IModelDocExtension) 获取或设置缩写视图是否处于活动状态。
IsConverted Method (IModelDocExtension) 获取活动文档是否已转换为当前版本更新打开,但尚未保存。
ISetMaterialPropertyValues Method (IModelDocExtension) 设置此模型文档的材质特性值。
IsExploded Method (IModelDocExtension) 获取当前在模型中显示的分解视图的名称。
IsFutureVersion Method (IModelDocExtension) 获取此文档是否用于solidworks的未来版本。
IsSamePersistentID Method (IModelDocExtension) 获取两个指定对象是否具有相同的持久引用ID。
IsVirtualComponent3 Method (IModelDocExtension) 获取到父程序集组件的路径,如果模型是虚拟组件,则该路径最多包括第一个非虚拟父程序集。
JogDimension Method (IModelDocExtension) 获取或设置交互选择的线性标注或坐标标注上的折弯点是打开还是关闭。
ListExternalFileReferences Method (IModelDocExtension) 获取部件上外部引用的名称和状态。
ListExternalFileReferencesCount Method (IModelDocExtension) 获取部件上的外部引用数。
LoadDraftingStandard Method (IModelDocExtension) 从文件加载自定义绘图标准。
MoveDecal Method (IModelDocExtension) 在应用于模型的贴花列表中向上或向下移动贴花。
MoveOrCopy Method (IModelDocExtension) 移动并可选地复制选定的草图实体或注释。
MultiSelect2 Method (IModelDocExtension) 选择多个对象并返回在模型中选定的对象数。
PrintOut4 Method (IModelDocExtension) 打印此文档而不显示任何对话框或消息框。
PublishSTEP242File Method (IModelDocExtension) 将solidworks mbd三维零件或部件导出到步骤242文件。
PublishTo3DPDF Method (IModelDocExtension) 为solidworks mbd创建三维pdf。
PurgeDisplayState Method (IModelDocExtension) 清除相同的显示状态,以便只保留唯一的显示状态。
RayIntersections Method (IModelDocExtension) 查找指定的光线集和指定的实体集之间的交点。
Rebuild Method (IModelDocExtension) 在部件和工程图文档中重建模型并返回重建的状态。
Refresh3DViews Method (IModelDocExtension) 更新此零件或部件的三维视图。
ReJogRunningDimension Method (IModelDocExtension) 在尺寸界线与角度标注中的标注文字重叠的位置应用折弯。
ReleaseStream Method (IModelDocExtension) 释放先前获得的流。
RemoveMaterialProperty Method (IModelDocExtension) 从此模型中删除材质特性值。
RemoveModelColorizer Method (IModelDocExtension) 删除iswcolorcontour接口的已安装实现接口。
RemoveTexture2 Method (IModelDocExtension) 从指定的配置中移除纹理。
RemoveTextureByDisplayState Method (IModelDocExtension) 删除在指定显示状态下应用于此模型的纹理。
RemoveVisibleBox Method (IModelDocExtension) 移除由imodeldocextension::set visible box设置的可见边界框,并将边界框的大小重置为solidworks为零件或部件计算的大小。
RenameDocument Method (IModelDocExtension) 使用指定的名称临时重命名选定的组件。
RenameDraftingStandard Method (IModelDocExtension) 将当前自定义绘图重命名为指定的名称。
ReorderFeature Method (IModelDocExtension) 将指定的特征移动到此零件或部件的FeatureManager设计树中的其他位置。
ResetStandardViews Method (IModelDocExtension) 将所有标准模型视图返回到其默认设置。
ReverseDecalsOrder Method (IModelDocExtension) 反转模型上贴花的顺序。
RotateOrCopy Method (IModelDocExtension) 旋转并可选地复制选定的草图实体或注释。
RunCommand Method (IModelDocExtension) 运行指定的solidworks命令。
SaveAs Method (IModelDocExtension) 以指定的格式将活动文档保存到指定的名称。
SaveDeFeaturedFile Method (IModelDocExtension) 从加载的零件或部件文档中删除除外表面以外的所有CAD数据,并将外表面保存为零件。
SaveDraftingStandard Method (IModelDocExtension) 将当前自定义绘图标准保存到文件中。
SavePackAndGo Method (IModelDocExtension) 保存指定用于打包的文件,然后转到文件夹或zip文件。
SaveSelection Method (IModelDocExtension) 创建包含选定实体的新选择集。
ScaleOrCopy Method (IModelDocExtension) 缩放并可选地复制选定的草图项或注释。
SelectAll Method (IModelDocExtension) 选择零件中的所有边、部件中的所有零部件或图形中的所有实体(默认情况下,草图实体、尺寸和注释)。
SelectByID2 Method (IModelDocExtension) 选择指定的实体。
SelectByRay Method (IModelDocExtension) 选择指定类型的第一个实体,该实体与从指定点开始并在指定半径内平行于指定方向矢量的光线相交。
SetAdvancedSpotLightProperties Method (IModelDocExtension) 设置此模型中指定的SolidWorks聚光灯的衰减相关高级属性。
SetApiUndoObject Method (IModelDocExtension) 实现外接程序应用程序的撤消对象。
SetKeepLightInRenderScene Method (IModelDocExtension) 设置场景更改时是否保留灯光。
SetLightEnabledInRender Method (IModelDocExtension) 设置此模型中的灯光是否打开。
SetMaterialPropertyValues Method (IModelDocExtension) 设置此模型文档的材质特性值。
SetSceneBkgDIBx64 Method (IModelDocExtension) 在64位应用程序中设置背景图像。
SetSunLightAdvancedPropertyValues Method (IModelDocExtension) 设置指定的日光高级属性。
SetSunLightSourcePropertyValues Method (IModelDocExtension) 设置日光源的特性值。
SetTexture Method (IModelDocExtension) 将纹理应用于指定的配置。
SetTextureByDisplayState Method (IModelDocExtension) 设置在指定显示状态下应用于此模型的纹理。
SetTopLevelTransparency Method (IModelDocExtension) 设置此零件或顶级部件的透明度。
SetUserPreferenceDouble Method (IModelDocExtension) 设置文档默认用户首选项值。此方法用于double类型的用户首选项。
SetUserPreferenceInteger Method (IModelDocExtension) 设置文档默认用户首选项值。此方法用于Integer类型的用户首选项。
SetUserPreferenceString Method (IModelDocExtension) 设置文档默认用户首选项值。此方法用于字符串类型的用户首选项。
SetUserPreferenceTextFormat Method (IModelDocExtension) 设置文档默认用户首选项值。此方法用于设置详细文本格式。
SetUserPreferenceToggle Method (IModelDocExtension) 设置文档默认用户首选项值。此方法用于可切换的用户首选项。
SetVisibleBox Method (IModelDocExtension) 将缩放的可见边界框设置为适合零件或部件。
ShowModelBreakView Method (IModelDocExtension) 获取是否在活动模型的当前配置中显示或隐藏指定的模型中断视图。
ShowSmartMessage Method (IModelDocExtension) 在图形区域和状态栏上显示solidworks样式消息作为工具提示。
SketchBoxSelect Method (IModelDocExtension) 框在选择框的指定坐标内选择草图中的所有实体。
SketchOffsetOnSurface Method (IModelDocExtension) 偏移选定边以在面或曲面上创建三维草图。
StartFormatPainter Method (IModelDocExtension) 启动格式绘制程序。
StartRecordingUndoObject Method (IModelDocExtension) 开始录制solidworks撤消对象。
StopFormatPainter Method (IModelDocExtension) 停止格式刷。
Stretch Method (IModelDocExtension) 拉伸选定的实体。
UpdateExternalFileReferences Method (IModelDocExtension) 更新此模型上的外部文件引用。
UpdateFrozenFeatures Method (IModelDocExtension) 更新模型的冻结特征。
UpdateRenderMaterialsInSceneGraph Method (IModelDocExtension) 设置是否更新模型中图形区域中的外观。
UpdateStandardViews Method (IModelDocExtension) 将指定的标准视图更改为当前模型视图。
UpdateSunLight Method (IModelDocExtension) 更新日光位置、颜色和背景图像。
ViewZoomToSheet Method (IModelDocExtension) 将绘图页放大到窗口内的最大尺寸。

C# SolidWorks 二次开发 API — 替换零件

有些情况下我们需要去零件进行升级改版,需要先改好零件再利用替换功能进行升级。

今天简单介绍下如何在装配体中进行零件的替换,当然我们默认参考关系都没问题。

 

代码如下:

private void Btn_ReplacePart_Click(object sender, EventArgs e)
        {
            //首先打开 TempAssembly.sldasm
            //运行后,程序会把装配体中的Clamp1零件替换成Clamp2

            ISldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = swApp.ActiveDoc;

            ModelDocExtension swModelDocExt = (ModelDocExtension)swModel.Extension;

            SelectionMgr selectionMgr = swModel.SelectionManager;

            AssemblyDoc assemblyDoc = (AssemblyDoc)swModel;

            //替换为同目录下的clamp2
            string ReplacePartPath = Path.GetDirectoryName(swModel.GetPathName()) + @"\clamp2.sldprt";

            bool boolstatus;

            //选择当前的clamp1
            boolstatus = swModelDocExt.SelectByID2("clamp1-1@TempAssembly", "COMPONENT", 0, 0, 0, false, 0, null, 0);

            boolstatus = assemblyDoc.ReplaceComponents2(ReplacePartPath, "", false, 0, true);

            if (boolstatus == true)
            {
                MessageBox.Show("替换完成!");
            }
        }

 

 

C# SolidWorks 二次开发 API — 把零件中的坐标点转换到总装配中

今天我们来看下solidworks中的坐标矩阵转换,这个例子是把子零件中的一个基准轴的两个端点读出来,并转换到总装配的坐标系中,得到在总装配体坐标系的位置,可以进一步判断轴的真实安装方向。

直接上代码:

 private void btn_Transform_PartToAsm_Click(object sender, EventArgs e)
        {
            //连接到Solidworks

            //这个例子是把零件中的一个基准轴 的两个点的坐标转换到装配体中

            //请打开装配体,并在某个零件下选择一下基准轴

            ISldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;

            SelectionMgr swSelMgr = swModel.ISelectionManager;

            Feature swFeat = (Feature)swSelMgr.GetSelectedObject6(1, 0);

            String sAxisName = swFeat.Name;

            RefAxis RefAxis = swFeat.GetSpecificFeature2();

            var vParam = RefAxis.GetRefAxisParams();

            Component2 inletPart = swSelMgr.GetSelectedObjectsComponent4(1, 0);

            double[] nPt = new double[3];
            double[] nPt2 = new double[3];

            object vPt;
            object vPt2;

            nPt[0] = vParam[0]; nPt[1] = vParam[1]; nPt[2] = vParam[2];
            nPt2[0] = vParam[3]; nPt2[1] = vParam[4]; nPt2[2] = vParam[5];

            vPt = nPt;
            vPt2 = nPt2;

            MathUtility swMathUtil = (MathUtility)swApp.GetMathUtility();

            MathTransform mathTransform = inletPart.Transform2;

            MathTransform swXform = (MathTransform)mathTransform;

            MathPoint swMathPt = (MathPoint)swMathUtil.CreatePoint((vPt));

            MathPoint swMathPt2 = (MathPoint)swMathUtil.CreatePoint((vPt2));

            //swXform.Inverse(); 反转的话就是把装配体中的点坐标转到零件对应的坐标系统中

            swMathPt = (MathPoint)swMathPt.MultiplyTransform(swXform);

            swMathPt2 = (MathPoint)swMathPt2.MultiplyTransform(swXform);

            var x = swMathPt.ArrayData[0];
            var y = swMathPt.ArrayData[1];
            var z = swMathPt.ArrayData[2];
            var x2 = swMathPt2.ArrayData[0];
            var y2 = swMathPt2.ArrayData[1];
            var z2 = swMathPt2.ArrayData[2];

            var v1 = x2 - x;
            var v2 = y2 - y;
            var v3 = z2 - z;

            if (Math.Round(v3, 4) != 0 && Math.Round(v1, 4) == 0 && Math.Round(v2, 4) == 0)
            {
                MessageBox.Show("此轴在Z方向上");
            }

          
        }

比较全的关于矩阵转换的一篇文章:

https://cadbooster.com/complete-overview-of-matrix-transformations-in-the-solidworks-api/#available-transformations-solidworks

 

 

C# SolidWorks 二次开发 API — 给指定面上色

功能: 用户选择一个或者多个面, 程序把面的颜色改为红色。

选中这个面,点击按钮,则面改为红色。

下面是代码:完整代码请见码云。

 private void btnSetColor_Click(object sender, EventArgs e)
        {
            //首先选择一个面.  点击按钮,将修改为红色.

            ISldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = swApp.ActiveDoc;

            SelectionMgr selectionMgr = swModel.SelectionManager;
            try
            {
                for (int i = 1; i <= selectionMgr.GetSelectedObjectCount(); i++)
                {
                    Face2 face2 = (Face2)selectionMgr.GetSelectedObject6(i, -1);
                    var vFaceProp = swModel.MaterialPropertyValues;

                    var vProps = face2.GetMaterialPropertyValues2(1, null);
                    vProps[0] = 1;
                    vProps[1] = 0;
                    vProps[2] = 0;
                    vProps[3] = vFaceProp[3];
                    vProps[4] = vFaceProp[4];
                    vProps[5] = vFaceProp[5];
                    vProps[6] = vFaceProp[6];
                    vProps[7] = vFaceProp[7];
                    vProps[8] = vFaceProp[8];

                    face2.SetMaterialPropertyValues2(vProps, 1, null);
                    vProps = null;

                    vFaceProp = null;
                }

                swModel.ClearSelection2(true);
            }
            catch (Exception)
            {
                MessageBox.Show("请选择面,其它类型无效!");
            }
        }

 

C# SolidWorks 二次开发 API —读取零件相关属性

如何读取零件相关属性

这一篇看下如何读取属性:

直接上代码:

代码如下:

      private void BtnGetPartData_Click(object sender, EventArgs e)
        {
            //请先打开零件: ..\TemplateModel\clamp1.sldprt

            ISldWorks swApp = Utility.ConnectToSolidWorks();

            if (swApp != null)
            {
                ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc; //当前零件

                //获取通用属性值
                string project = swModel.GetCustomInfoValue("", "Project");

                swModel.DeleteCustomInfo2("", "Qty"); //删除指定项
                swModel.AddCustomInfo3("", "Qty", 30, "1"); //增加通用属性值

                var ConfigNames = (string[])swModel.GetConfigurationNames(); //所有配置名称

                Configuration swConfig = null;

                foreach (var configName in ConfigNames)//遍历所有配置
                {
                    swConfig = (Configuration)swModel.GetConfigurationByName(configName);

                    var manger = swModel.Extension.CustomPropertyManager[configName];
                    //删除当前配置中的属性
                    manger.Delete2("Code");
                    //增加一个属性到些配置
                    manger.Add3("Code", (int)swCustomInfoType_e.swCustomInfoText, "A-" + configName, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue);
                    //获取此配置中的Code属性
                    string tempCode = manger.Get("Code");
                    //获取此配置中的Description属性

                    var tempDesc = manger.Get("Description");
                    Debug.Print("  Name of configuration  ---> " + configName + " Desc.=" + tempCode);
                }
            }
            else
            {
                MessageBox.Show("Please open a part first.");
            }
        }
  

增加一个信息,读取summy里面的信息需要用

swModel.SummaryInfo((int)swSummInfoField_e.swSumInfoComment)

C# SolidWorks 二次开发 API—给零件加材质

这两天比较忙,在整理一份api帮助的功能翻译清单.

今天看一下如何获取零件的材质 以及修改材质.

我们先打开一个零件,如下图:

 

 

        private void btn_SetMaterial_Click(object sender, EventArgs e)
        {
            ISldWorks swApp = Utility.ConnectToSolidWorks();

            ModelDoc2 swModel = swApp.ActiveDoc;
            ModelDocExtension swModelDocExt = (ModelDocExtension)swModel.Extension;
            string swMateDB = "";
            string tempMaterial = "";
            //获取现有材质
            tempMaterial = ((PartDoc)swModel).GetMaterialPropertyName2("", out swMateDB);

            MessageBox.Show($"当前零件材质为 {swMateDB} 中的 {tempMaterial} ");

            string configName = null;
            string databaseName = null;
            string newPropName = null;
            configName = "默认";
            databaseName = "SOLIDWORKS Materials";
            newPropName = "Beech";
            ((PartDoc)swModel).SetMaterialPropertyName2(configName, databaseName, newPropName);

            tempMaterial = ((PartDoc)swModel).GetMaterialPropertyName2("", out swMateDB);

            MessageBox.Show($"修改之后  当前零件材质为 {swMateDB} 中的 {tempMaterial} ");
        }

 

效果如下:

C# SolidWorks 二次开发 API —新零件的创建以及打开已有文件

这一篇我们来看一下如何进行新零件的创建以及打开已有文件,我们以零件为例。

继续建一个按钮来测试

逻辑如下:首先得到文件模板,因为我们手动创建新零件时也是要选择对应的模板的。

Solidworks中的设置如下:

代码:

 private void btnOpenAndNew_Click(object sender, EventArgs e)
        {
            ISldWorks swApp = Utility.ConnectToSolidWorks();

            if (swApp != null)
            {
                //通过GetDocumentTemplate 获取默认模板的路径 ,第一个参数可以指定类型
                string partDefaultTemplate = swApp.GetDocumentTemplate((int)swDocumentTypes_e.swDocPART, "", 0, 0, 0);
                //也可以直接指定slddot asmdot drwdot
                //partDefaultTemplate = @"xxx\..prtdot";

                var newDoc = swApp.NewDocument(partDefaultTemplate, 0, 0, 0);

                if (newDoc != null)
                {
                    //创建完成
                    swApp.SendMsgToUser("Create done.");

                    //下面获取当前文件
                    ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;

                    //选择对应的草图基准面
                    bool boolstatus = swModel.Extension.SelectByID2("Plane1", "PLANE", 0, 0, 0, false, 0, null, 0);

                    //创建一个2d草图
                    swModel.SketchManager.InsertSketch(true);

                    //画一条线 长度100mm  (solidworks 中系统单位是米,所以这里写0.1)
                    swModel.SketchManager.CreateLine(0, 0, 0, 0, 0.1, 0);

                    //关闭草图
                    swModel.SketchManager.InsertSketch(true);

                    string myNewPartPath = @"C:\study\myNewPart.SLDPRT";

                    //保存零件.
                    int longstatus = swModel.SaveAs3(myNewPartPath, 0, 1);

                    //关闭零件
                    swApp.CloseDoc(myNewPartPath);
                    swApp.SendMsgToUser("Closed");
                    //重新打开零件.
                    swApp.OpenDoc(myNewPartPath, (int)swDocumentTypes_e.swDocPART);

                    swApp.SendMsgToUser("Open completed.");
                }
            }
        }

这里我们以创建一个新零件为例(第一次是Part1  第二次就是Part2….):

 

接着会继续创建一个新草图,绘制一条一线。然后把文件保存到指定路径。最后闭文件后再打开。

源代码见码云仓库:https://gitee.com/painezeng/CSharpAndSolidWorks