Showing results for 
Search instead for 
Do you mean 
Solved! Go to solution

API for properties of midsurfaces



I am new to using the API functions for FEMAP. I was wondering if there is a method to identify properties of various midsurfaces. For example if I were to select on a midsurface in my model, I would like to know its thickness and which solid it belongs to.


Re: API for properties of midsurfaces



If I may ask, what do you plan to use the thickness and solid information for?  If you are planning on creating mesh on a midsurface(s) that use the thickness of the orignial solid, the option to "Assign Mesh Attributes" could be what you're looking for. 


Automatic Sizing.png


From here, select your midsurfaces you'd like to mesh, assign or create your material, choose "No" when prompted to 'Consolidate Properties By Thickness?', then create your mesh using Mesh > Geometry > Surface.  Select the Midsurfaces you'd like to mesh again and make sure "0..Use Meshing Attributes" is the Property.


Use Meshing attributes.png


Use the drop down next to the 'View Style' button and turn on "Thickness/Cross Section" to view the mesh sized to the orignial solid.


thickness cross.png

Re: API for properties of midsurfaces

The API method you need is feSurfaceMidAttrib.  You will need to have a material ID available for this as well as a single surface ID or a set of surfaces.  For example:


The HTML Clipboard

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

    Dim rc As femap.zReturnCode

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

    'Select Midsurfaces for Assignment of Mesh Attributes
    rc = midsurfaces.Select ( FT_SURFACE, True, "Select Midsurfaces for Assigning Attributes" )
    If rc <> FE_OK Then
    End If

    'Select Material for Midsurfaces Properties
    Dim matID As Long
    rc = App.feSet.SelectID ( FT_MATL, "Select Material for Midsurfaces", matID )
    If rc <> FE_OK Then
    End If

    rc = App.feSurfaceMidAttrib ( midsurfaces.ID, matID )
    If rc <> FE_OK Then
        App.feAppMessage ( FCM_ERROR, ("Surface" + Str$(msID ) + " was not generated by midsurfacing methods, skipping" ) )
    End If

    App.feViewRegenerate ( 0 )

End Sub

Best Regards,
Chip Fricke
Principal Applications Engineer - Femap Product Development

Re: API for properties of midsurfaces

I hope I am able to explain what I would like to achieve.





These two solids are adjacent to each other. After creating their midsurface there is now a gap between them as shown below.




The final step would then be to extend the orange surface to the blue surface, non-manifold add the surfaces together before meshing.




I am trying to write a script that would be able to detect adjacent solids (within a tolerance) and extend the respective midsurfaces to each other and would appreciate any help in pointing me towards the right direction.

Accepted by topic author yx
‎12-23-2016 01:39 AM

Re: API for properties of midsurfaces



Give the API below a try.  It utilizes the built-in Femap command "Connect > Automatic"  and uses the curves and surfaces found within a specified tolerance to perform a curve > extend.



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

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

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

    Dim tol As Double
    App.feGetReal("Enter Tolerance", 1E-15, 1000, tol)
    connectType = 2
    AngularTolerance = 1.0
    SearchAggressiveness = 3

    ' If you would prefer to select surfaces individually, comment out "s.AddAll( FT_SOLID )" and uncomment "s.Select(FT_SOLID,True,"Select for Automatic Extend")"
    s.AddAll( FT_SOLID )
    's.Select(FT_SURFACE,True,"Select for Automatic Extend")

    check = connectSet.Count

    App.feConnectAuto2(s.ID, connectType, tol, AngularTolerance, SearchAggressiveness, False, True, 0, True)
    App.feViewRegenerate ( 0 )

    test = connectSet.Count 'check that new connectors have been made before proceeding to ExtendToSurfaceSub

    If test <= check Then
        MsgBox "Surfaces Not Identified, Lowering Tolerance value may help",vbExclamation,"Error"
        Exit All
    End If

End Sub

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

    Dim rc As femap.zReturnCode

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

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

    Dim nullVariant(10) As Variant 'the feSurfaceExtend function requires input of this data type despite no value being used
    Dim nullDouble As Double 'the feSurfaceExtend function requires input of this data type despite no value being used

    Dim connectorMaster As femap.Connection
    Set connectorMaster = App.feConnection

    Dim connectRegion As femap.ConnectionRegion
    Set connectRegion = App.feConnectionRegion

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


    While connectorSet.Next
            master = connectorMaster.Contact(0)
            slave = connectorMaster.Contact(1)

                'If the surface does not match the solid...
                SurfaceOfMaster = MasterSurfSet.First
                SolidOfMaster = MasterSurfSet.First

                    CurveOfSlave = SlaveSurfSet.First

    'feSurfaceExtend, through the API, requires extending to a SOLID
    rc = App.feSurfaceExtend(-CurveOfSlave,0,0,SolidOfMaster,nullVariant,nullDouble)
        If rc <> FE_OK Then
            App.feAppMessage(FCM_ERROR,"Problem Extending Curve to Solid, Please Check Selection")
        End If


    App.feViewRegenerate( 0 )

End Sub





Play with the tolerance to capture all the gaps you need.


In addition to this, there is the ability in the Meshing Toolbox that you may find useful.  The option "Surface Auto Curve" within Geometry Editing will extend surfaces by curves on a stitched or non-manifold body to a surface.




Re: API for properties of midsurfaces

Hi Ryan,


This API does indeed work very well! The idea of using connectors to determine neighbouring solids is brilliant and I would have thought of it. Cheers!