Continue to Site

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 - count number of fasteners

Status
Not open for further replies.

ntweisen

Mechanical
Jul 12, 2010
94
I'm trying to wrtie a marco to count the number of fasteners within a single CATIA part. More specifically, I want to count the number of spot welds but I'm not sure what the best approach is. Any ideas on how to get the number of spot welds?

Here's what I have so far:

Dim partDocument As PartDocument
Dim Part As Part
Dim oSpotWeld As SpotWeld
Dim i, oSpotweldCount As Integer

Set partDocument=CATIA.ActiveDocument
Set Part = partDocument.Part

Than I assume something along the lines of spotweld.count?

 
Replies continue below

Recommended for you

Can you post a sample part ? Question is how the fasteners are represented ? Lines with a specific length or color or something else ?

Regards
Fernando
 
You didn't specify where are those points, so bellow is an example how this can be handle (of course you have to modify the CATScript).

I would search for the name "WELD_CENTER_PT" to create the selection.

Language="VBSCRIPT"
' The goal of this macro is to illustrate the use of the following methods
' on CATIASelection: SelectElement2, Count, Item

Sub CATMain()

'Definition of a list of types for objects
Dim listOfTypes(1)
listOfTypes(0)="Body"
listOfTypes(1)="Hole"

Dim myDocument
Set myDocument = CATIA.ActiveDocument

Dim mySelection As Selection
Set mySelection = myDocument.Selection

'If the selection does not contain any Body or Hole, then the following message
'appears in the bottom left corner of the application, and the script execution
'resumes as soon as a correct object has been selected.
'The SelectElement2 method fills the selection with SelectedElement objects whose Value property is of the
'specified type, as mentionned in the listOfTypes list.
Dim str As String
str=mySelection.SelectElement2(listOfTypes,"Select a Body or a Hole",true)

'Computes the number of Bodies or Holes that have been selected
Dim number
number = mySelection.Count
msgbox "Number of Bodies and Holes selected: " & Cstr(number)

'Since there is no more temporary set of objects, the Count and Item methods apply
'to the whole selection.
number = mySelection.Count
msgbox "Total number of objects in the selection: " & Cstr(number)


'Now, we retrieve each object from the selection
Dim selectedElement As SelectedElement
for i=1 to number
Set selectedElement = mySelection.Item(i)
msgbox "Object " & Cstr(i) & "/" & Cstr(number) & "retrieved."
next

End Sub

Regards
Fernando
 
I created a new macro to count the number of weld points in my catpart. I use selection and search to find the weld center points and axis lines. Some of the code is below:

Dim oSelection as Selection
Set oSelection = CATIA.ActiveDocument.Selection

Dim iCount
Dim i

' search for center points
oSelection.Search "Name=WELD_CENTER_PT,all"

iCount = oSelection.Count
msgbox "Number of weld points is "&icount

' save points in array
Dim aPoints()
ReDim aPoints(iCount)

For i=1 to iCount
Set aPoints(i) = oSelection.Item(i).Value
Next

' search for lines
oSelection.Search "Name=WELD_N*,all"

iCount = oSelection.Count
'msgbox "number of lines is "&icount

' save lines in array
Dim aLines()
ReDim aLines(iCount)

-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor