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!

Python COM interfaces properties extraction

Status
Not open for further replies.

cencio86

Aerospace
Apr 2, 2009
3
Hi,
I'm looking for the possible integration of CATIA V5 with other CAE tools. I'm forced to use Python scripting language to extract physical properties from CAD model (also if there are Visual Basic scripts that do the same thing in the right way ;-C). I manage to extract quantities such as mass, density, volume but other properties as COG, inertia matrix or other vector quantities are not working properly (I have try with .GetTechnologicalObject("Inertia") and Analyze.GetGravityCenter methods but they work only for mass, volume, density, etc... as just previously described).
I hope I was clear in the description of my situation.
Has anyone had the same problem and maybe they have solved it ?
Any help or link to online resources that allow to tackle the problem are welcome.

Thanks in advance
 
Replies continue below

Recommended for you

Hi,

Did you checked the v5automation.chm file from CATIA instalation folder?

I believe there are some examples there. Also, you can check FAQ section here or search the forum (you will find also a wide script collection which maybe can help you).

In CATScript you can get also the CoG, surface, BbL...

Regards
Fernando

 
Thanks Fernando for the rapid answer,
yes, I have just checked the v5automation.chm file from CATIA instalation folder. All the examples that I have find are using the .GetTechnologicalObject("Inertia") and Analyze.GetGravityCenter methods but they not work properly in my case. They only work well for Mass, Density, Volume, etc... but not for CGO, Inertia Matrix, etc...

I'm forced to use Python script and not CATScript because the interfaces with the CAE tools are all implemented with Python and I wanted to avoid the use of another scripting language.
As a last solution I think I'll use CATScript.
 
Sorry for this late answer, I've been bussy with other things....

Don't know about Python (I would like to, but who knows when I will have time...). Anyway , in CATScript you can get data like this (I see that mass and volum there is no problem for you, I just put it here to let others how they can get this parameters, they will find also CoG).

Language="VBSCRIPT"

CATIA.StatusBar = "Calculating inertia data and write user defined properties by ferdo"
'*********************************************************
' Purpose: This macro can be used interactively to compute inertia data for a CATPart
' Creation of some user defined properties
' Inputs : Part Name by selecting in graphic area
' Author: ferdo (Disclaimer: You use this code at your own risk)
'*********************************************************
Sub CATMain()

CATIA.DisplayFileAlerts = False

Dim objSelection 'as Selection
Set objSelection = CATIA.ActiveDocument.Selection
' clear selection
objSelection.Clear
' select root product (I suppose we have CATProduct document here
objSelection.Add CATIA.ActiveDocument.Product
CATIA.StartCommand "DESIGN MODE"

Dim Message, Style, Title, Response, MyString
Message = ( "This macro calculate standard inertia data and write them in user defined properties and works ONLY in CATPart. You can continue, a new window will open" &_
(chr(13)) &_
""&(chr(13))&_
" Do you want to continue ?")
Style = vbYesNo + vbDefaultButton1 'Define buttons.
Title = "Purpose "
Response = MsgBox(Message, Style, Title)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes"


'Acquire the name from the user selection

Dim Doc As ProductDocument
Set Doc = CATIA.ActiveDocument

Dim Prod_Root As Product
Set Prod_Root = Doc.Product

Dim Prods_Root As Products
Set Prods_Root = Prod_Root.Products

Dim oSelection 'As Selection
Set oSelection = Doc.Selection

Dim Status As String
Dim InputObjectType(0)
Dim prt As Part

MsgBox "Select part in graphic area or in specification tree"

oSelection.Clear
InputObjectType(0) = "Part"
Status = oSelection.SelectElement2(InputObjectType, "Select a part", False)
If Status = "Normal" And oSelection.Count = 1 Then
Set prt = oSelection.Item(1).Value

CATIA.StartCommand "Open in new window"

End If

' Find the workbench
Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench ( "SPAWorkbench" )

' Create the inertia
Dim ProductInertia As Inertia
Set ProductInertia = TheSPAWorkbench.Inertias.Add(prt)

' Get the inertia data
Dim St_Mass 'As Double
St_Mass = ProductInertia.Mass

Dim Coordinates(2)
ProductInertia.GetCOGPosition Coordinates


Dim St_Volume 'As Double
Set objPart = CATIA.ActiveDocument.Part
Set objRef = objPart.CreateReferenceFromObject(objPart.MainBody)
Set objSPAWkb = CATIA.ActiveDocument.GetWorkBench("SPAWorkbench")
Set objMeasurable = objSPAWkb.GetMeasurable(objRef)
St_Volume = objMeasurable.Volume


Dim filename As String
filename = CATIA.ActiveDocument.Name


Set iProduct = CATIA.ActiveDocument.Product
Set parameters1 = iProduct.UserRefProperties

Set iparameter2 = parameters1.CreateString("File_Name", Cstr(filename))
Set iparameter3 = parameters1.CreateString("CATIA_Mass (kg)", Cstr(St_Mass))
Set iparameter4 = parameters1.CreateString("CATIA_Volume (m3)", Cstr(St_Volume))

Set iparameter5 = parameters1.CreateString("Gx", Cstr(Coordinates(0)*1000) & "mm")
Set iparameter6 = parameters1.CreateString("Gy", Cstr(Coordinates(1)*1000) & "mm")
Set iparameter7 = parameters1.CreateString("Gz", Cstr(Coordinates(2)*1000) & "mm")

End If

End Sub

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top