×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro to transfer InertiaVolume to Parameters

Macro to transfer InertiaVolume to Parameters

Macro to transfer InertiaVolume to Parameters

(OP)
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

RE: Macro to transfer InertiaVolume to Parameters

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources