title: VBA Macro TO Export Splines from catia to text file(.dat)
body: <p>so I was wondering if i could get some help here. so basically i am trying to find out how to write a dat file that will be able to import splines into <code>Catia</code>. These splines when imported are supposed to act like meshes on a structure, that is, picture a meshed structure, but instead of mesh it will be splines on it. so right now i thought to learn a macro that exports a few splines i created on a structure into a text(.dat) file. but i have been having troubles with the macro i have as it asks me to select a spline, but wont allow me to click on the spline in spec tree. The thing is that i have lots of splines and i would like the macro to just select splines automatically without asking and export them..... PLS HELP ME. thanks alot.</p>
  
  <p>So here is the code:</p>
  
  <pre><code>   Sub CATMain()
  
  '*** *** Definition Variables
  Dim CtrlPoint()
  Dim oCoordinates(1)
  Dim StartKrit As Integer
  
  '*** Query document type ***
  StartKrit = 0
  Set oDoc = CATIA.ActiveDocument
  ObjType = TypeName(oDoc)
  If ObjType = "PartDocument" Then
  DocType = "Part"
  StartKrit = 1
  ElseIf ObjType = "DrawingDocument" Then
  DocType = "Drawing "
  StartKrit = 1
  End If
  
  If StartKrit = 0 Then
  box = MsgBox(" The active document is neither a CATPart still CATDrawing! " + Chr(10) + _
  " The macro can not continue and will now exit " + Chr(10) + _
  "Please select a CATPart or a CATDrawing and start the macro again!", vbCritical + vbOKOnly, "incorrect document type")
  Exit Sub
  End If
  
  
  '*** Create the * .txt files ***
  StorePath = "C: \"
  StoreName = "Splinekoordinaten" &amp; Date
  Set fs = CreateObject("Scripting.FileSystemObject")
  If fs.FileExists(StorePath &amp; StoreName &amp; ".txt ") = True Then
  box = MsgBox(" file ==&gt; " + StorePath + StoreName + " &lt;== already exists! " + Chr(10) + " Do you want to overwrite the file? ", vbCritical + vbYesNo, "file already exists ")
  If box = vbNo Then
  box = MsgBox(" The macro is now finished ", vbInformation + vbOKOnly, " the user stops ")
  Exit Sub
  End If
  End If
  Set A = fs.CreateTextFile("D:\school\INTERNSHIP\Macro\Newest.txt ", True)
  A.WriteLine (" points coordinates of a spline ")
  A.WriteLine (" ")
  If DocType = " Part " Then
  A.WriteLine (" name of CATParts: " &amp; oDoc.Name)
  ElseIf DocType = " Drawing " Then
  A.WriteLine ("name of CATDrawing:" &amp; oDoc.Name)
  End If
  A.WriteLine ("")
  
  '*** Readout from the CATDrawing ***
  If DocType = "Drawing" Then
  Dim otype2D(0)
  Dim Selection
  Set mysel = oDoc.Selection
  mysel.Clear
  otype2D(0) = "Spline2D"
  mysel.Clear
  box = MsgBox(" Please select now the spline ", vbInformation + vbOKCancel, " spline Select ")
  If box = vbCancel Then
  box = MsgBox(" you have the selection canceled " + Chr(10) + _
  " the macro is now finished! ", vbCritical, "abort by user")
  If fs.FileExists(StorePath &amp; StoreName &amp; ".txt") = True Then
  A.Close
  fs.DeleteFile (StorePath &amp; StoreName &amp; ".txt")
  End If
  Exit Sub
  End If
  Selection = mysel.SelectElement2(otype2D, "Please select the spline", False)
  If Selection = "Normal" Then
  oSplineName = mysel.Item(1).Value.Name
  Set oSpline = mysel.Item(1).Value
  A.WriteLine ("name of the selected spline:" &amp; oSplineName)
  A.WriteLine ("")
  A.WriteLine ("")
  Else
  box = MsgBox("you have canceled the selection" + Chr(10) + _
  "the macro is now finished! ", vbCritical, " abort by user ")
  If fs.FileExists(StorePath &amp; StoreName &amp; " .txt ") = True Then
  A.Close
  fs.DeleteFile (StorePath &amp; StoreName &amp; " .txt ")
  End If
  Exit Sub
  End If
  mysel.Clear
  
  Set QuCtrlP = oSpline.EndPoint
  QuCtrlPRaw = QuCtrlP.Name
  QuCtrlPSemi = Split(QuCtrlPRaw, ".")
  QuCtrlPFin = QuCtrlPSemi(1) - 1
  ReDim Preserve CtrlPoint(QuCtrlPFin)
  For j = 0 To QuCtrlPFin
  Set CtrlPoint(j) = oSpline.GetItem("Ktrl-point." &amp; j + 1)
  CtrlPoint(j).GetCoordinates oCoordinates
  A.WriteLine ("point" &amp; j + 1 &amp; "X / Y")
  A.WriteLine (oCoordinates(0))
  A.WriteLine (oCoordinates(1))
  A.WriteLine ("")
  Next
  
  '*** readout from the CATPart ***
  ElseIf DocType = "Part" Then
  Dim otype3D(0)
  Set mysel = oDoc.Selection
  mysel.Clear
  otype3D(0) = "Spline2D"
  mysel.Clear
  box = MsgBox("Please select now the spline", vbInformation + vbOKCancel, "spline Select")
  If box = vbCancel Then
  box = MsgBox("you have canceled the selection" + Chr(10) + _
  "The macro is now finished!", vbCritical, "abort by user")
  If fs.FileExists(StorePath &amp; StoreName &amp; ".txt") = True Then
  A.Close
  fs.DeleteFile (StorePath &amp; StoreName &amp; ".txt ")
  End If
  Exit Sub
  End If
  Selection = mysel.SelectElement2(otype3D, " Please select the spline ", False)
  If Selection = " Normal " Then
  oSplineName = mysel.Item(1).Value.Name
  Set oSpline = mysel.Item(1).Value
  A.WriteLine ("name of the selected spline:" &amp; oSplineName)
  A.WriteLine ("")
  A.WriteLine ("")
  Else
  box = MsgBox("you have canceled the selection" + Chr(10) + _
  "The macro is now finished!", vbCritical, "abort by user")
  If fs.FileExists(StorePath &amp; StoreName &amp; ".txt") = True Then
  A.Close
  fs.DeleteFile (StorePath &amp; StoreName &amp; " .txt ")
  End If
  Exit Sub
  End If
  
  mysel.Clear
  Set QuCtrlP = oSpline.EndPoint
  QuCtrlPRaw = QuCtrlP.Name
  QuCtrlPSemi = Split(QuCtrlPRaw, " ")
  QuCtrlPFin = QuCtrlPSemi(1) - 1
  ReDim Preserve CtrlPoint(QuCtrlPFin)
  For j = 0 To QuCtrlPFin
  Set CtrlPoint(j) = oSpline.GetItem("Ktrl-point." &amp; j + 1)
  CtrlPoint(j).GetCoordinates oCoordinates
  A.WriteLine ("point" &amp; j + 1 &amp; "X / Y")
  A.WriteLine (oCoordinates(0))
  A.WriteLine (oCoordinates(1))
  A.WriteLine ("")
  Next
  End If
  
  '**** Issue Storage Location ****
  Ml = "The macro has completed successfully"
  M2 = "The * .txt file is saved under the following path:"
  M2_ZU_1 = "==&gt;"
  M2_ZU_2 = "&lt;== "
  M3 = " Are you in the path now oeffnen? "
  Title = "memory data"
  skin = vbInformation + vbYesNo
  query = MsgBox(Ml + Chr(10) + Chr(10) + M2 + Chr(10) + Chr(10) + M2_ZU_1 + StorePath + StoreName + M2_ZU_2 + Chr(10) + Chr(10) + M3, skin, Title)
  
  If query = vbYes Then
  ExplorerPath = "C: \ WINDOWS \ explorer.exe"
  Explorer = CATIA.SystemService.ExecuteProcessus(ExplorerPath &amp; "" &amp; StorePath)
  End If
  
  
  End Sub
  </code></pre>