3 Replies Latest reply on Mar 7, 2016 4:37 PM by Artem Taturevych


    Joe Pickens

      I wrote a macro to make top level assembly but i can figure out how clear the memory so i keep crashing Solidworks. Is there a way to clear the memory

          Artem Taturevych

          You do not clear the memory if you use the pure SolidWorks API (SolidWorks does it for you). If you are using external windows APIs you might need to release the memory. There may be different reason for crash such as GDI objects: Low memory/System Resources Warning | MySolidWorks

              Joe Pickens

              I dont think the GDI objects is the issue although the memory low is the error i get right before it crashes but the low memory only occurs when i run the macro. if i open and add all the components manually I don't get this error and in face the only other time I have ever seen the low memory warning is when I open over 150 Solidworks components in my window but as soon as i closed out of so the memory error went away.


              this is the macro im using to add the components to the assembly


              Sub Add_Comp_to_Asm


              Dim swApp       As SldWorks.SldWorks

              Dim swModel     As SldWorks.modelDoc2

              Dim SWAsm       As SldWorks.assemblyDoc

              Dim SWAddComp   As SldWorks.modelDoc2

              Dim SWComp      As Component2

              Dim SWCompName  As String

              Dim SWAsmTitle  As String

              Dim SWAsmName   As String

              Dim FLocation   As String

              Dim PrtAsm      As Integer

              Dim count       As Integer

              Dim Str         As Variant

              Dim Errors      As Long

              Dim Warnings    As Long

              Dim boolstat    As Boolean

              Dim SWAsmEvents As Class1


              Set swApp = CreateObject("SldWorks.Application")

              Set swModel = swApp.ActiveDoc

              swApp.Visible = True


              'Get the title of the assembly document

              SWAsmTitle = swModel.GetTitle


              'Split the title into two strings using the period(.) as the delimiter

              Str = Split(SWAsmTitle, ".")


              boolstat = True


              'Set assemby name for use in mating in module5

              SWAsmName = Str(0)


              FLocation = C:\....


              If Right(FLocation, 6) = "sldprt" Or Right(FLocation, 6) = "SLDPRT" Then

                  PrtAsm = 1 'swDocPART


                  PrtAsm = 2 'swDocASSEMBLY

              End If


              Set SWAddComp = swApp.OpenDoc6(FLocation, PrtAsm, 1, "", Errors, Warnings)


              If FLocation <> "0" Then

              SWAddComp.Visible = False


              If SWAddComp Is Nothing Then

                  boolstat = False

              End If


              'Re-activate the assembly to add new component to it

              Set swModel = swApp.ActivateDoc3(SWAsmTitle, True, swUserDecision, Errors)


              'Set up events

              Set SWAsm = swModel

              Set SWAsmEvents = New Class1

              Set SWAsmEvents.SWAsm = swApp.ActiveDoc


              'Add component to assembly

              Set SWComp = SWAsm.AddComponent5(FLocation, 0, "", False, "", 0, 0, 0)


              swApp.Visible = False

              Set SWAsm = Nothing

              Set SWComp = Nothing

              Set SWAddComp = Nothing

              Set swApp = Nothing


              End If

              End Sub