0

I am writing a macro handling a title block in Catia drawings. I have subs that I use to move circles and lines, which work fine (code initially found here)

Private Sub moveCircle(oCircle, dX As Double, dY As Double)
    Dim oCtr(1)
    oCircle.GetCenter oCtr
    
    movePoint oCircle.CenterPoint, dX, dY
    movePoint oCircle.StartPoint, dX, dY
    movePoint oCircle.EndPoint, dX, dY
    
    oCircle.SetData oCtr(0) + dX, oCtr(1) + dY, oCircle.Radius
    
    Debug.Print "move circle OK"
End Sub

Private Sub movePoint(oPt, dX As Double, dY As Double)
    Dim oCoord(1)

    oPt.GetCoordinates oCoord
    oPt.SetData oCoord(0) + dX, oCoord(1) + dY
End Sub

Private Sub moveLine(oLine, dX As Double, dY As Double)
    Dim oStartPt As Variant
    Dim oEndPt As Point2D
    Dim myDir(1)
    Dim oPtCoord(1)
    
    oLine.GetDirection myDir
    
    Set oStartPt = oLine.StartPoint
    Set oEndPt = oLine.EndPoint
    movePoint oStartPt, dX, dY
    movePoint oEndPt, dX, dY

    oStartPt.GetCoordinates oPtCoord
    
    oLine.SetData oPtCoord(0), oPtCoord(1), myDir(0), myDir(1)
End Sub

So those functions are called in a sub called "DrawView" when I create the drawing to move stuff around depending on the paper format, and everything works well. If the paper format is changed later on, I want to resize everything and call those functions again from another sub "resizeTitleBlock", exactly the same way, and this is when it doesn't work anymore. I get an error saying the the method SetData in sub movePoint failed.

Those functions are called in both cases like this:

Dim element
        For Each element In refView.GeometricElements
            Select Case TypeName(element)
                Case "Axis2D":
                    'nothing to do, must be excldued
                Case "Line2D":
                    moveLine element, sheetWidth - 210, 0
                Case "Circle2D":
                    moveCircle element, sheetWidth - 210, 0
            End Select
        Next element

Any idea what may cause this issue?

I tried checking that the elements I pass to those functions are the same in both cases (by checking the name of the element). From Sub DrawView, "Line.1" is moved properly. From Sub resizeTitleBlock, I pass "Line.1" to the function again and get the error "the method SetData has failed".

I tried calling calling moveLine from Sub DrawView several times, and it works.

  • Does this line have any constraints? Can you move this line by hand (drag)? Does this problem occur only on this specific line? – Shrotter Dec 14 '22 at 15:54
  • No, no constraints, I can move them by hand. It happens on every Line or Circle. – fabien.d Dec 15 '22 at 09:46
  • Does your macro work if the background view (where your geometries are located) is active? – Shrotter Dec 16 '22 at 08:35
  • No it doesn't! I tried with the background view active or inactive, and it had to be active indeed. So I found the solution which is to add a refView.Activate before calling the functions. Thank you! – fabien.d Dec 16 '22 at 10:50

0 Answers0