-
Re: Macro which suppresses all folders of the same name in an assembly
Deepak Gupta May 8, 2015 12:51 AM (in response to Kyle Schutte)If you're to suppress the fasteners in the assembly, then go to Tools > Component Selection > Select Toolbox. This would select all toolbox files in the top level assembly including sub-assembly. Then right click and select suppress/unsuppress.
This would be faster than macro and would be easy to use.
-
Re: Macro which suppresses all folders of the same name in an assembly
Kyle Schutte May 8, 2015 8:22 AM (in response to Deepak Gupta)Deepak,
Thank you very much for taking the time to respond.
This works very well for my application, however, I do have a lot of 'fastener-like' components that are not in my Toolbox, but are still placed within my "Fasteners" folder. This created the need for a macro to suppress the folders.
-
-
Re: Macro which suppresses all folders of the same name in an assembly
Yuvaraj Sakthivel May 8, 2015 5:57 AM (in response to Kyle Schutte)Dear Sir,
Try the below macro, Kindly check and let me know
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAsm As SldWorks.AssemblyDoc
Dim swcomp As SldWorks.Component2
Dim swModelComp As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAsm = swModel
Dim vComp As Variant
Dim i As Integer
vComp = swAsm.GetComponents(True)
For i = 0 To UBound(vComp)
Set swcomp = vComp(i)
If Not swcomp Is Nothing Then
Dim s As Integer
s = swcomp.GetSuppression
If Not s = 0 Then
Dim strComp As String
strComp = swcomp.Name2
Set swModelComp = swcomp.GetModelDoc2
Dim t As Integer
t = swModelComp.GetType
If t = 1 Then
Dim ret As Long
ret = swModelComp.Extension.ToolboxPartType
If ret = 1 Then
swcomp.Select4 True, Nothing, False
End If
End If
End If
End If
Next i
swModel.EditSuppress2
swModel.ClearSelection2 True
swModel.ForceRebuild3 True
End Sub
Regards,
Yuvaraj S
-
Re: Macro which suppresses all folders of the same name in an assembly
Kyle Schutte May 8, 2015 8:26 AM (in response to Yuvaraj Sakthivel)Yuvaraj,
Thank you for the response.
I ran the macro and I get the following error:
From the following code:
t = swModelComp.GetType
My macro skills are not the best so I'm not entirely sure why I am getting this error, as the variable 't' is set in the prior line as an integer.
Any insight is appreciated.
-
Re: Macro which suppresses all folders of the same name in an assembly
Yuvaraj Sakthivel May 8, 2015 8:43 AM (in response to Kyle Schutte)If swModelComp is nothing , this error may come. Add if condition above that line.
Check with the below macro.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAsm As SldWorks.AssemblyDoc
Dim swcomp As SldWorks.Component2
Dim swModelComp As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAsm = swModel
Dim vComp As Variant
Dim i As Integer
vComp = swAsm.GetComponents(True)
For i = 0 To UBound(vComp)
Set swcomp = vComp(i)
If Not swcomp Is Nothing Then
Dim s As Integer
s = swcomp.GetSuppression
If Not s = 0 Then
Dim strComp As String
strComp = swcomp.Name2
Set swModelComp = swcomp.GetModelDoc2
If Not swModelComp Is Nothing Then
Dim t As Integer
t = swModelComp.GetType
If t = 1 Then
Dim ret As Long
ret = swModelComp.Extension.ToolboxPartType
If ret = 1 Then
swcomp.Select4 True, Nothing, False
End If
End If
End If
End If
End If
Next i
swModel.EditSuppress2
swModel.ClearSelection2 True
swModel.ForceRebuild3 True
End Sub
-
Re: Macro which suppresses all folders of the same name in an assembly
Kyle Schutte May 8, 2015 12:20 PM (in response to Yuvaraj Sakthivel)Yuvaraj,
I was able to run the macro within the compiler and in the assembly model view, however, nothing happened.
Is the macro looking for and suppressing all parts within a certain folder or is it suppressing all Toolbox parts?
Thanks.
-
-
-
-
Re: Macro which suppresses all folders of the same name in an assembly
Keith Rice May 11, 2015 10:41 AM (in response to Kyle Schutte)IAssemblyDoc::GetComponents won't work because it returns components, and a folder is not a component. Rather, it is necessary to find the folder as an IFeature object and suppress it.
Option Compare Text Const FOLDER_NAME As String = "Fasteners" Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc TraverseModel swModel, swModel, 1 End Sub Private Sub TraverseModel(swModel As SldWorks.ModelDoc2, model As Object, nLevel As Integer) Dim swFeat As SldWorks.Feature Dim swComp As SldWorks.Component2 Set swFeat = model.FirstFeature Do While Not swFeat Is Nothing If swFeat.Name = FOLDER_NAME And _ swFeat.GetTypeName = "FtrFolder" Then swFeat.Select2 False, Empty swModel.EditSuppress2 End If If swFeat.GetTypeName = "Reference" Then Set swComp = swFeat.GetSpecificFeature2 TraverseModel swModel, swComp, nLevel + 1 End If Set swFeat = swFeat.GetNextFeature Loop End Sub
Keith
-
Re: Macro which suppresses all folders of the same name in an assembly
Kyle Schutte May 11, 2015 8:06 AM (in response to Keith Rice)Keith,
The macro works perfectly! Thank you for your time and effort.
Thank you Yuvaraj and Deepak for your input as well!
I was able to learn a lot from everyone.
Regards,
Kyle
-
Re: Macro which suppresses all folders of the same name in an assembly
Kyle Lami Mar 18, 2016 5:36 PM (in response to Keith Rice)Keith,
This is a great macro! I now have 2 macro buttons, one to suppress and one to unsuppress.
What would it take to also suppress all the patterns made from these fasteners? And Unsuppress...
-Kyle
-