solidworks二次开发学习(3)move all of the bodies in a part document。

本文介绍如何使用SolidWorks API 进行VB.NET编程,具体演示了如何打开指定零件文档并移动所有体至指定位置。操作完成后确保不保存任何更改,避免影响零件在其他地方的使用。
 


1
'SolidWorks API Help 2 'Move Bodies Example (VB.NET) 3 'This example shows how to move all of the bodies in a part document. 4 5 '------------------------------------------------------------- 6 ' Preconditions: 7 ' 1. Specified part document to open exists. 8 ' 2. Run the macro. 9 ' 10 ' Postconditions: All of the bodies in the part document 11 ' are moved to the specified location. 12 ' 13 ' NOTE: Because this part is used elsewhere, do not save 14 ' any changes when closing it. 15 '-------------------------------------------------------------- 16 Imports SolidWorks.Interop.sldworks 17 Imports SolidWorks.Interop.swconst 18 Imports System.Runtime.InteropServices 19 Imports System 20 21 Partial Class SolidWorksMacro 22 23 Sub SelectBodies(ByVal swApp As SldWorks, ByVal swModel As ModelDoc2, ByVal bodyArr As Object) 24 ' Select and mark the bodies to move 25 Dim swSelMgr As SelectionMgr 26 Dim swSelData As SelectData 27 Dim body As Object 28 Dim swBody As Body2 29 Dim status As Boolean 30 31 swSelMgr = swModel.SelectionManager 32 swSelData = swSelMgr.CreateSelectData 33 34 If (bodyArr Is Nothing) Then Exit Sub 35 For Each body In bodyArr 36 swBody = body 37 swSelData.Mark = 1 38 status = swBody.Select2(True, swSelData) 39 Next body 40 41 End Sub 42 43 Sub Main() 44 45 Dim swModel As ModelDoc2 46 Dim swPart As PartDoc 47 Dim bodyArr As Object 48 Dim swFeatMgr As FeatureManager 49 Dim swFeat As Feature 50 Dim fileName As String 51 Dim errors As Integer 52 Dim warnings As Integer 53 swModel = CType(swApp.ActiveDoc, ModelDoc2) 54 fileName = "D:\test.SLDPRT" 55 swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings) 56 swPart = swModel 57 swFeatMgr = swModel.FeatureManager 58 59 swModel.ClearSelection2(True) 60 61 ' Get the bodies to move 62 bodyArr = swPart.GetBodies2(swBodyType_e.swAllBodies, False) 63 SelectBodies(swApp, swModel, bodyArr) 64 ' Move the bodies 65 swFeat = swFeatMgr.InsertMoveCopyBody2(0, 0, -0.0255, 0, 0, 0, 0, 0, 0, 0, True, 1) 66 End Sub 67 68 ''' <summary> 69 ''' The SldWorks swApp variable is pre-assigned for you. 70 ''' </summary> 71 Public swApp As SldWorks 72 73 End Class

 

转载于:https://www.cnblogs.com/frankwu2014/p/4345215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值