用excel 调用solidworks 2018 画一个正方体,长在excel sheet1的A1位置,宽在excel sheet1的B1位置,高在excel sheet1的C1位置,写出代码
时间: 2023-03-06 19:26:23 浏览: 131
可以使用以下代码:Sub Create_Cube()
Dim swApp As Object
Dim swModel As Object
Dim swDrawing As Object
Dim swSelMgr As ObjectSet swApp = CreateObject("Sldworks.Application")
Set swModel = swApp.ActiveDoc
Set swDrawing = swModel
Set swSelMgr = swDrawing.SelectionManagerDim lLength As Double
Dim lWidth As Double
Dim lHeight As DoublelLength = Sheet1.Range("A1").Value
lWidth = Sheet1.Range("B1").Value
lHeight = Sheet1.Range("C1").ValueswModel.Extension.SelectByID2 "Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0
swModel.SketchManager.InsertSketch TrueswModel.SketchManager.CreateLine 0, 0, 0, lLength, 0, 0
swModel.SketchManager.CreateLine lLength, 0, 0, lLength, lWidth, 0
swModel.SketchManager.CreateLine lLength, lWidth, 0, 0, lWidth, 0
swModel.SketchManager.CreateLine 0, lWidth, 0, 0, 0, 0
swModel.SketchManager.CreateLine 0, 0, 0, 0, 0, lHeight
swModel.SketchManager.CreateLine lLength, 0, 0, lLength, 0, lHeight
swModel.SketchManager.CreateLine lLength, lWidth, 0, lLength, lWidth, lHeight
swModel.SketchManager.CreateLine 0, lWidth, 0, 0, lWidth, lHeight
swModel.SketchManager.CreateLine 0, 0, lHeight, lLength, 0, lHeight
swModel.SketchManager.CreateLine lLength, 0, lHeight, lLength, lWidth, lHeight
swModel.SketchManager.CreateLine lLength, lWidth, lHeight, 0, lWidth, lHeight
swModel.SketchManager.CreateLine 0, lWidth, lHeight, 0, 0, lHeightswModel.Extension.SelectByID2 "Line1", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"
swModel.SketchAddConstraints "sgCOINCIDENT"swModel.ClearSelection2 TrueswModel.FeatureManager.FeatureExtrusion2 False, False, False, 0, 0, lHeight, 0.01, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, FalseswModel.ViewZoomtofit2Set swModel = Nothing
Set swApp = NothingEnd Sub
阅读全文