Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

PARAMETERS TO EXCEL

Status
Not open for further replies.
Replies continue below

Recommended for you

Hello.

Selecting a "Geometrical Set", with this macro generates a text file.

Code:
'##ALGORITMO CATScript
'Export parameters and values of Geometrical Set to txt File
Sub CATMain()
'Documento Activo
Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part 
If Err.Number <> 0 Then                 
Message = MsgBox("This script only works with a CATPart as active document", vbCritical, "Error")
Exit Sub
End If
' What do want to select
Dim EnableSelectionFor(0)
  EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSEL = CATIA.ActiveDocument.Selection
  sSEL.Clear
' Define Selection
  MsgBox "Select the 'Geometrical Set' where the parameters are"
  UserSelection = sSEL.SelectElement2(EnableSelectionFor, "Seleccione otro Geometrical Set", False)
' Evaluation if the selectio is correct or not
If UserSelection <> "Normal" Then
      MsgBox "Error con la seleccion"
    Exit Sub
Else
Set oGeoSet = sSEL.Item(1).Value
REM  MsgBox "The Geometrical Set select is : " & oGeoSet.Name
End If

Set ParametersList = CATIA.ActiveDocument.Part.Parameters
Set SubList = ParametersList.SubList(oGeoSet,FALSE)

'--------------------------------------------------------------------------------
'  Location where the file will be saved
'--------------------------------------------------------------------------------
Dim filename As String
filename = CATIA.FileSelectionBox("Where to save the resulting file?", "*.txt", CatFileSelectionModeSave)
Set Datos = CATIA.FileSystem.CreateFile(filename & ".txt" , True)
Set oSTR = Datos.OpenAsTextStream("ForAppending")
oSTR.Write ("Parameters extract to: " & oPartDoc.Name & ".CATPart" & Chr(10))
oSTR.Write ("The Geometrical Set select is : " & oGeoSet.Name & Chr(10))
oSTR.Write (" "& Chr(10))
oSTR.Write ("Line as: 'Name of Parameter = Value' "& Chr(10))
oSTR.Write (" "& Chr(10))

For i = 1 to SubList.Count
	Set Parameter = SubList.Item(i)
	oSTR.Write (Parameter.Name & " = " & Parameter.ValueAsString & "." & Chr(10) )
	REM MsgBox Parameter.Name & " = " & Parameter.ValueAsString
Next
oSTR.Close

MsgBox "Parameters export : " & (i-1) & "x"  & Chr(10) & "The file was saved in : "  &  chr(10) & filename & ".txt"& chr(10)&  chr(10) & "Process terminated    :D"
End Sub

As usual, I hope it suits your needs

regards.
Urim
 
works fine for one geo set. but if i choose several geo sets macro exports inly one geo set to txt.
 
what's wrong with that? if you want to talk about something else just go for a new thread.
 
A new thread...oh look, it's about a macro too! I'll write macros when I'm in my stone cold grave.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor