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:
Any input would be very appreciated.
Thank you.
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.