Python SolidWorks 二次开发---SolidWorks保存文件
Python SolidWorks 二次开发—SolidWorks保存文件
Python SolidWorks 二次开发—SolidWorks保存文件
文章目录
- Python SolidWorks 二次开发---SolidWorks保存文件
- 一、连接SolidWorks 二次开发
- 二、保存文件函数:Save3
- 1.Save3函数定义
- 2.Save3函数的使用
一、连接SolidWorks 二次开发
连接SolidWorks见>>Python SolidWorks 二次开发—Python如何连接SolidWorks
二、保存文件函数:Save3
使用Save3函数进行文件的保存
1.Save3函数定义
函数原型如下:
Function Save3( _ByVal Options As System.Integer, _ByRef Errors As System.Integer, _ByRef Warnings As System.Integer _
) As System.Boolean
参数说明:
Options:保存文件时的选项,包含以下选项
Member | Description |
---|---|
swSaveAsOptions_AvoidRebuildOnSave | 8 or 0x8 |
swSaveAsOptions_Copy | 2 or 0x2 |
swSaveAsOptions_DetachedDrawing | 128 or 0x80; Not a valid option for IPartDoc::SaveToFile2 |
swSaveAsOptions_IgnoreBiography | 256 or 0x100; Prune a SOLIDWORKS file’s revision history to just the current file name |
swSaveAsOptions_OverrideSaveEmodel | 32 or 0x20; Saves eDrawings-related information into a section of the file being saved; specifying this setting overrides the Tools, Options, System Options, General, Save eDrawings data in SOLIDWORKS document setting; not a valid option for IPartDoc::SaveToFile2 |
swSaveAsOptions_SaveEmodelData | Obsolete. |
swSaveAsOptions_SaveReferenced | 4 or 0x4; Supports parts, assemblies, and drawings; this setting indicates to save all components (sub-assemblies and parts) in both assemblies and drawings; if a part has an external reference, then this setting indicates to save the external reference |
swSaveAsOptions_Silent | 1 or 0x1 |
swSaveAsOptions_UpdateInactiveViews | 16 or 0x10; Not a valid option for IPartDoc::SaveToFile2; this setting is only applicable for a drawing that has one or more sheets; this setting updates the views on inactive sheets |
Errors:保存文件出现错误的定义,包含如下选项
Member | Description |
---|---|
swFileLockError | 16 or 0x10 |
swFileNameContainsAtSign | 8 or 0x8 = File name cannot contain the at symbol (@) |
swFileNameEmpty | 4 or 0x4 = File name cannot be empty |
swFileSaveAsBadEDrawingsVersion | 1024 or 0x400 |
swFileSaveAsDoNotOverwrite | 128 or 0x80 = Do not overwrite an existing file |
swFileSaveAsInvalidFileExtension | 256 or 0x100 = File name extension does not match the SOLIDWORKS document type |
swFileSaveAsNameExceedsMaxPathLength | 2048 or 0x800 = File name cannot exceed 255 characters |
swFileSaveAsNoSelection | 512 or 0x200 = Save the selected bodies in a part document. Valid option for IPartDoc::SaveToFile2; however, not a valid option for IModelDocExtension::SaveAs |
swFileSaveAsNotSupported | 4096 or 0x1000 = Save As operation:is not supported was executed is such a way that the resulting file might not be complete, possibly because SOLIDWORKS is hidden; if the error persists after setting SOLIDWORKS to visible and re-attempting the Save As operation, contact SOLIDWORKS API support. |
swFileSaveFormatNotAvailable | 32 or 0x20 = Save As file type is not valid |
swFileSaveRequiresSavingReferences | 8192 or 0x2000 = Saving an assembly with renamed components requires saving the references |
swFileSaveWithRebuildError | Obsolete = See swFileSaveWarning_e |
swGenericSaveError | 1 or 0x1 |
swReadOnlySaveError | 2 or 0x2 |
Warnings:保存文件出现警告的定义,包含如下选项
Member | Description |
---|---|
swFileSaveWarning_AnimatorCameraViews | 128 or 0x80 |
swFileSaveWarning_AnimatorFeatureEdits | 16 or 0x10 |
swFileSaveWarning_AnimatorLightEdits | 64 or 0x40 |
swFileSaveWarning_AnimatorNeedToSolve | 8 or 0x8 |
swFileSaveWarning_AnimatorSectionViews | 256 or 0x100 |
swFileSaveWarning_EdrwingsBadSelection | 32 or 0x20 |
swFileSaveWarning_MissingOLEObjects | 512 or 0x200 |
swFileSaveWarning_NeedsRebuild | 2 or 0x2 |
swFileSaveWarning_OpenedViewOnly | 1024 or 0x400 |
swFileSaveWarning_RebuildError | 1 or 0x1 |
swFileSaveWarning_ViewsNeedUpdate | 4 or 0x4 |
swFileSaveWarning_XmlInvalid | 2048 or 0x800 |
返回值,返回布尔类型,保存成功放回true,失败返回falese
2.Save3函数的使用
执行以下代码可直接在SolidWorks中保存当前激活的文件
import win32com.client
from swconst import constants
import pythoncomdef savefile():# SolidWorks年份版本sldver=2018# 建立com连接,如只有一个版本,可以只写"SldWorks.Application"swApp=win32com.client.Dispatch(f'SldWorks.Application.{sldver-1992}')# 提升API交互效率swApp.CommandInProgress =True# 显示SolidWorks界面swApp.Visible =True# 获取当前激活文档对象swModel = swApp.ActiveDoc#错误和警告Errors=win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, -1)Warnings=win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, -1)# constants.swSaveAsOptions_Silent也可以直接按照选项说明写整数:1boolstatus = swModel.Save3(constants.swSaveAsOptions_Silent, Errors, Warnings)if boolstatus:print('文件保存成功')else:print(f'文件保存失败,出现如下错误:{Errors}')print(f'文件保存失败,出现如下警告:{Warnings}')if __name__ == '__main__':savefile()
Python SolidWorks 二次开发---SolidWorks保存文件相关推荐
- Python SolidWorks 二次开发---SolidWorks另存文件为其他格式
Python SolidWorks 二次开发-SolidWorks另存文件为其他格式 Python SolidWorks 二次开发-SolidWorks另存文件为其他格式 文章目录 Python So ...
- Python SolidWorks 二次开发—SolidWorks中的事件实现
Python SolidWorks 二次开发-SolidWorks中的事件实现 文章目录 Python SolidWorks 二次开发---SolidWorks中的事件实现 前言 一.如何实现com事 ...
- 基于Python的Solidworks二次开发方法
关于python简易二次开发Solidworks的小程序 第一次动手开发了一个Solidworks的小程序,实验的功能也很简单,出来分享一下,第一次大佬们也可以指出一些问题,来帮助我改进~ 此处特别感 ...
- 基于Python的Solidworks二次开发小尝试(一)
文章目录 前言 一.自我理解 二.使用步骤 1.建立 Python 与 SolidWorks 之间的关联 2.通过录制宏获取vb代码 总结 前言 第一次运用python对solidworks进行二次开 ...
- SolidWorks二次开发 API-获取当前语言与重命名文件
新的一年了,开始新的分享. 做SolidWorks二次开发的时候,难免会遇到多语言的问题. 针对不同语言的客户生成不同语言的菜单,所以我们要知道Solidworks的当前界面语言是什么. 这个就简单的 ...
- solidworks二次开发
1.solidworks二次开发加入时间限制 限制用户的使用期限,可以一定程度上保护自己的软件.思路:在第一次安装注册的时候,向注册表写入信息.这里采用一明一暗的做法.首先将当前时间写入注册表的某一项 ...
- Solidworks二次开发平台 --- RyS.SwWorks [2015-09-18更新]
RyS.SwWorks 是一款基于.NET的Solidworks二次开发平台,该平台封装了插件注册.菜单.工具栏.侧边栏.Document接口,使得Solidworks开发和部署简单高效. 安装程序中 ...
- SolidWorks二次开发的研究
三维机械设计软件SolidWorks是一套基于Windows的CAD/CAE/CAM/PDM桌面集成系统,是由美国SolidWorks公司在总结和继承大型机械CAD软件的基础上,在Windows环境下 ...
- 基于SOLIDWORKS二次开发的3D产品研发增效和企业信息化工具集SolidKits
基于SOLIDWORKS二次开发的SolidKits工具的含义是3D产品研发增效和企业信息化工具集,目前已经帮助高科技.机器人.航空航天.船舶.汽车.机械设备.电器.电子等行业的上百家制造业企业提供了 ...
最新文章
- windows10远程控制 电脑,远程桌面
- 人工智能浪潮下的语音交互——VUI设计(基础篇)
- C#连接ORACLE数据库乱码问题
- CTFshow 信息收集 web10
- python vs java的rsa加密
- git仓库迁移(全部分支)
- 【中级软考】计算能力足够强大,所有加密算法原理上都会被破解吗?
- cacti linux cpu datasource,Cacti监控Cisco CPU 以及内存
- 9个元素换6次达到排序序列_C语言必学的12个排序算法:希尔排序(第3篇)
- Python的psutil模块监控内存代码
- WAP调用微信支付https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1
- Endnote X6大客户版破解版+新功能介绍+视频介绍
- 明净素雅-会议礼品送什么
- banner图片通用设置
- 台式计算机如何扫描文件,打印机怎么扫描,教您打印机怎么扫描文件
- C# 数组去重的三种方法
- 我用Python分析了1500家电商的销售数据,竟发现了进口车厘子的秘密
- switch中break用法
- JVM初探究【JVM入门教程】
- mysql中防呆是什么_防呆是什么意思
热门文章
- windows防火墙启动不了,错误代码13
- 越南军用电子电信集团Viettel成为越南首家5G运营商
- Html的a标签onclick属性,关于通过js给a标签增加onclick属性
- 让QQ被封后还能正常使用QQ邮箱的方法
- python实验目的_python实验一
- [Download]Softimage XSI addon -- Batch Passes(JS Python)
- 录屏剪辑软件哪个好 录屏后怎么剪辑视频
- 南方计算机好的大学排名,中国南方最好的五所大学排名
- 【第010篇】vue表单验证之验证非空字符(空格等空白符)
- 执行器市场现状及未来发展趋势