vbnet怎么在已打开的solidworks程序,新建一个零件,并在这个零件画一个正方体
时间: 2023-04-05 17:04:03 浏览: 256
你可以使用以下代码在已打开的SolidWorks程序中新建一个零件,并在这个零件中画一个正方体:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
'获取SolidWorks应用程序对象
Set swApp = GetObject(, "SldWorks.Application")
'创建一个新零件
Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SolidWorks 2019\templates\Part.prtdot", 0, 0, 0)
'获取零件模型对象
Dim swModel As Object
Set swModel = swApp.ActiveDoc
'创建一个正方体
Dim swSketchMgr As Object
Dim swSketch As Object
Dim swFeatMgr As Object
Dim swExtrudeFeat As Object
Set swSketchMgr = swModel.SketchManager
Set swSketch = swSketchMgr.AddSketch(swPlaneXY)
swSketch.AddToDB = True
swSketchMgr.CreateCenterRectangle 0, 0, 0, 0.1, 0.1, 0
Set swFeatMgr = swModel.FeatureManager
Set swExtrudeFeat = swFeatMgr.FeatureExtrusion(True, False, False, swEndCondBlind, 0.1, 0, Nothing, Nothing, swModel.Extension.CreateSelectionBox2(0, 0, 0, 0.1, 0.1, 0))
'保存零件
boolstatus = swModel.SaveAs("C:\Temp\NewPart.SLDPRT")
'关闭零件
swApp.CloseDoc "NewPart.SLDPRT"
注意:在运行此代码之前,请确保已经打开了SolidWorks应用程序。
阅读全文