Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

CGR to CATPart converter 1

Status
Not open for further replies.

VojtaR

Automotive
Joined
Apr 2, 2020
Messages
20
Location
CZ
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...

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.
 
I'm sure there are peoples here who can modify the script but it would be interesting for you to modify it yourself. You can start searching the forum for keyword batch. There are several examples here and also in CATIA Portable Script Center (and in DS documentation).

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top