×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

MACRO - Catia Rename to File Name

MACRO - Catia Rename to File Name

MACRO - Catia Rename to File Name

(OP)
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 

RE: MACRO - Catia Rename to File Name

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources