Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

GetCOG in SPA Workbench gives empty result 1

Status
Not open for further replies.

Sebmarshall

Automotive
May 7, 2020
4
FR
Hello

I am trying to create a VBA macro to have an analysis of assembly mass and center of gravity, by checking each part body from each part in the assembly.

The part analysis is made by a sub called from the main one which is working from the assembly.

The macro only make calculation for part body that are at the root ; not in the no show and not empty.

After getting COG coordinates, it calculates the COG coordinates in the assembly reference.

The mass and COG are put in an excel file according to the part category, this is for a race engine, and I need to know the mass and the COG analyse according a given list of part. This is managed from the assembly instance description (MassFIA and CODFIA)


To get the part body COG I apply the SPA Workbench (objMeasurable.GetCOG (Coords) here under), but I get an empty result instead of the expected x,y,z coordinates. Can you help me understand why ?



Here under my code ; sorry if it looks quite messy, this my first one :




Code:
Sub TraitementPart(InstanceCourante, g, WBK, AxisSystemProd, Niveau1, Niveau2, Niveau3, Niveau4, ComptaResultats)

   
    Set PieceInst = InstanceCourante.ReferenceProduct
    Set Piece = PieceInst.Parent.Part
    NbreCorpsDePiece = Piece.Bodies.Count
    
    For h = 1 To NbreCorpsDePiece
    
        Dim CorpsH As Body
        Set CorpsH = Piece.Bodies.Item(h)
        
        'Verifier si le corps de pièce n'est pas vide
        Y = CorpsH.Shapes.Count + CorpsH.HybridBodies.Count + CorpsH.Sketches.Count
        Dim showstate As CatVisPropertyShow
        
        'Verifier si le corps de pièce est en Show
        Set CorpsHSelection = CATIA.ActiveDocument.Selection
        CorpsHSelection.Clear
        CorpsHSelection.Add CorpsH
        Set CorpsHSelection = CATIA.ActiveDocument.Selection.VisProperties
        CorpsHSelection.GetShow showstate
        
        'Verifier si le corps de pièce est à la racine de la part
        InBoolOpp = CorpsH.InBooleanOperation
        
        'Si le corps de pièce ne réponds à l'un des 3 critères précédents alors on passe au suivant
        If (Y <> 0 And showstate = 0 And InBoolOpp = False) Then
                    
        'Calcul masse
      
        Set objSPAWorkbench = PieceInst.Parent.GetWorkbench("SPAWorkbench")
        Set objInertia = objSPAWorkbench.Inertias.Add(CorpsH)
        Set objRef = Piece.CreateReferenceFromObject(CorpsH)
        Set objMeasurable = objSPAWorkbench.GetMeasurable(objRef)
        Dim Coords(2) As Variant
        objMeasurable.GetCOG (Coords)
        
        ' Recuperer le systeme d'axe de la pièce exprimé dans le repère de l'assemblage
        Dim AxisSystemRef(11)
        InstanceCourante.Position.GetComponents AxisSystemRef
        
        'Changement de repere du repere pièce vers le repere de son assemblage (de rang n)
        XcdgN = AxisSystemRef(9) + Coords(0) * AxisSystemRef(0) + Coords(1) * AxisSystemRef(3) + Coords(2) * AxisSystemRef(6)
        YcdgN = AxisSystemRef(10) + Coords(0) * AxisSystemRef(1) + Coords(1) * AxisSystemRef(4) + Coords(2) * AxisSystemRef(7)
        ZcdgN = AxisSystemRef(11) + Coords(0) * AxisSystemRef(2) + Coords(1) * AxisSystemRef(5) + Coords(2) * AxisSystemRef(8)
        
        'Changement de repere de l'assemblage (de rang n) vers le repere du Porduct rang 0
        Xcdg = AxisSystemProd(9) + XcdgN * AxisSystemProd(0) + YcdgN * AxisSystemProd(3) + ZcdgN * AxisSystemProd(6)
        Ycdg = AxisSystemProd(10) + XcdgN * AxisSystemProd(1) + YcdgN * AxisSystemProd(4) + ZcdgN * AxisSystemProd(7)
        Zcdg = AxisSystemProd(11) + XcdgN * AxisSystemProd(2) + YcdgN * AxisSystemProd(5) + ZcdgN * AxisSystemProd(8)
        
        MasseCorpsH = objInertia.Mass
        
        XiMi = Xcdg * MasseCorpsH
        YiMi = Ycdg * MasseCorpsH
        ZiMi = Zcdg * MasseCorpsH
        
        'Verifier les attributs masse/CDG
        Dim PropDescriptionMCDG As String
        PropDescriptionMCDG = InstanceCourante.DescriptionInst
        If PropDescriptionMCDG Like "*MasseFIA*" Then
        MasseFIA = "Oui"
        InertiaFIA = MasseCorpsH
        Else
        MasseFIA = "Non"
        InertiaFIA = 0
        End If
        
        If PropDescriptionMCDG Like "*CDGFIA*" Then
        CDGFIA = "Oui"
        InertiaCDGFIA = MasseCorpsH
        XiMiFIA = Xcdg * InertiaCDGFIA
        YiMiFIA = Ycdg * InertiaCDGFIA
        ZiMiFIA = Zcdg * InertiaCDGFIA
        Else
        CDGFIA = "Non"
        InertiaCDGFIA = 0
        End If
        
        'Inscription des données dans Excel
        NomPiece = Piece.Name
        NomCorps = CorpsH.Name
        WBK.Cells(g, 1) = Niveau1
        WBK.Cells(g, 2) = Niveau2
        WBK.Cells(g, 3) = Niveau3
        WBK.Cells(g, 4) = Niveau4
        WBK.Cells(g, 5) = NomPiece
        WBK.Cells(g, 6) = NomCorps
        WBK.Cells(g, 7) = objInertia.Density
        WBK.Cells(g, 8) = Round(MasseCorpsH, 3)
        WBK.Cells(g, 9) = Round(Xcdg, 3)
        WBK.Cells(g, 10) = Round(Ycdg, 3)
        WBK.Cells(g, 11) = Round(Zcdg, 3)
        WBK.Cells(g, 12) = MasseFIA
        WBK.Cells(g, 13) = CDGFIA
        WBK.Cells(g, 14) = Round(InertiaFIA, 3)
        WBK.Cells(g, 15) = Round(InertiaCDGFIA, 3)
        WBK.Cells(g, 16) = Round(XiMiFIA, 3)
        WBK.Cells(g, 17) = Round(YiMiFIA, 3)
        WBK.Cells(g, 18) = Round(ZiMiFIA, 3)
        
        'Comptabilisation des sommes
        ComptaResultats = Array(ComptaResultats(0) + MasseCorpsH, ComptaResultats(1) + InertiaFIA, ComptaResultats(2) + InertiaCDGFIA, ComptaResultats(3) + XiMiFIA, ComptaResultats(4) + YiMiFIA, ComptaResultats(5) + ZiMiFIA, ComptaResultats(6) + XiMi, ComptaResultats(7) + YiMi, ComptaResultats(8) + ZiMi)
        g = g + 1
        
        End If
    Next

