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!

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

Status
Not open for further replies.

l3ob

Aerospace
Apr 28, 2004
56
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
 
Replies continue below

Recommended for you

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
 
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.
 
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
 
Nev

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

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor