0

I have developed a piece of CATVBA code to rename and coordinate points under a geometric set. Here the problem is, i can able to rename the points but the coordination is not working. I am able to get the coordinate value of each points under geometric set but set coordination is not working. Please check and let us know if any one has any solution. P.S:- I want to make coordinate of same point and don't want to create any new points with the coordinate values. Thanks.

Sub CATMain()

Dim MyObj As Object, pd1 As PartDocument, a As String
Dim Result As String
ReDim InputObjectType(0) As Variant
Dim MySelection As Object

If TypeName(CATIA.ActiveDocument) <> "PartDocument" Then
    Message = MsgBox("This program only works on a CATPart.", vbDefaultButton1, "Error")
    Exit Sub
End If

Set pd1 = CATIA.ActiveDocument
Set MySelection = pd1.Selection
ReDim InputObjectType(0)
InputObjectType(0) = "HybridBody"

MsgBox "Select a Geoset in which its elements needs to renamed."

Result = MySelection.SelectElement2(InputObjectType, "Select a Geoset in which its elements needs to renamed.", False)

If Result = "Normal" Then
    Set MyObj = pd1.Selection.Item(1).Value
ElseIf Result = "Redo" Then
    MsgBox "Redo is not an option for this program."
End
Else
End
End If

Call Dumb_Renumber(MyObj)

End Sub

Sub Dumb_Renumber(x As HybridBody)

Dim n As Double, i As Integer
Dim m As String
Dim PtString As String
Dim PtNumberOld As Integer, PtNumberNew As Integer
Dim ptName As String, NewPtName As String
Dim StartPos As Integer

m = InputBox("What would be your Prefix?", "Rename Input")   'get Prefix Input from user
n = InputBox("What number would you like to start with?", "Rename Input", "100")  'get suffix input from user


For i = 0 To x.HybridShapes.Count - 1

    On Error Resume Next
    Dim coord(2)

    x.HybridShapes.Item(i + 1).GetCoordinates coord      ' i am able to get Co ordinate value here
    'MsgBox coord(0) & " " & coord(1) & " " & coord(2)

    x.HybridShapes.Item(i + 1).SetCoordinates coord      'not able to set coordinate value

    x.HybridShapes.Item(i + 1).Name = m & n + i          'this is to rename the elements under the selected geometric set

Next

End Sub
Abdul
  • 11
  • 1
  • 4
  • "x.HybridShapes.Item(i + 1).SetCoordinates coord" it is the place where i used for point coordination and it is not working – Abdul Aug 10 '17 at 05:08
  • Are you sure all your points are HybridShapePointCoord types? The SetCoordinate methods only works for that type of point. Also what is the point to read the coordinates and then immediately set them again. – C R Johnson Aug 10 '17 at 16:26
  • Yes. I have "x.HybridShapes.Item(i + 1).GetCoordinates coord" just before Set coordinate which is giving me exact Coordinate value. – Abdul Aug 17 '17 at 13:10
  • That is not what I asked. GetCoordinates will work for any type of point (Point on Surface, Point On Curve, etc). SetCoordinates works for HybridShapePointCoordinate type objects only. And why are you setting the same point's "x.HybridShapes.Item(i+1)" coordinates with the values you just retrieved? It's the same object. Nothing should change. – C R Johnson Aug 17 '17 at 15:13

1 Answers1

0

It is a late answer, but I hope it still helps.

First of all, most of CATIA collections uses a range from 1 up to .Count, so you should change your loop to:

For i = 1 To x.HybridShapes.Count
    'Code here
next

Also, as C.R. Johnson pointed out in the comments, you can only directly retrieve a Point coordinate if it is of type HybridShapePointCoord.

But you can also use the Spaworkbench and Measurable objects to retrieve geometrical information about HybridShapes

Here is a code sample that will work:

Dim SPAWorkBench As SPATypeLib.SPAWorkbench
Dim Measurable As SPATypeLib.Measurable
Dim HybridBody As MECMOD.HybridBody
Dim i As Integer
Dim Coord(2)

'Initialize your variables propertly

set SPAWorkBench = Catia.ActiveDocument.GetWorkbench("SPAWorkbench")

For i = 1 To HybridBody.HybridShapes.Count

    set Measurable = SPAWorkBench.GetMeasurable(HybridBody.HybridShapes.Item(i))
    If Measurable.GeometryName = SPATypeLib.CatMeasurableName.CatMeasurablePoint Then
        Measurable.GetPoint(Coord)
                'Coord will have the points coordinates
    Else
                'Not a point, will not be possible to retrieve coordinates
    End If

Next
Quima
  • 894
  • 11
  • 21