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
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?
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?
RE: How do I filter Points out of an OpenBody within VBA?
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?
Thank you so much. That 'work-around' works great. I really appreciate the help and speed of your response.
Cheers