Posts

Referenced Configuration of Top level Components in Assembly

      Dim swApp As SldWorks.SldWorks     Dim swAssy As SldWorks.AssemblyDoc     Dim swSelMgr As SldWorks.SelectionMgr     Dim swModel As SldWorks.ModelDoc     Dim swComp As SldWorks.Component     Dim RefCfg As String     Dim vcomp As Variant Sub main()     Set swApp = Application.SldWorks     Set swModel = swApp.ActiveDoc     Set swAssy = swModel     vcomp = swAssy.GetComponents(True)     'Set swSelMgr = swModel.SelectionManager     For i = 0 To UBound(vcomp)          Set swComp = vcomp(i)     ' Change component configuration to "in-use"     'swComp.ReferencedConfiguration = ""     RefCfg = swComp.ReferencedConfiguration     MsgBox.Show swComp.Name2 & "-" & "Referenced configuration: " & RefCfg     Next     ' For changes to take effect     swModel.EditRebuild3 End Sub

To select the last created plane

To select by using SolidWorks API / Macro to select the last plane on the Feature Manager tree Dim swApp As SldWorks.SldWorks Dim swmodel As SldWorks.ModelDoc2 Dim swfeat As SldWorks.Feature Dim var As Variant Dim swfeatmgr As SldWorks.FeatureManager Dim n As Integer Dim plan As Variant Dim swplan As SldWorks.Feature Dim bool As Boolean Sub main() Set swApp = Application.SldWorks Set swmodel = swApp.ActiveDoc Set swfeatmgr = swmodel.FeatureManager var = swfeatmgr.GetFeatures(False) For i = 0 To UBound(var) Set swfeat = var(i) If swfeat.GetTypeName2 = "RefPlane" Then n = i Debug.Print swfeat.Name & "  " & swfeat.GetTypeName2 End If Next bool = var(n).Select2(False, 0) End Sub

To delete every configuration except the active one

SolidWorks API Macro to delete every configuration except the active one. Please find the macro for the same. Dim swApp As SldWorks.SldWorks Dim swmodel As SldWorks.ModelDoc2 Dim swconfig As SldWorks.Configuration Dim vconfig As Variant Dim conName As String Dim Sconfig As String Dim bool As Boolean Sub main() Set swApp = Application.SldWorks Set swmodel = swApp.ActiveDoc vconfig = swmodel.GetConfigurationNames Set swconfig = swmodel.GetActiveConfiguration conName = swconfig.Name vconfig = swmodel.GetConfigurationNames For i = 0 To UBound(vconfig) Sconfig = vconfig(i) If Not config = conName Then bool = swmodel.DeleteConfiguration2(vconfig(i)) End If Next End Sub

SolidWorks API Macro to check Compare balloons with BOM

 This macro helps to identify if every balloons has been insert in relevance to the BOM in the first page.When you run the Macro, The missed out item will be shown in the Listbox. Click here for the Macro

SOLIDWORKS MACRO TO HIDE/SHOW SKETCH IN DRAWING

Image
This macro helps to Hide/Show macro depending on the selected view. Click below for downloading the macro file. SKETCH_HIDE 1.Any view with model has to be selected before running the macro. The visibility of sketches are hided automatically by the macro.This is done by using Treecontrolitem ,Which helps to traverse the tree thoroughly.VBA collection is used to collect the features and the collected sketch are all hided by blanksketch, 

SolidWorks Macro to create DXF file from each configuration

'Hi All, 'The Code as follows: Dim swApp As SldWorks.SldWorks Dim swmodel As SldWorks.ModelDoc2 Dim swconfig As SldWorks.Configuration Dim vconfig As Variant Dim swpart As SldWorks.PartDoc Dim dataAlignment(11) As Double Dim varAlignment As Variant Dim dataViews(0) As String Sub main() Set swApp = Application.SldWorks Set swmodel = swApp.ActiveDoc Set swpart = swmodel vconfig = swmodel.GetConfigurationNames dataAlignment(0) = 0     dataAlignment(1) = 0     dataAlignment(2) = 0     dataAlignment(3) = 1     dataAlignment(4) = 0     dataAlignment(5) = 0     dataAlignment(6) = 0     dataAlignment(7) = 1     dataAlignment(8) = 0     dataAlignment(9) = 0     dataAlignment(10) = 0     dataAlignment(11) = 1     varAlignment = dataAlignment     dataViews(0) = "*Current" varviews = dataViews Dim bool As Boolean Dim fpath As String fpath = InputBox("Paste the folder location") For i = 0 To UBound(vconfig) 'swmodel.Extension.ac

SolidWorks VBA Macro to remove flag of Toolbox Components

Image
 We all work with SolidWorks toolbox components .But we wonder if we could remove the flag at sometime. I have created a Macro file which would help you to remove the flag of Toolbox Components in assembly. Reach me for any clarification.