×
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

How do I filter Points out of an OpenBody within VBA?
2

How do I filter Points out of an OpenBody within VBA?

How do I filter Points out of an OpenBody within VBA?

(OP)
I am trying to improve a VBA utility so that the program will filter out all of the points, regardless of their typename, out of an openbody that is selected by the user. An example of this would be selecting an openbody of points and vectors that represent a fastener pattern. The points can be made my the point, intersect, or project function. I only want to work with the points within the openbody; so, I've tried to use 'FilterCorrespondence' with a 'Point' or type string identifier, to filter out the points from the selection. I get a 'not a valid VB function for this even though it shows up in the options list after the 'Selection.'. I've tried serveral things to reliably segregate points with no luck.

Code snippet:

If TypeName(SelectedPoints) = "HybridBody" And Selection3D.Count = 1 Then
    Set SelectedPointsDoc = CatDocs.Item(Selection3D.FindObject("CATIAPart").Parent.Name)
    PointCount = SelectedPoints.HybridShapes.Count
    Selection3D.Clear
      
    For j = 1 To PointCount
     Selection3D.Add (SelectedPoints.HybridShapes.Item(j))
    Next

ReDim SelType(0) As Variant
SelType(0) = "Point"
Filter1 = Selection3D.FilterCorrespondence(SelType)
<<<Dies Here

RE: How do I filter Points out of an OpenBody within VBA?

2
Try This.

But bear in mind that if the result of projection or intersection is a point you will not find it easily.

Sub CATMain()

Set cPoints = New Collection

If TypeName(SelectedPoints) = "HybridBody" And oSel.Count = 1 Then
    Set SelectedPointsDoc = CAtDocs.Item(oSel.FindObject("CATIAPart").Parent.Name)
    PointCount = SelectedPoints.HybridShapes.Count
    oSel.Clear
    
    
   Dim SelType(0)
   SelType(0) = "Point"
   
    For j = 1 To PointCount
         oSel.Add (SelectedPoints.HybridShapes.Item(j))
         
       bRes = oSel.FilterCorrespondence(SelType)
        
        If bRes = True Then
            cPoints.Add oSel.Item(oSel.Count).Value.Name
        End If

        oSel.Clear
    Next j
    
End If

For Each p In cPoints
oSel.Add p
Next

End Sub

RE: How do I filter Points out of an OpenBody within VBA?

(OP)
Thanks 'nev99', that worked perfectly; but, you were right about the 'intersect' and 'project'. I really hoped that it would see when these were indeed points. The 'Point-Type' that is used on the Selection allows the user to pick intersects and projections when they are points, I thought this woluld work the same. I've tried 'Vertex' and 'CATIAPoint'. No luck. Any ideas would be appreciated.

RE: How do I filter Points out of an OpenBody within VBA?

OK. I have a workaround using the following provided the intersect or project does not create more than one point.
Try this. It does not even use the .FilterCorrespondence method

Sub CATMain()

'---Find and filter points no matter if
'---result of intersection or projection
'---if intersection or projection create
'---more than one point they will be ignored

Dim coords(2)

Set cPoints = New Collection

Set CAtDocs = CATIA.Documents
Set oSel = CATIA.ActiveDocument.Selection

Set SelectedPoints = oSel.Item(1).Value 'Note assumes set alraedy selected

If TypeName(SelectedPoints) = "HybridBody" And oSel.Count = 1 Then
    Set SelectedPointsDoc = CAtDocs.Item(oSel.FindObject("CATIAPart").Parent.Name)
    PointCount = SelectedPoints.HybridShapes.Count
    oSel.Clear
    
   
    For j = 1 To PointCount
         oSel.Add (SelectedPoints.HybridShapes.Item(j))
         

Set oSPA = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
 Set m_Obj = oSel.Item(1)
Set ref = m_Obj.Reference
Set TheMeasurable = oSPA.GetMeasurable(ref)
On Error Resume Next
TheMeasurable.GetPoint coords
If Err.Number = 0 Then
     cPoints.Add oSel.Item(oSel.Count).Value, oSel.Item(oSel.Count).Value.Name
Else
Err.Clear
End If

Enjoy

Nev

RE: How do I filter Points out of an OpenBody within VBA?

(OP)
Nev

Thank you so much. That 'work-around' works great. I really appreciate the help and speed of your response.

Cheers

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