×
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

CATIA Start Command - On a Loop

CATIA Start Command - On a Loop

CATIA Start Command - On a Loop

(OP)
I have the following VBA code that will loop through an assembly and assign user reference properties to each product and part (different properties depending on if it's a part or a product). A couple of issues are the "Measure Inertia" command happens to each part instance, I only need to do it once for each part number, and if the "Measure Inertia" is not named "InertiaVolume.1" the formula is not recognized. I need to be able to use the "Measure Inertia" no matter what the name is and only instantiate it once for each part number. Any help is very much appreciated...

Code:

Sub CATMain()

GetNextNode CATIA.ActiveDocument.Product

End Sub

Sub GetNextNode(oCurrentProduct)

Dim oCurrentTreeNode As Product
Dim oCurrentTreeNodePart As Part
Dim StrNomenclature, StrDesignation, StrWindows As String
Dim i As Integer
Dim mBody As Body

'Loop through every tree node for the current product
For i = 1 To oCurrentProduct.Products.Count

Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
Set oParameters = oCurrentTreeNode.ReferenceProduct.UserRefProperties

StrWindows = oCurrentTreeNode.ReferenceProduct.Parent.FullName
On Error Resume Next

'Determine if the current node is a part, product or component

If Right(StrWindows, 4) = "Part" Then

Set oCurrentTreeNodePart = oCurrentTreeNode.ReferenceProduct.Parent.Part
Set mBody = oCurrentTreeNodePart.MainBody
Set oPartProdParam = oCurrentTreeNodePart.Parameters
Set oPartRelations = oCurrentTreeNodePart.Relations

While oParameters.Count > 0
oParameters.Remove (1)
Wend

Set oPartSel = CATIA.ActiveDocument.Selection
oPartSel.Clear
oPartSel.Add oCurrentTreeNodePart
AppActivate ("CATIA V5")
SendKeys "c:" & "FrmActivate" & Chr(13), True

CATIA.StartCommand ("Measure Inertia")
CATIA.RefreshDisplay = True
SendKeys "{Tab 6}", True
SendKeys "{Enter}", True
CATIA.RefreshDisplay = True

CATIA.StartCommand "Collapse All"

Set Xdim = oPartProdParam.GetItem("BBLx")
Set Ydim = oPartProdParam.GetItem("BBLy")
Set Zdim = oPartProdParam.GetItem("BBLz")

oParameters.CreateString "DRAWING/PART NO.", oCurrentTreeNode.PartNumber & "_SHT_1"
oParameters.CreateString "MATERIAL/SPECIFICATION", mBody.Name

If Xdim.Value < Ydim.Value And Xdim.Value < Zdim.Value Then
Set paramDimension1 = oParameters.CreateDimension("SURFACE AREA", "AREA", 0#)
Set Xdim = oPartRelations.CreateFormula("AREA", "", paramDimension1, "InertiaVolume.1\BBLy * InertiaVolume.1\BBLz")
ElseIf Ydim.Value < Xdim.Value And Ydim.Value < Zdim.Value Then
Set paramDimension1 = oParameters.CreateDimension("SURFACE AREA", "AREA", 0#)
Set Ydim = oPartRelations.CreateFormula("AREA", "", paramDimension1, "InertiaVolume.1\BBLx * InertiaVolume.1\BBLz")
ElseIf Zdim.Value < Xdim.Value And Zdim.Value < Ydim.Value Then
Set paramDimension1 = oParameters.CreateDimension("SURFACE AREA", "AREA", 0#)
Set Zdim = oPartRelations.CreateFormula("AREA", "", paramDimension1, "InertiaVolume.1\BBLx * InertiaVolume.1\BBLy")
End If

oCurrentTreeNodePart.Update

ElseIf Right(StrWindows, 7) = "Product" Then

While oParameters.Count > 0
oParameters.Remove (1)
Wend

oParameters.CreateString "DRAWING/PART NO.", oCurrentTreeNode.PartNumber & "_SHT_1"

Else
'MsgBox oCurrentTreeNode.PartNumber & " is a component"

End If

'if sub-nodes exist below the current tree node, call the sub recursively

If oCurrentTreeNode.Products.Count > 0 Then
GetNextNode oCurrentTreeNode
End If

Next
End Sub

Thanks,
Culbygt

RE: CATIA Start Command - On a Loop

If you only want to run Measure Inertia once on a part that is in the structure multiple times, check the part for the feature before running the command.

You could do a search for "InertiaVolume.1" inside the part or go after it directly if it is available in the API documentation.

If it is there, don't run the command...else run it.

You could also use a dictionary by adding the part to the dictionary and use the part number as the dictionary key. If the part comes up again in the product, the key will fail because you cannot have multiple keys with the same value. Then you know the inertia measure has already been created. I would only do this if you needed to collect the parts for some downstream use - else go with the first option.

RE: CATIA Start Command - On a Loop

(OP)
lardman363 thanks for your response. I don't think "InertiaVolume.1" is available in the API documentation. Could elaborate more on the dictionary and maybe give an example.

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