Macro - count number of fasteners
Macro - count number of fasteners
(OP)
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?
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?





RE: Macro - count number of fasteners
Regards
Fernando
RE: Macro - count number of fasteners
http://excelspreadsheetshelp.blogspot.com
RE: Macro - count number of fasteners
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
RE: Macro - count number of fasteners
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)
http://excelspreadsheetshelp.blogspot.com - http://scripting4v5.com