python二次开发Solidworks:扫描

在新零件文档中创建一个圆形草图和两条线段草图,并将它们插入到模型中。接着,选中圆形草图作为扫描轮廓,并选中两条线段草图并将它们分组为一个对象。最后,使用特征管理器的InsertProtrusionSwept4方法创建扫描特征。

python 复制代码
import win32com.client as win32
import pythoncom
swApp = win32.Dispatch('sldworks.application')
swApp.Visible = True
Nothing = win32.VARIANT(pythoncom.VT_DISPATCH, None)
swModel = swApp.NewDocument(r"C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\gb_part.prtdot", 0, 0, 0)
swModelDocExt = swModel.Extension
swSketchManager = swModel.SketchManager
swFeatureManager = swModel.FeatureManager
#Create sketch of circle for the sweep profile
swSketchSegment = swSketchManager.CreateCircle(0, 0, 0, 0.002394, -0.006333, 0)
swSketchManager.InsertSketch(True)
#Create sketches of lines for the sweep path
status = swModelDocExt.SelectByID2("右视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
swSketchManager.InsertSketch(True)
swSketchSegment = swSketchManager.CreateLine(-0, 0, 0, 0.088481, 0.035691, 0)
swSketchManager.InsertSketch(True)
swModel.ClearSelection2(True)
status = swModelDocExt.SelectByID2("右视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
swSketchManager.InsertSketch(True)
swSketchSegment = swSketchManager.CreateLine(0.088481, 0.035691, 0, 0.079214, 0.076295, 0)
swSketchManager.InsertSketch(True)
swModel.ClearSelection2(True)
#Select the sketch of the circle for the sweep profile
status = swModelDocExt.SelectByID2("草图1", "SKETCH", -5.86834883582351E-03, -3.37646707201764E-03, 0, False, 1, Nothing, 0)
#Select the sketches of the lines for the sweep path and group them as an object
status = swModelDocExt.SelectByID2("直线1@草图2", "EXTSKETCHSEGMENT", 3.79259971310087E-02, 1.52983890733924E-02, 0, True, 4, Nothing, 0)
status = swModelDocExt.SelectByID2("直线1@草图3", "EXTSKETCHSEGMENT", 8.48435978763939E-02, 5.16285284155501E-02, 0, True, 4, Nothing, 0)
status = swModelDocExt.SelectByID2("Unknown", "SELOBJGROUP", 0, 0, 0, True, 4, Nothing, 0)
#Create the sweep feature
swFeature = swFeatureManager.InsertProtrusionSwept4(False, False, 0, False, False, 0, 0, False, 0, 0, 0, 0, True, True, True, 0, True, False, 0, 0)
swModel.ShowNamedView2("*上下二等角轴测", 8)
swModel.SelectionManager.EnableContourSelection = False
swModel.ViewZoomtofit2()
相关推荐
红衣小蛇妖1 小时前
Python基础学习-Day23
开发语言·python·学习
Hello world.Joey2 小时前
数据挖掘入门-二手车交易价格预测
人工智能·python·数据挖掘·数据分析·conda·pandas
刘延林.2 小时前
树莓5安装 PyCharm 进行python脚本开发
ide·python·pycharm
小洛~·~2 小时前
多模态RAG与LlamaIndex——1.deepresearch调研
人工智能·python·深度学习·神经网络·chatgpt
q_q王3 小时前
‌FunASR‌阿里开源的语音识别工具
python·大模型·llm·语音识别
不学无术の码农3 小时前
《Effective Python》第1章 Pythonic 思维总结——编写优雅、高效的 Python 代码
开发语言·python
zhou1853 小时前
MySQL保姆级安装教程(附资源包+5分钟极速配置+环境变量调试技巧)
java·python·mysql·php
lczdyx4 小时前
PNG转ico图标(支持圆角矩形/方形+透明背景)Python脚本 - 随笔
图像处理·python
lgily-12254 小时前
常用的设计模式详解
java·后端·python·设计模式
陈苏同学5 小时前
MPC控制器从入门到进阶(小车动态避障变道仿真 - Python)
人工智能·python·机器学习·数学建模·机器人·自动驾驶