Let’s Start Programming! Forums CATIA Macro Programming Macro code save images and list parts in Excel

This topic contains 4 replies, has 2 voices, and was last updated by  Emmett Ross 2 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1447

    Tony_bcn
    Participant

    Hello Ermett,

    I would like to ask if you know how to create macro codes for the following:

    1. Generating screenshots from a list of catparts and saving it in a specific folder

    2. Export all CATPART file names in an excel sheet once all files are saved in a folder

    Thanks in advance
    Toni

    #1448

    Emmett Ross
    Keymaster

    Hi Toni,

    Welcome to the forum!

    1. There is an article here that will give you an idea of how to create a screen shot macro: http://www.scripting4v5.com/additional-articles/screen-shot-macro/ If you have any specific questions about the code please let me know.

    2. Are you exporting from CATIA to Excel, Excel to CATIA, or something else? Please explain more what you are trying to do. Also, there are example codes how to export in my book (http://www.scripting4v5.com/books/vb-scripting-for-catia-v5/) and macro pack: http://www.scripting4v5.com/books/catia-macro-pack-download/.

    Emmett

    #1449

    Tony_bcn
    Participant

    Hello Emmet,

    thanks again for your nice reply.

    The macro I want to create should do the steps described below

    From a list of CAT Parts

    1. Open a CATpart
    2. Retrieve info from catpart (part number etc..)
    3. Change viewpoint to iso and hide the specification tree.
    4. Reframe part in window so that it is all visible.
    5. Take picture and store it in required location with specific filename (probably the catpart filename and the current date / time and the fileextension for the picture type.)
    6. Write info including hyperlink to open picture to an empty line in an excel file.
    7. Close the catpart
    8. Goto step 1.

    Regarding step number 2 I didn’ t find info regarding this topic and also I dont know how to create the loop in order to save the list of images.

    Thanks again and regards
    Toni

    PS: My current version is CATIA V5 R24

    #1451

    Tony_bcn
    Participant

    Hello Emmet,

    as discussed , I started to retrieve information from a list of catparts,
    using the code published in your book.

    Now I would like to be able to run this script on every part and export the properties into the same Excel sheet. ( like I am showing in this code)
    Any ideas how to add on to my code to accomplish this?

    Remarks: The code opens the excel sheet but is not able to export the properties of the catparts.

    Any ideas how to fix this issue?

    Thanks and regards

    Sub CATMain()
    Dim documents1 As Documents
    Set documents1 = CATIA.Documents
    MsgBox “The number of documents is ” & documents1.Count
    Dim doc1 As String
    Set doc1 = documents1.Item(1)
    ‘MsgBox doc1.Name
    ‘MsgBox doc1.FullName
    ‘For Each doc1 in documents1
    ‘MsgBox doc1.Name
    ‘Next
    Dim partDoc1 as PartDocument
    Set partDoc1 = doc1
    MsgBox partDoc1.Name

    ‘to excel

    Dim Excel As Object
    Dim workbooks As workbooks
    Dim workbook As workbook
    Dim worksheet As Excel.worksheet

    On Error Resume Next
    Set Excel = GetObject(, “EXCEL.Application”)
    If Err.Number <> 0 Then
    Err.Clear
    Set Excel = CreateObject(“EXCEL.Application”)
    Else
    Err.Clear
    MsgBox “Please note you have to close Excel”, vbCritical
    Exit Sub
    End If

    Excel.Visible = True

    ‘load a sheet

    Set workbooks = Excel.Application.workbooks
    Set myworkbook = Excel.workbooks.Add
    Set myworksheet = Excel.ActiveWorkbook.Add
    Set myworksheet = Excel.Sheets.Add

    ‘download the properties
    ‘row one
    Excel.Cells(1,1)=”Part Number”
    Excel.Cells(1,2)=”Thickness”
    Excel.Cells(1,3)=”Material”
    Excel.Cells(1,4)=”Mass”

    ‘row 2
    Excel.Cells(2,1)= doc1
    Excel.Cells(2, 2) = getThickness
    Excel.Cells(2, 3) = getMaterial
    Excel.Cells(2, 4) = getMass

    End Sub

    #1502

    Emmett Ross
    Keymaster

    You need to define what getThickness, getMeterial, etc. are. Try adding the below code after Dim partDoc1 as PartDocument:

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘CATIA Macro Programming’ is closed to new topics and replies.