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!

Macro to transfer InertiaVolume to Parameters

Status
Not open for further replies.

rickyt

Automotive
Jun 26, 2002
233
US
In need of some help on setting a Variable equal to the density value of a measurement.



I have created a macro that will take an inertia volume measurement (InertiaVolume.Part) and
create relations to the Parameter section of the tree.
The parameter section of the tree will transfer into an adobe 3d file as attributes.
Sometimes I will have a product or part with multiple density values.
The measure inertia will return a value of -1 (Not Uniform) if there are multiple density values.

I have been trying to figure out how to set a variable equal to my density of the inertia measurement.
Then use this variable in the IfThenElse statement.

Here is my working macro for a CATPart macro
========================================================================================

Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

Set parameters1 = part1.Parameters
Set realParam1 = parameters1.CreateReal("CAD Part Volume mm3", 0.000000)
Set relations1 = part1.Relations
Set formula1 = relations1.CreateFormula("Formula.Measure-Parameter Volume", "", realParam1, "`InertiaVolume.Part\Volume`/1mm3")


'Set a numeric value of Densvalue for IfThenElse statement
'A new parameter could be created and used to read value if needed, then delete parameter
'Densvalue = Part1.Parameters.Value("`InertiaVolume.Part\Density` ") HELP NEEDED HERE

' value set to a number for testing of IfThenElse, Densvalue needs to be read from inertia measurement
Densvalue = 4

'message box for temporary debugging to see the value of Densvalue
MsgBox (Densvalue)


Set parameters2 = part1.Parameters
'If Densvalue > 0 Then
Set realParam2 = parameters2.CreateReal("CAD Part Density kgm3", 0.000000)
Set relations2 = part1.Relations
Set formula2 = relations2.CreateFormula("Formula.Measure-Parameter Density", "", realParam2, "`InertiaVolume.Part\Density`/1kg_m3")

'Else
'Set realParam2 = parameters2.CreateString("CAD Part Density kgm3", "Not Uniform")

'End If


Set parameters3 = part1.Parameters
Set realParam3 = parameters3.CreateReal("CAD Part Mass grams", 0.000000)
Set relations3 = part1.Relations
Set formula3 = relations3.CreateFormula("Formula.Measure-Parameter Mass", "", realParam3, "`InertiaVolume.Part\Mass`/1g")

Set parameters4 = part1.Parameters
Set realParam4 = parameters4.CreateReal("CAD Bounding Box Length in X mm", 0.000000)
Set relations4 = part1.Relations
Set formula4 = relations4.CreateFormula("Formula.Measure-Parameter bblx", "", realParam4, "`InertiaVolume.Part\BBLx`/1mm")

Set parameters5 = part1.Parameters
Set realParam5 = parameters5.CreateReal("CAD Bounding Box Length in Y mm", 0.000000)
Set relations5 = part1.Relations
Set formula5 = relations5.CreateFormula("Formula.Measure-Parameter bbly", "", realParam5, "`InertiaVolume.Part\BBLy`/1mm")

Set parameters6 = part1.Parameters
Set realParam6 = parameters6.CreateReal("CAD Bounding Box Length in Z mm", 0.000000)
Set relations6 = part1.Relations
Set formula6 = relations6.CreateFormula("Formula.Measure-Parameter bblz", "", realParam6, "`InertiaVolume.Part\BBLz`/1mm")


End Sub




==========================================================================================================

Thanks,
Rick
 
 http://files.engineering.com/getfile.aspx?folder=39cdcb25-fa54-4b72-bde2-cc0ac973aec4&file=161031__Image009.jpg
Replies continue below

Recommended for you

Solved with help from a user at COE.
Here is the updated script.




Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part

Set parameters1 = part1.Parameters
Set realParam1 = parameters1.CreateReal("CAD Part Volume mm3", 0.000000)
Set relations1 = part1.Relations
Set formula1 = relations1.CreateFormula("Formula.Measure-Parameter Volume", "", realParam1, "`InertiaVolume.Part\Volume`/1mm3")


'Set a numeric value of Densvalue for IfThenElse statement
Densvalue = Part1.Parameters.Item("`InertiaVolume.Part\Density`").Value

Set parameters2 = part1.Parameters

If Densvalue > 0 Then
Set realParam2 = parameters2.CreateReal("CAD Part Density kgm3", 0.000000)
Set relations2 = part1.Relations
Set formula2 = relations2.CreateFormula("Formula.Measure-Parameter Density", "", realParam2, "`InertiaVolume.Part\Density`/1kg_m3")

Else
Set realParam2 = parameters2.CreateString("CAD Part Density kgm3", "Not Uniform")

End If


Set parameters3 = part1.Parameters
Set realParam3 = parameters3.CreateReal("CAD Part Mass grams", 0.000000)
Set relations3 = part1.Relations
Set formula3 = relations3.CreateFormula("Formula.Measure-Parameter Mass", "", realParam3, "`InertiaVolume.Part\Mass`/1g")

Set parameters4 = part1.Parameters
Set realParam4 = parameters4.CreateReal("CAD Bounding Box Length in X mm", 0.000000)
Set relations4 = part1.Relations
Set formula4 = relations4.CreateFormula("Formula.Measure-Parameter bblx", "", realParam4, "`InertiaVolume.Part\BBLx`/1mm")

Set parameters5 = part1.Parameters
Set realParam5 = parameters5.CreateReal("CAD Bounding Box Length in Y mm", 0.000000)
Set relations5 = part1.Relations
Set formula5 = relations5.CreateFormula("Formula.Measure-Parameter bbly", "", realParam5, "`InertiaVolume.Part\BBLy`/1mm")

Set parameters6 = part1.Parameters
Set realParam6 = parameters6.CreateReal("CAD Bounding Box Length in Z mm", 0.000000)
Set relations6 = part1.Relations
Set formula6 = relations6.CreateFormula("Formula.Measure-Parameter bblz", "", realParam6, "`InertiaVolume.Part\BBLz`/1mm")


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top