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!

Catia Macro for mass

Status
Not open for further replies.

VojtaR

Automotive
Apr 2, 2020
20
CZ
Hello,

I have quite special request...

I would like to have "live" mass parameter in the drawing. ("live" in a meaning that parameter in drawing will get updated according to parameter in product and that will get updated according to part's design).

I would like to create macro which will work in Product by selecting part from that product or on the whole product. So if I select a part it will take its bodie's Material(Density) * Volume (to get mass). And create a parameter in the product. The parameter should be linked to the material assigned in that part (not just a number). In case there are two or more bodies, it will consider all bodies within the part with its densities.

I was able to find a code to get part's mass, but it is a "dead" number, I need it to get updated if there is any change in that part. Here is the code:
Code:
Sub CATMain()

' Retrieve the selected component
Dim oSelection As Selection
Set oSelection = CATIA.ActiveDocument.Selection
Dim oProduct As AnyObject
On Error Resume Next
Set oProduct = oSelection.FindObject("CATIAProduct")
If (Err.Number <> 0) Then
MsgBox "No selected part/product"
Else
On Error GoTo 0

' Compute the inertia
Dim oInertia As AnyObject
Set oInertia = oProduct.GetTechnologicalObject("Inertia")

' Read the inertia data
Dim dMass As Double
dMass = oInertia.Mass

' Create mass parameter

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Set product1 = product1.ReferenceProduct

Dim parameters1 As Parameters
Set parameters1 = product1.Parameters

Dim mass As Dimension
Set mass = parameters1.CreateDimension("", "MASS", dMass)

End If
End Sub

Any input would be very appreciated.

Thank you.
 
Replies continue below

Recommended for you

Try approaching it this way so we can help you troubleshoot the code as you write it;

[ul]
[li]Start in the destination drawing so you can identify it in the code. It is possible to have the user select a drawing view in order to find the associated 3D file. You should be able to skip the user interaction and find it directly with code if you want that.[/li]
[li]Create a new parameter with external link to the target 3D file and attribute of whatever bodies you target.[/li]
[li]Create the textbox with an attribute link to the external parameter in your drawing specification tree. (I see InsertVariable() available for linking the textbox)[/li]
[/ul]

If you have a material applied as you say, you should be able to just InertiaMeasure the Mass directly rather than do an additional calculation in the code.

Landscape-Start_1.CATDrawing_x80qww.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top