×
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!

*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

CATIA Macro measure inertia (mass) only for shown elements

CATIA Macro measure inertia (mass) only for shown elements

CATIA Macro measure inertia (mass) only for shown elements

(OP)
Hello all,

I have created a macro to measure mass of each part in an Assembly(CatProduct).
The macro is exporting BOM of complete assembly as excel file and then using that BOM to get mass of each part present in the assembly.
The macro is working fine but I noticed that it is measuring mass of hidden bodies/elements too.

Can someone help to modify the macro so that it measures only shown elements?

here's my code:

CODE --> catvba

Sub CATMain()
    Dim Template As String
    Template = "C:\Users\xyz\Desktop\BOM.xls"  'modify this path
    Dim productDocument1 As ProductDocument
    Set productDocument1 = CATIA.ActiveDocument

    Dim product1 As Product
    Set product1 = productDocument1.Product

    Dim assemblyConvertor1 As AssemblyConvertor
    Set assemblyConvertor1 = product1.GetItem("BillOfMaterial")

    Dim arrayOfVariantOfBSTR1(4)
    arrayOfVariantOfBSTR1(0) = "Quantity"
    arrayOfVariantOfBSTR1(1) = "Part Number"
    arrayOfVariantOfBSTR1(2) = "Type"
    arrayOfVariantOfBSTR1(3) = "Nomenclature"
    arrayOfVariantOfBSTR1(4) = "Revision"
    Set assemblyConvertor1Variant = assemblyConvertor1
    assemblyConvertor1Variant.SetCurrentFormat arrayOfVariantOfBSTR1

    Dim arrayOfVariantOfBSTR2(1)
    arrayOfVariantOfBSTR2(0) = "Quantity"
    arrayOfVariantOfBSTR2(1) = "Part Number"
    Set assemblyConvertor1Variant = assemblyConvertor1
    assemblyConvertor1Variant.SetSecondaryFormat arrayOfVariantOfBSTR2
    assemblyConvertor1.[Print] "XLS", Template, product1
    
    MsgBox "Bom Exported Successfully"
    
    Dim FileSys
    Set FileSys = CATIA.FileSystem
    Dim xlApp
    Set xlApp = CreateObject("Excel.Application")
    Dim mydoc
    Set mydoc = xlApp.workbooks.Open(Template)
    
    Call Getweight
    
End Sub


Sub Getweight()
    Dim BOMExcel As Object
    
    On Error Resume Next
    
    'if Excel is already running, then get the Excel object
    Set BOMExcel = GetObject(, "Excel.Application")
    
    
    If Err.Number <> 0 Then
        'If Excel is not already running, then create a new session of Excel
        Set BOMExcel = CreateObject("Excel.Application")
        BOMExcel.Visible = True
    End If
    
    'add a new workbook
    BOMExcel.workbooks.Open ("C:\Users\Z0002829\Desktop\Steering Team Macro Support\WIP\BOM.xls")
    BOMExcel.Visible = True
    Set ws = BOMExcel.ActiveWorkbook.Sheets(1)
    
    ws.cells(4, 6).Value = "CAD Weight"
    With ws
        Set findrow = .Range("A:A").Find(What:="Recapitulation", LookIn:=xlValues) 
    End With
    
    
    FindRowNumber = findrow.Row
    
    For i = 1 To FindRowNumber - 1
            If ws.cells(i, 3).Value = "Part" Then
            
            PNtoSearch = ws.cells(i, 2).Value
            'measure weight
            Set productDocument1 = CATIA.ActiveDocument
            
            Set product1 = productDocument1.Product
            
            Dim oSelection As Selection
            
            Set oSelection = CATIA.ActiveDocument.Selection
            
            oSelection.Search "CATAsmSearch.Part.PartNumber=" & PNtoSearch & ",all"
            
             Dim objProd As Product
             
              Set objProd = CATIA.ActiveDocument.Selection.Item2(1).Value
              Set objInertia = GetProductInertiaa(objProd)
              If Not (objInertia Is Nothing) Then
                'Retrieve the mass just to show it worked
                'MsgBox objInertia.Mass
                ws.cells(i, 6).Value = objInertia.Mass * 1000
                
              Else
                MsgBox "The Inertia could not be retrieved!"
              End If
            End If
    Next i
    
    MsgBox "Weight Exported!"
    
    ws.SaveAs Filename:="BOM with Weight exproted.xlsx", FileFormat:=xlWorkbookDefault
    

End Sub

Function GetProductInertia(ByRef iProd As Product) As Inertia
 
  'If successful, this function will return an inertia object
  'Otherwise, Nothing is returned (you should check the return value)
 
  Dim objInertia As Inertia
 

  On Error Resume Next
 
  Set objInertia = iProd.ReferenceProduct.GetTechnologicalObject("Inertia")
  'Set ObjDensity = iProd.ReferenceProduct.GetTechnologicalObject("Density")
  If Err.Number = 0 Then
    Set GetProductInertia = objInertia
  Else
    Set GetProductInertia = Nothing
End If
 
End Function 


thread560-340604: Weight and inertia properties after Union trim
Replies continue below

Recommended for you

RE: CATIA Macro measure inertia (mass) only for shown elements

(OP)
In short, I am searching for how to select "Measure only shown elements" using catvba? as shown in this image:

RE: CATIA Macro measure inertia (mass) only for shown elements

Check each part visibility with Selection.VisProperties

RE: CATIA Macro measure inertia (mass) only for shown elements

(OP)
Thank you for your reply Little Cthulhu.

Selection.VisProperties doesn't solve my issue as there are visible parts having some bodies hiddden.

I want to measure the mass of that part as a whole (but it should not measure the hidden body mass).

RE: CATIA Macro measure inertia (mass) only for shown elements

there is a setting in tools-options that controls that tick-mark:
General-Parameters and Measure: Measuring Criteria: Measure only shown elements
Once you export settings of this tab, you will be able to deduct how you can toggle it on via script (GetAttr/PutAttr-methods):

CODE -->

Set settingControllers1 = CATIA.SettingControllers

Set settingRepository1 = settingControllers1.Item("MeasureSettings")
long2 = settingRepository1.GetAttr("MeasureOnlyShownElementsStatus")
'--------------------------------------------------
' Parameter 1 : (String) "MeasureOnlyShownElementsStatus"
' Returned value : (Variant) (Long) 0
'-------------------------------------------------- 

regards,
LWolf

RE: CATIA Macro measure inertia (mass) only for shown elements

(OP)
Great, I was looking for this only...
I will modify the macro and test it....

Thank you LWolf!

RE: CATIA Macro measure inertia (mass) only for shown elements

Is it worked? i had tried here and I could'nt change the setting...

RE: CATIA Macro measure inertia (mass) only for shown elements

(OP)
Yes, It worked for me!

RE: CATIA Macro measure inertia (mass) only for shown elements

how to measure COGPosition of hole

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! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close