Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

MACRO - Catia Rename to File Name

Status
Not open for further replies.

PavelsBabbles

Aerospace
Oct 28, 2015
3
0
0
US
I need some help with this macro (I found this from a different thread on here). The objective with this macro is to rename all parts/assemblies in catia to their respective file names. I can not get this code to run properly. Does anyone have an alternative macro, or see what is wrong with this one?

Code:
Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument

  If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
     MsgBox "Active CATIA Document is not a Product. Open a Product file and run this script again.", , msgboxtext
     Exit Sub
   End If
   Call ListingNames(productDocument1.Product)


End Sub

Sub ListingNames(current_prod)
If current_prod.Products.Count > 0 Then
For i = 1 To current_prod.Products.Count
Call ListingNames(current_prod.Products.Item(i))
If InStr(current_prod.Products.Item(i).ReferenceProduct.Parent.Name, ".CATProduct") > 0 Then
current_prod.Products.Item(i).PartNumber = Left(current_prod.Products.Item(i).ReferenceProduct.Parent.Name, Len(current_prod.Products.Item(i).ReferenceProduct.Parent.Name) - 11)
End If
Next
Else
If InStr(current_prod.ReferenceProduct.Parent.Name, ".CATPart") > 0 Then
current_prod.PartNumber = Left(current_prod.ReferenceProduct.Parent.Name, Len(current_prod.ReferenceProduct.Parent.Name) - 8)
End If
End If
End Sub
 
Replies continue below

Recommended for you

Hello

I think you want to rename your files ( CATPart ) with the reference file .

Below I run a macro from a form , you must pay attention to the file names , do not have an accent .

Code:
'*** macro Jean-Pierre LE CAM, 10/10/2015 **********
'*** pour intégration dans Macro listing RefInst ***
'*** cao.3d.pro.com*********************************
Public Ndoc As Document
Public NomDoc As String
Public NomRef As String
Public DocTeteNamePublic
Public NomDocumentCatia As String
Public ProductDocumentCatia As ProductDocument
Public PartDocumentCatia As PartDocument
Public NomRacName As String
Public Property Get ProduitSelectionne() As ProductDocument
 Set ProduitSelectionne = CATIA.ActiveDocument
End Property
Public Property Get DocumentCatia() As Documents
    Set DocumentCatia = CATIA.Documents
End Property
Public Function TypeDocuments()
Dim LgName As Integer
Dim Lgext As Integer
Dim LgRest As Integer
Dim PathDoc As String
Dim PathSave As String
'
For Each Ndoc In ProduitSelectionne.Application.Documents
NomDocumentCatia = Ndoc.Name
    If DocTeteName = NomDocumentCatia Then
    Else
        If (InStr(1, NomDocumentCatia, "CATProduct") > 0) Then
            Set ProductDocumentCatia = DocumentCatia.Item(NomDocumentCatia)
            NomDoc = ProductDocumentCatia.Name
            NomRef = ProductDocumentCatia.Product.PartNumber
        End If
            If (InStr(1, NomDocumentCatia, "CATPart") > 0) Then
                Set PartDocumentCatia = DocumentCatia.Item(NomDocumentCatia)
                PathDoc = PartDocumentCatia.Path
                NomDoc = PartDocumentCatia.Name
                LgName = Len(NomDoc)
                LgRest = LgName - 7
                NomDoc = Left(PartDocumentCatia.Name, LgRest)
                NomRef = PartDocumentCatia.Product.PartNumber
                    If NomRacName = NomRef Then
                    Else
                        PathSave = PathDoc & "\" & NomRef & ".CATPart"
                        PartDocumentCatia.SaveAs PathSave
                    End If
        End If
    End If
Next
End Function
 
Status
Not open for further replies.
Back
Top