|
经典案例图书 某位麻烦人士已经贴出代码, 如下:
(俺只不过转贴, 如有任何问题不要找俺, 感谢俺就可以了)
- Dim swApp As Object
- Dim Part As Object
- Dim longstatus As Long
- Sub main()
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set swSelMgr = Part.SelectionManager
- Set swSelData = swSelMgr.CreateSelectData
- swSelData.Mark = 1
- Set ThinFeature = Part.FeatureManager.FeatureExtrusionThin2(True, False, False, 0, 0, 0.005, 0.005, False, False, False, False, 0, 0, False, False, False, False, False, 0.005, 0.005, 0.005, 0, 0, False, 0.005, True, True, 0, 0, False)
- Part.ClearSelection
- Bodies = Part.GetBodies2(swSolidBody, True)
- For Each myBody In Bodies
- myBody.Select2 True, swSelData
- Next
- Set MoveFeature = Part.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, 1)
- Set FeatureData = MoveFeature.GetDefinition()
- Set PlaneFeature = Part.FirstFeature
- PlaneFeaturename = PlaneFeature.GetTypeName
- While PlaneFeaturename <> "RefPlane"
- Set PlaneFeature = PlaneFeature.GetNextFeature
- PlaneFeaturename = PlaneFeature.GetTypeName
- Wend
- Part.Extension.SelectByID2 PlaneFeature.Name, "PLANE", 0, 0, 0, False, 1, Nothing, 0
- Faces = ThinFeature.GetFaces
- Faces(0).Select4 True, swSelData
- FeatureData.AddMate Nothing, 0, 0, 0, 0, longstatus
- MoveFeature.ModifyDefinition FeatureData, Part, Nothing
- Set PlaneFeature = PlaneFeature.GetNextFeature
- Part.Extension.SelectByID2 PlaneFeature.Name, "PLANE", 0, 0, 0, False, 1, Nothing, 0
- Faces = ThinFeature.GetFaces
- Faces(2).Select4 True, swSelData
- FeatureData.AddMate Nothing, 0, 1, 0, 0, longstatus
- MoveFeature.ModifyDefinition FeatureData, Part, Nothing
- Set PlaneFeature = PlaneFeature.GetNextFeature
- Part.Extension.SelectByID2 PlaneFeature.Name, "PLANE", 0, 0, 0, False, 1, Nothing, 0
- Faces = ThinFeature.GetFaces
- Faces(3).Select4 True, swSelData
- FeatureData.AddMate Nothing, 0, 0, 0, 0, longstatus
- MoveFeature.ModifyDefinition FeatureData, Part, Nothing
- Faces = ThinFeature.GetFaces
- Set myBody = Faces(0).GetBody
- myBody.Select2 True, swSelData
- Part.FeatureManager.InsertDeleteBody
- Part.ClearSelection
- End Sub
复制代码
|
|