Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA Start Command - On a Loop

Status
Not open for further replies.

cubygt

Aerospace
Feb 10, 2017
10
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
 
Replies continue below

Recommended for you

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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor