Components stay floating in assy after insertion by API

Hi Everyone,

The company I work for receives vast amounts of 3D CAD Data via IGS files. These IGS files normally are parts, which can be put together in an assembly and form a component together. In order to reduce the manual labour, I am now programming a macro which converts all IGS files in it's folder to SLDPRT's, starts an assy, inserts the new SLDPRT, then transforms the origin so the origin of the part lines up with the origin of the assembly, repeats this proces for all IGS files in it's folder and  saves and closes all documents. So far so good. All of this is working.

But here comes the problem;

It only fixes the first component which is inserted in the assy. The second (and all latter ones for that matter) stay floating. I have looked into the fixcomponent Method but I can't seem to get it to work properly. Who can help me out?

PS: The code is still sloppy, I have quite some experience in Excel VBA, but these are my first endeauvours in SW, so be kind

The code I have so far:

Dim swApp           As Object

Dim Part            As Object

Dim boolstatus      As Boolean

Dim longstatus      As Long

Dim longwarnings    As Long

Dim sFileName       As String

Dim Path            As String

Dim partFileName    As String

Dim FixFileName     As String

Dim openDocs        As Variant

Dim currentModel    As Variant

Dim swPartDoc       As PartDoc

Dim swAssemblyDoc   As AssemblyDoc

Dim swComp          As Component2

Dim swMathUtil      As SldWorks.MathUtility

Dim swXform         As SldWorks.MathTransform

Sub main()

Set swApp = _

Application.SldWorks

Path = Left(swApp.GetCurrentMacroPathName(), InStrRev(swApp.GetCurrentMacroPathName(), "\"))

sFileName = Dir(Path & "*.igs")

Set Part = swApp.NewDocument("H:\SolidWorks\Common Data\VdB Assembly.asmdot", 0, 0, 0)

swApp.ActivateDoc2 "Assem1", False, longstatus

longstatus = Part.SaveAs3(Path + "Assy.SLDASM", 0, 2)

Do Until sFileName = ""

        boolstatus = swApp.LoadFile2(Path + sFileName, "r")

        Set Part = swApp.ActiveDoc

        Dim myModelView As Object

        Set myModelView = Part.ActiveView

        myModelView.FrameState = swWindowState_e.swWindowMaximized

        longstatus = Part.ImportDiagnosis(True, False, True, 0)

        Part.ClearSelection2 True

        Part.ClearSelection2 True

        longstatus = Part.SaveAs3(Path + Part.GetTitle + ".SLDPRT", 0, 0)

        openDocs = swApp.GetDocuments()

        For Each currentModel In openDocs

            If (currentModel.GetType = swDocumentTypes_e.swDocASSEMBLY) Then

                Set swAssemblyDoc = currentModel

            End If

            If (currentModel.GetType = swDocumentTypes_e.swDocPART) Then

                Set swPartDoc = currentModel

                partFileName = swPartDoc.GetPathName()

            End If

        Next

        Set swMathUtil = swApp.GetMathUtility

        Set swXform = swMathUtil.CreateTransform(Nothing)

        swComp.Transform2 = swXform

        swAssemblyDoc.EditRebuild3

        longstatus = swAssemblyDoc.SaveAs3(Path + "Assy.SLDASM", 0, 2)

        swApp.CloseDoc swPartDoc.GetTitle

        sFileName = Dir

Loop

swApp.CloseAllDocuments (True)

End Sub

SolidworksApi macros