cancel
Showing results for 
Search instead for 
Did you mean: 

API Programming using COM/OLE

Valued Contributor
Valued Contributor

Hello,

 

I have written a very simple code using Visual Studio 2012 - VB.net. This code colors all triangular elements green. The issue I'm having is when I run the code, the femap command window stays open. What do I need to add to my code to make the command window close (or not open in the first place)? I compiled the code into an executable file and just run it from my Custom Toolbars menu. Below are the code and femap command window which remains open.

 

Thanks

 

VB.Net Code: (Console Application)

code_example.jpg

 

Femap Command window that likes to stay open upon execution of the code:

femap_command_window.jpg

7 REPLIES

Re: API Programming using COM/OLE

Phenom
Phenom

Hello,

 

This may be related to VS, not FEMAP. We often do what you describe but the console closes asap.

 

AP

 

 

PS: no need for a loop: look up sets and rules ("group selection rules"), a very powerful aspect of the FEMAP API:

 

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

 

    Dim elset As femap.Set
    Set elset = App.feSet

 

    elset.AddRule(FTO_TRIA3,FGD_ELEM_BYSHAPE)
    App.feModifyColor(FT_ELEM,elset.ID,FCL_GREEN,False)
    App.feViewRegenerate(0)
End Sub

Re: API Programming using COM/OLE

Valued Contributor
Valued Contributor
Thank you for thr tip! I also notice you do not utilize the put statement. When would we actually need to use the put and get statement? I have some older API tutorials which state the database won't refresh with the entity changes sans the put call.

Thanks for the help.

Stressman

Re: API Programming using COM/OLE

Phenom
Phenom

The Get and Put methods are used for all FEMAP Entity Objects (those listed in Help > API > 5.Entity Objects). Here I use the App object (Help > API > 3.Application Object), which directly modifies the database without Get or Put.

 

The App object can be thought of as the main FEMAP toolbar: it contains many of the functions you will find in the various menus. It also contains all the methods related to the various dialog boxes you find in FEMAP (corrdinate/vector/plane selection, output selection, face selection...etc...), as well as other things...

 

app.jpg

Re: API Programming using COM/OLE

Valued Contributor
Valued Contributor

Beautiful explanation, thank you very much Astrium_tls.

 

While we are on the topic I have another question. I switched back to the API window so we are all on the same page. Below I have code where I'm trying to call the fechecksumforces2 and have it sum the loads from the active load-set.  My issues are as follows:

 

1. Do I need to initialize a variable for the Output Field? It's calling for an summedForces Array...

 

2. When I run the code I encounter a type mismatch error for field 6 of fechecksumforces...

 

 

 

fechecksum.jpg

Thanks again,

 

Stressman - API noob

Re: API Programming using COM/OLE

Genius
Genius

Hi Stressman,

 

I modified the API:

 

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

	Dim ElemSet As femap.Set
	Dim NodeSet As femap.Set

	Set ElemSet=App.feSet
	Set NodeSet =App.feSet

	rc=ElemSet.AddGroup(FT_ELEM,1)
	rc=NodeSet.AddGroup(FT_NODE,1)

	Dim basePoint(2) As Double
	basePoint(0)=0.0
	basePoint(1)=0.0
	basePoint(2)=0.0

	Dim summedForces As Variant
	Dim csysID As Long
	csysID=0	'Basic Rectangular

	App.feCheckSumForces2(True,True,True,True,NodeSet.ID,ElemSet.ID, 0 ,basePoint, csysID,summedForces)

	MsgBox "Nodal Force FX =" & Str(summedForces(0))

End Sub

I used basic rectangular coordinate system insteed basic cylindrical, and corrected summedForces to Variable. I corrected the groupID in AddGroup commands from -1 to 1 too. I think enough to dimensioning basePoint(2), because you don't use basePoint(3).

So works for me.

 

Best Regard

 

Peter Kaderasz

Re: API Programming using COM/OLE

Valued Contributor
Valued Contributor

Hi Kadpeter - Thank you for the modification to the code, it worked just fine in Femap.

 

I'm also wirting the same code in Visual Studo - VB.NET, console application. When I execute the code I get a type mismatch error for fechecksumforeces2. Do you think the error stems from the way I dimensioned the summedForces array? I have tried dimensioning summedForces as both Double and Object but still receive the type mismatch error.

 

 

Module Module1

    Sub Main()

        Dim app As femap.model
        app = GetObject(, "femap.model")

        Dim rc As femap.zReturnCode

        Dim ElemSet As femap.Set
        Dim NodeSet As femap.Set

        ElemSet = app.feSet
        NodeSet = app.feSet

        rc = ElemSet.AddGroup(femap.zDataType.FT_ELEM, 1)
        rc = NodeSet.AddGroup(femap.zDataType.FT_NODE, 1)

        Dim basePOINT(2) As Double
        basePOINT(0) = 0.0
        basePOINT(1) = 0.0
        basePOINT(2) = 0.0

        Dim summedForces As Double
        Dim csysID As Integer

        csysID = 0 'Basic Rectangular

        app.feCheckSumForces2(True, True, True, True, NodeSet.ID, ElemSet.ID, 0, basePOINT, csysID, summedForces)


    End Sub

End Module

Stressman

Re: API Programming using COM/OLE

Valued Contributor
Valued Contributor

I found the issue with my VB.net code...

 

basePoint and summedForces needed to be dimension as an Object for VB.net.

 

Now it works fine. I'm just curious is there a way conceal the command window from flashing during code execution. It's only for a brief second but it would be nice if it ran smooth, similiar to executing code from the Femap API window.

 

Thanks,

Module Module1

    Sub Main()

        Dim app As femap.model
        app = GetObject(, "femap.model")

        Dim rc As femap.zReturnCode

        Dim ElemSet As femap.Set
        Dim NodeSet As femap.Set

        ElemSet = app.feSet
        NodeSet = app.feSet

        rc = ElemSet.AddGroup(femap.zDataType.FT_ELEM, 1)
        rc = NodeSet.AddGroup(femap.zDataType.FT_NODE, 1)

        Dim basePOINT(2) As Object
        basePOINT(0) = 0.0
        basePOINT(1) = 0.0
        basePOINT(2) = 0.0

        Dim summedForces As Object
        Dim csysID As Integer

        csysID = 0 'Basic Rectangular

        app.feCheckSumForces2(True, True, True, True, NodeSet.ID, ElemSet.ID, 0, basePOINT, csysID, summedForces)


    End Sub

End Module