|
经典案例图书 楼主有点不太地道,即然收费了就应该给完整的代码,来下载的就是想直接下下来使用,要么就是看看有没有好的方法思路,懂代码的修改后才可以用,我不能上传图片,也不能上传附件,所以只能打字说说:第一把设置颜色模块里的
'If Dir("C:\ma_t_f", vbDirectory) = "" Then MkDir "C:\ma_t_f"
'Dim Ma_p_n_ As String
'Ma_p_n_ = Application.SldWorks.GetCurrentMacroPathName
'Ma_p_n_ = Left(Ma_p_n_, InStrRev(Ma_p_n_, "\") - 1)
'Ma_p_n_ = Left(Ma_p_n_, InStrRev(Ma_p_n_, "\") - 1)
'Application.SldWorks.RunMacro Ma_p_n_ & "\宏启动器.swp", "ms_ms", "msms"
'If Dir("C:\ma_t_f", vbDirectory) <> "" Then Exit Sub
这些删除
第二在usfSetColor用户窗体里代码增加'选择零件
Private Sub CommandButton2_Click()
Dim swPart As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim count As Integer
Dim i As Integer
Dim swModel2() As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
PathName = swModel.GetPathName
If swModel.GetType = 1 Then
Set_Bo = 3
Label5.Caption = "已选择当前<零件>对象!"
swModel.ClearSelection2 True '取消选择
set_color
ElseIf swModel.GetType = 2 Then
Set swSelectionMgr = swModel.SelectionManager
count = swSelectionMgr.GetSelectedObjectCount2(-1)
If count = False Then MsgBox "请选择对象!": Exit Sub
Set Path_Arr = CreateObject("Scripting.Dictionary") '文档路径
For i = 0 To count - 1
ReDim Preserve swModel2(i)
Set swModel2(i) = swSelectionMgr.GetSelectedObjectsComponent4(i + 1, -1)
Next i
h = 0
For i = 0 To count - 1
If swModel2(i).GetSuppression = 1 Then swModel2(i).SetSuppression2 2
Set swPart = swModel2(i).GetModelDoc2
If swPart.GetType = 1 Then
If Path_Arr.Exists(swPart.GetPathName) = False Then
Path_Arr(swPart.GetPathName) = ""
ReDim Preserve Set_Co(h)
Set Set_Co(h) = swPart
h = h + 1
End If
Else
asm_get swPart '遍历子装配体内零件
End If
Next i
Set_Bo = 2
Label5.Caption = "已选择" & Path_Arr.count & "个<零件>对象!"
swModel.ClearSelection2 True '取消选择
set_color
End If
End Sub
增加了这两行代码: set_color
|
|