-
1
- #1
VojtaR
Automotive
- Apr 2, 2020
- 20
Hello everyone,
would anyone be able to modify this macro so it translates all CGRs in folder to CATParts?
Following macro is doing file by file, with manual selection of each file...
Thank you.
would anyone be able to modify this macro so it translates all CGRs in folder to CATParts?
Following macro is doing file by file, with manual selection of each file...
Code:
Sub CATMain()
Dim sInputFile As String
sInputFile = CATIA.FileSelectionBox("Choose cgr file...", "*.cgr", CatFileSelectionModeOpen)
Dim sInputFileName As String
sInputFileName = Left(sInputFile, InStrRev(sInputFile, ".") - 1)
Dim sInputFileNameV4 As String
If Len(sInputFileName) > 72 Then
sInputFileNameV4 = Left(sInputFileName, 72) & ".model"
Else
sInputFileNameV4 = sInputFileName & ".model"
End If
Dim oDoc As document
Set oDoc = CATIA.documents.Read(sInputFile)
oDoc.ExportData sInputFileNameV4, "model"
oDoc.Close
Set oDoc = CATIA.documents.Open(sInputFileNameV4)
Dim docSel As selection
Set docSel = oDoc.selection
If CATIA.SystemConfiguration.Release < "16" Then
docSel.Search "Name=CAT_1000_1"
Else
docSel.Search "V4Model.MASTER"
End If
docSel.Copy
Dim iPartNumber As String
iPartNumber = Mid(sInputFileName, InStrRev(sInputFileName, CATIA.FileSystem.FileSeparator) + 1)
Set oDoc = CATIA.documents.Add("Part")
Dim iProduct As Product
Set iProduct = oDoc.Product
iProduct.PartNumber = iPartNumber
Set docSel = oDoc.selection
docSel.Add iProduct
docSel.Paste
iProduct.Update
oDoc.SaveAs sInputFileName & ".CATPart"
oDoc.Close
Set oDoc = CATIA.documents.Item(CATIA.documents.Count)
oDoc.Close
Set oDoc = CATIA.documents.Open(sInputFileName & ".CATPart")
End Sub
Thank you.