Let’s Start Programming! Forums CATIA Macro Programming Macro retrieve CATPartname and CATDrawing name

This topic contains 0 replies, has 1 voice, and was last updated by  Tony_bcn 2 years, 10 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1485

    Tony_bcn
    Participant

    Hello Emmett,

    Below are the steps im doing now, but I am having a hard time completing step no 2 because I am not sure what variables to use. I attached the codes I created below , my only problem is that the macro is not getting the name of the file that I wish to appear in excel.

    This is the information i want to retrieve in Excem CATPartname , CATDrawing name, path where the file is saved, volume and mass.

    Description of the code

    From a list of CATParts

    1. Open a CATpart saved in a specific folder ( ex c:\Temp\)
    2. Retrieve info from catpart (part name)and export to excel
    3. Go to step 1
    3. Save excel sheet in a especific folder (ex c:\Temp\output)

    The code :

    Sub CATMain()

    Set Excel = CreateObject(“Excel.Application”)
    Excel.visible = true

    Set workbooks = Excel.Application.workbooks
    Set myworkbook = Excel.workbooks.Add
    Set objsheet1 = Excel.Sheets.Add

    objsheet1.Cells(1, 1) = “Part Name”
    objsheet1.Cells(1, 2) = “CATIA Part Body mass”
    objsheet1.Cells(1, 3) = “CATIA Part Body mass SMD”
    objsheet1.Cells(1, 4) = “CATIA mass”
    objsheet1.Cells(1, 5) = “Density”
    objsheet1.Cells(1, 6) = “Real mass”
    objsheet1.Cells(1, 7) = “CATPart path”

    Set documents1 = CATIA.Documents
    CATIA.DisplayFileAlerts = False

    set ShellApp=CreateObject(“Shell.Application”) ‘generate a new “Shell Application” object
    set FolBrowser=ShellApp.BrowseForFolder(0,”Choose the folder where your files are stored”,16,17)
    folderinput = “C:\Temp”
    If not FolBrowser is Nothing then
    folderinput=FolBrowser.Self.Path ‘save the path & folder in the variable “folderinput”
    End If

    badfolder = instr(folderinput, “{“)

    If badfolder > 0 then
    folderinput = “C:\Temp”
    End if

    Dim fs, fld
    Set fs = CreateObject(“Scripting.FileSystemObject”)

    Dim fso ‘As FileSystem
    Set fso = CATIA.FileSystem
    sFolderPath = folderinput
    Set folder = fso.GetFolder(sFolderPath)
    Set Files = folder.Files

    For i=1 to Files.Count
    Set file = Files.Item(i)
    if file.Type = “CATIA Part” then

    Set partDocument1 = documents1.Open(File.Path)
    ”””””””””””””””””””””
    Dim selection7 ‘As Selection
    Set selection7 = partDocument1.Selection
    selection7.Search “Name=PartBody,all”
    ””””””””””””””””””measure
    Set objPart = CATIA.ActiveDocument.Part
    Set objRef = objPart.CreateReferenceFromObject(objPart.MainBody)
    Set objSPAWkb = CATIA.ActiveDocument.GetWorkBench(“SPAWorkbench”)
    Set objMeasurable = objSPAWkb.GetMeasurable(objRef)
    Dim weightL ‘as Long
    weightL = CATIA.ActiveDocument.product.Analyze.Mass

    objsheet1.Cells(i+1, 1) = CATIA.ActiveDocument.Name
    objsheet1.Cells(i+1, 2) = weightL
    ””””””””””””””””””””””
    partDocument1.Close
    End If
    Next

    End Sub

    Thanks and regards

Viewing 1 post (of 1 total)

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