End Sub
 
Replies continue below

Recommended for you

Hello Cthulhu

Yes, measurement is fine with standard tool in 3D, this what I use to do to check the results from the macro.

My macro gives wrong result because it calculates with 0 when getCOG is empty
 
Does measurement work for every body at the first level?
Does GetCOG fail for every body or does it work for some of them?
Do you have all of your parts updated and koaded in design mode?
 
Hello

The "manual" measurement works well for every body at first level.
GetCOG fails for all the bodies from all the part in the product.
The macro manages switch to "design mode" and switch back to "visualization mode" for each instance of the product, this is done in the main sub which is working on the product level before and after calling the Part analyse sub.
 
Can you go step by step and find out why objMeasurable.GetCOG (Coords) return empty result?
I do not have access to catia V5 but I wonder if all is good in the line:

Code:
PieceInst.Parent.GetWorkbench("SPAWorkbench")

- myInstance.Parent is the collection of instances of the Product above, not the product above. Not sure it's the best object to call GetWorkbench.

Again, run your code step by step to know exactly where it fails

stay safe...

Eric N.
indocti discant et ament meminisse periti
 
Hello,

Code seems to be okay. I am able to get coordinates for one of my product instance

Capture1_bhnfnt.jpg



Eventhough you are counting body(shapes) + hybridbodies + sketches, you are measuring only for body, So Check if your product instance contains part body / body with solid to measure.

Dim CorpsH As Body
Set CorpsH = Piece.Bodies.Item(h)
Y = CorpsH.Shapes.Count + CorpsH.HybridBodies.Count + CorpsH.Sketches.Count
CorpsHSelection.Add CorpsH
 
Hello

After some tests, I found the issue. The code was working on some computer and not some other.
Removing the bracket make it work everywhere.

I now have :
Code:
objMeasurable.GetCOG Coords

Instead of :
Code:
objMeasurable.GetCOG (Coords)

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top