Cancel
Showing results for 
Search instead for 
Did you mean: 

Rotation via API in real time

Experimenter
Experimenter

Dear experts,

I am trying to write my first macro to achieve a rotation of a view. I think I can manage to write a few lines that actually rotate my view by the angle I want but I would like to have a background macro (infinite loop?) that keeps rotating my view at fixed angle with the possibility of still interacting with the view via the mouse.

 

As I am learning I can write the code to rotate by a fixed angle my view, but how to get it running in background all the time and more important still allowing the user the freedom to interact with the model/view?

 

thanks for your suggestions!

4 REPLIES

Re: Rotation via API in real time

Siemens Genius Siemens Genius
Siemens Genius

You can try something like this, but I'm not sure this is exactly what you will want.

 

The HTML Clipboard

Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim v As femap.View
    Set v = App.feView

    Dim viewID As Long

    Do
        App.feAppGetActiveView(viewID)
        v.Get(viewID)
        v.Rotate(0, 0, 0, 0, 1, 0, 90)
        v.Put(viewID)
        App.feViewRegenerate(viewID)
        Wait(1)
    Loop

End Sub

Re: Rotation via API in real time

Experimenter
Experimenter

Yes that is a possibility, can this be implemented using a callbackfunction such as feAppEventCallback?

 

The callbackfunction should be called only if the user triggers a rotation (is it considered as redraw?), how to use such callbackfunction?

Re: Rotation via API in real time

Siemens Phenom Siemens Phenom
Siemens Phenom

Here is an attempt to achieve close to what you are looking for.  To get multiple processes to occur at the same time, you will have to attach to Femap from an external program, like Visual Studio.

 

Continuous Rotation.png

 


    Dim App As femap.model
    Dim v As View
    Dim eSet As Set
    Dim viewID As Long
    Dim x As Double, y As Double, z As Double
    Dim dx As Double, dy As Double, dz As Double, angle As Double
    Dim check_dx As Double
    Dim rc As Long, i As Long, a As Long
    Dim HighlightOn As Boolean

Sub Main
    Set App = GetObject(,"femap.model")
    Set eSet = App.feSet
    Set v = App.feView
    App.feAppGetActiveView(viewID)
    i = 0
    a = 0

    eSet.AddAll(FT_ELEM)

    Begin Dialog UserDialog 350,119,"Contiuous Rotation",.DlgFunc ' %GRID:10,7,1,1
        OKButton 140,91,90,21
        CancelButton 240,91,90,21
        text 40,7,90,14,"Origin:",.Text1
        text 150,7,90,14,"Rotate About:",.Text5
        text 260,7,50,14,"Angle:",.Text6
        TextBox 40,21,90,21,.TextBox1
        TextBox 40,42,90,21,.TextBox2
        TextBox 40,63,90,21,.TextBox3
        TextBox 150,21,90,21,.TextBox4
        TextBox 150,42,90,21,.TextBox5
        TextBox 150,63,90,21,.TextBox6
        TextBox 260,21,80,21,.TextBox7
        text 20,21,20,14,"X",.Text2
        text 20,49,20,14,"Y",.Text3
        text 20,70,20,14,"Z",.Text4
        text 40,98,90,14,"",.Text7
        PushButton 260,49,80,21,"Pick Elems",.ListElems
    End Dialog
    Dim dlg As UserDialog
    x = Val(dlg.TextBox1)
    y = Val(dlg.TextBox2)
    z = Val(dlg.TextBox3)
    dx = Val(dlg.TextBox4)
    dy = Val(dlg.TextBox5)
    dz = Val(dlg.TextBox6)
    angle = Val(dlg.TextBox7)

    If Dialog (dlg) = 0 Then End

    'App.feAppMessage(FCM_NORMAL,dlg.TextBox1)

End Sub
Rem See DialogFunc help topic for more information.
Function DlgFunc(DlgItem$, Action%, SuppValue?) As Boolean
    Select Case Action%
    Case 1 ' Dialog box initialization
        'Rotate About...
        DlgText("TextBox1","0.0") : DlgText("TextBox2","0.0") : DlgText("TextBox3","0.0")
        'Degree...
        DlgText("TextBox4","0.0") : DlgText("TextBox5","0.0") : DlgText("TextBox6","0.0")
        'Angle...
        DlgText("TextBox7","0.05")
        DlgText("Text7","Still")
    Case 2 ' Value changing or button pressed
        a = 0
        Select Case DlgItem$
            Case "OK"
                OKPush:
                a = 1
                'Keep dialog box open for rotaton
                DlgFunc = True
                check_dx = dx
                If dx > 0.0 Or dy > 0.0 Or dz > 0.0 Then
                    If angle > 0.0 Then
                        Do
                            Call RotateRun()
                            If DlgFocus() <> "OK"  Then
                                Exit Do
                            End If
                        Loop
                Else
                DlgText("Text7","Angle /= 0.0")
                    End If
                Else
                DlgText("Text7","No Rotation")
                End If
            Case "ListElems"
                DlgFunc = True
                Call ListElems()
            Case "Cancel"
                DlgFunc = False
            Case Else
                DlgFunc = False
                App.feAppMessage(FCM_NORMAL,"Does this hit Else?")
        End Select
    Case 3 ' TextBox or ComboBox text changed
        x = DlgText("TextBox1") : y = DlgText("TextBox2") : z = DlgText("TextBox3")
        dx = DlgText("TextBox4") :  dy = DlgText("TextBox5") :  dz = DlgText("TextBox6")
        angle = DlgText("TextBox7")
        If dx > 0 Or dy > 0 Or dz > 0 Or angle > 0 Then
            DlgFocus("OK")
        End If
        'Call RotateRun()
    Case 4 ' Focus changed
        Debug.Print "DlgFocus="""; DlgFocus(); """"
        DlgFunc = True
        If DlgFocus() ="OK" Then
            DlgText("Text7","Rotating...")
        Else
            DlgText("Text7","Paused")
        End If

    Case 5 ' Idle
    Case 6 ' Function key
    End Select
End Function
Private Sub RotateRun()

        App.feAppGetActiveView(viewID)
                For i = 0 To 1
                    v.Get(viewID)
                    v.Rotate(x,y,z,dx,dy,dz,angle)
                    v.Put(viewID)
                    App.feViewRegenerate(viewID)
                    i = i+ 1
                Next i

End Sub
Sub ListElems()
    Dim fe As femap.model
    Set fe = GetObject(,"femap.model")

    Dim eSet As femap.Set
    Set eSet = fe.feSet

    eSet.Select(FT_ELEM,False,"Test")

    While eSet.Next()
        fe.feAppMessage(FCM_NORMAL,Str$(eSet.CurrentID))
    Wend


End Sub

Re: Rotation via API in real time

Experimenter
Experimenter

Thank you!

Meanwhile, I was also looking at running the macro in Visual Studio. In addition to the microsoft standard forms (buttons, frames etc), how can I add one or more FEMAP graphics windows inside the visual studio IDE?