5 Replies Latest reply on Jul 1, 2017 2:06 PM by Amen Allah Jlili

    How to open/import CatiaV5 data using vba?

    Michael Pieper

      Good Morning Gentleman,


      I was wondering how to use the available Interconnect functionality to import CATIA V5 data using a simple macro.

      Using the OpenDoc6 method is obviously not doing the needful.


      So I tried to record a macro of manually opening a CATIA V5 element using the file/open dialog within SolidWorks. The process was sucessfull (as expected) but taking a look into the generated macro was only showing the creation of the sldprt but not showing anything regarding the actual method used to open the file in the first step.


      Any advice?


      Thanks in advance and best regards,


        • Re: How to open/import CatiaV5 data using vba?
          Cad Admin

          Are you trying to convert part...then insert into an assembly? or inserting native into an assembly.


          Below is a recorded "inserting native into an assembly", which includes some convert & transform code...


          ' ******************************************************************************

          ' C:\Users\XXXXX\AppData\Local\Temp\swx7732\Macro1.swb - macro recorded on 06/29/17

          ' ******************************************************************************

          Dim swApp As Object


          Dim Part As Object

          Dim boolstatus As Boolean

          Dim longstatus As Long, longwarnings As Long


          Sub main()


              Set swApp = Application.SldWorks


              Set Part = swApp.ActiveDoc


          ' New Document

              Dim swSheetWidth As Double

              swSheetWidth = 0

              Dim swSheetHeight As Double

              swSheetHeight = 0

              Set Part = swApp.NewDocument("D:\Solidworks Custom Paths\Templates\Part.prtdot", 0, swSheetWidth, swSheetHeight)

              Dim swPart As PartDoc

              Set swPart = Part

              swApp.ActivateDoc2 "Part5", False, longstatus

              Set Part = swApp.ActiveDoc

              boolstatus = Part.EditRebuild3()


          ' Insert Component

              Dim AssemblyTitle As String

              AssemblyTitle = Part.GetTitle

              Dim tmpObj As ModelDoc2

              Dim errors As Long

              Set tmpObj = swApp.OpenDoc6("C:\Users\XXXXX\Desktop\mdrawing test\model2.prt.SLDPRT", 1, 32, "", errors, longwarnings)

              Set Part = swApp.ActivateDoc3(AssemblyTitle, True, 0, errors)

              Dim swInsertedComponent As Component2

              Set swInsertedComponent = Part.AddComponent5("C:\Users\XXXXX\Desktop\mdrawing test\model2.prt.SLDPRT", 0, "", False, "", 0.183225696407994, 0.183474767172876, 0.18322569640805)

              swApp.CloseDoc "C:\Users\XXXXX\Desktop\mdrawing test\model2.prt.SLDPRT"

              Dim TransformData() As Double

              ReDim TransformData(0 To 15) As Double

              TransformData(0) = 1

              TransformData(1) = 0

              TransformData(2) = 0

              TransformData(3) = 0

              TransformData(4) = 1

              TransformData(5) = 0

              TransformData(6) = 0

              TransformData(7) = 0

              TransformData(8) = 1

              TransformData(9) = 0

              TransformData(10) = 0

              TransformData(11) = 0

              TransformData(12) = 1

              TransformData(13) = 0

              TransformData(14) = 0

              TransformData(15) = 0

              Dim TransformDataVariant As Variant

              TransformDataVariant = TransformData

              Dim swMathUtil As Object

              Set swMathUtil = swApp.GetMathUtility()

              Dim swTransform As Object

              Set swTransform = swMathUtil.CreateTransform((TransformDataVariant))

              boolstatus = swInsertedComponent.SetTransformAndSolve2(swTransform)

              Dim swcomp As Object

              Set swcomp = Part.SelectionManager.GetSelectedObject6(1, -1)

              boolstatus = swcomp.MakeVirtual2(True)

          End Sub


          FYI this was with a UN NX part...however Catia should be similar enough....