ArnaudG
Mechanical
- Dec 5, 2019
- 25
Hi all,
I created a VBscript (CATVBS file) that works fine to recover the mass of a part and put it inside a custom mass parameter.
I noticed that in parameter formulas it should be possible to run a specific script with the command VBscript->Run(). However I don't understand how it works. I tried to use the full path of my script, only its name, its full name (name + extension) but it won't work. Moreover I don't understand what should be the arguments of the Run command.
How could I use this script (maybe with some modifications, for instance using a Function returning the mass instead of a Sub writing the value in a parameter) in order to run it inside a custom parameter and maybe get the value in this parameter ? The help is not very detailed for stuff like that.
Here's the code (remember it's a catvbs) which will send the calculated mass to a mass parameter called CalculatedWeight (it must exist in your part if you want it to work).
I created a VBscript (CATVBS file) that works fine to recover the mass of a part and put it inside a custom mass parameter.
I noticed that in parameter formulas it should be possible to run a specific script with the command VBscript->Run(). However I don't understand how it works. I tried to use the full path of my script, only its name, its full name (name + extension) but it won't work. Moreover I don't understand what should be the arguments of the Run command.
How could I use this script (maybe with some modifications, for instance using a Function returning the mass instead of a Sub writing the value in a parameter) in order to run it inside a custom parameter and maybe get the value in this parameter ? The help is not very detailed for stuff like that.
Here's the code (remember it's a catvbs) which will send the calculated mass to a mass parameter called CalculatedWeight (it must exist in your part if you want it to work).
Code:
Option Explicit
Sub CATMain()
'On Error Resume Next
Dim oDoc
Set oDoc = CATIA.ActiveDocument
Dim oPart
Set oPart = oDoc.Part
If (Err.Number <>0) Then
MsgBox "Cette macro fonctionne avec un fichier CATPart ouvert uniquement"
Exit Sub
End If
Err.Clear
Dim oBody
Dim objSPAWorkbench
Dim objInertia
Dim oWeight
Set oBody = oPart.MainBody
Set objSPAWorkbench = oPart.Parent.GetWorkbench("SPAWorkbench")
Set objInertia = objSPAWorkbench.Inertias.Add(oBody)
If (Err.Number = 0) Then
oWeight = objInertia.Mass
Else
oWeight = 1
MsgBox "Impossible de déterminer la masse du corps principal." & vbCr & "Masse définie à 1."
End If
oPart.Parameters.Item("CalculatedWeight").Value = oWeight
End Sub