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()
相关推荐
Gitpchy20 分钟前
Day 20 奇异值SVD分解
python·机器学习
MediaTea1 小时前
Python 第三方库:matplotlib(科学绘图与数据可视化)
开发语言·python·信息可视化·matplotlib
草莓熊Lotso1 小时前
C++ 方向 Web 自动化测试入门指南:从概念到 Selenium 实战
前端·c++·python·selenium
我是李武涯1 小时前
PyTorch Dataloader工作原理 之 default collate_fn操作
pytorch·python·深度学习
Kratzdisteln2 小时前
【Python】绘制椭圆眼睛跟随鼠标交互算法配图详解
python·数学·numpy·pillow·matplotlib·仿射变换
maxruan2 小时前
PyTorch学习
人工智能·pytorch·python·学习
唐古乌梁海3 小时前
【python】在Django中,执行原生SQL查询
python·sql·django
程序员大雄学编程3 小时前
「用Python来学微积分」5. 曲线的极坐标方程
开发语言·python·微积分
一位代码4 小时前
python | requests爬虫如何正确获取网页编码?
开发语言·爬虫·python
可触的未来,发芽的智生4 小时前
新奇特:神经网络速比器,小镇债务清零的算法奇缘
javascript·人工智能·python