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

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?

http://excelspreadsheetshelp.blogspot.com

RE: Macro - count number of fasteners

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
 

RE: Macro - count number of fasteners

(OP)
All of the spot welds have a point at their center called "WELD_CENTER_PT" as well as a line projected normal to the mating parts called "WELD_LN".

http://excelspreadsheetshelp.blogspot.com

RE: Macro - count number of fasteners

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
 

RE: Macro - count number of fasteners

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

http://excelspreadsheetshelp.blogspot.com - http://scripting4v5.com

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