API to create Surface from boundary Curves

Gears Phenom Gears Phenom
Gears Phenom



I wrote a macro to create Surface from boundary Curves:



Sub Main	'Create Surface from boundary Curves

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

    Dim curve_ID As Long
    Dim surf_ID As Long
    Dim startPt As Long
    Dim endPt As Long
    Dim coinCount As Long

    Dim curveSet As femap.Set
    Set curveSet = App.feSet
    Dim curveSet2 As femap.Set
    Set curveSet2 = App.feSet
    Dim pointSet As femap.Set
    Set pointSet = App.feSet
    Dim pointSet2 As femap.Set
    Set pointSet2 = App.feSet

    Dim cu As femap.Curve
    Set cu=App.feCurve

    Dim tracker As femap.TrackData
    Set tracker = App.feTrackData

    Dim xLength As Double, yLength As Double, zLength As Double
    Dim dTolerance As Double
    Dim vect(2) As Double
    Dim sTolerance As String

    dTolerance=Round(Sqr(xLength*xLength+yLength*yLength+zLength*zLength)/10000, 6)
    If dTolerance<1 Then sTolerance ="0"+Trim(sTolerance)


    Dim coinPoints As Variant
    Dim vec As Variant

App.feAppMessage( FCM_COMMAND, "Create Surfaces from Curves") rc = curveSet.Select( FT_CURVE, True, "Select Curves to create Surfaces (in case of error select Cancel in the next selection box))" ) If rc = FE_CANCEL Or rc=FE_NOT_EXIST Then App.feAppMessage( FCM_ERROR, "Curve(s) not selected - Cancelled") App.feViewRegenerate( 0 ) Exit Sub End If surf_ID=App.Info_NextID(FT_SURFACE) rc=App.feBoundaryFromCurves( curveSet.ID) If rc=FE_FAIL Then App.feAppMessage( FCM_NORMAL, "Trying to repair...") sTolerance=InputBox("Tolerance to merging endpoints of temporary created curves:", "Create Surfaces from Curves", sTolerance) 'sTolerance=Replace(sTolerance,",",".") 'to Hungarian number format dTolerance=Val(sTolerance) If dTolerance<>0 Then tracker.Start(FT_CURVE) tracker.Start(FT_POINT) rc=App.feGenerateCopy(FT_CURVE, curveSet.ID, vec, 0, False) tracker.Stop(FT_CURVE) tracker.Stop(FT_POINT) tracker.Created(FT_CURVE, curveSet2.ID, False) tracker.Created(FT_POINT, pointSet2.ID, False) If rc<>FE_FAIL Then pointSet.Clear curve_ID=curveSet2.First While curve_ID>0 rc=cu.Get(curve_ID) rc=cu.EndPoints(startPt, endPt) pointSet.Add(startPt) pointSet.Add(endPt) curve_ID=curveSet2.Next Wend rc=App.feCheckCoincidentPoint(pointSet.ID, pointSet.ID, dTolerance, True, True, coinCount, coinPoints) If Not (rc=FE_TOO_SMALL Or rc=FE_NOT_AVAILABLE Or rc=FE_INVALID Or rc=FE_BAD_TYPE) Then 'App.feAppMessage( FCM_NORMAL, Str(coinCount)+" temporary points merged.") End If rc=App.feBoundaryFromCurves( curveSet2.ID) If rc<>FE_FAIL Then GoTo CONVERT End If App.feAppMessage( FCM_ERROR, "Merging all endpoints failed -" + Str(pointSet.Count/2-coinCount) + " points weren't merged.") End If End If App.feAppMessage( FCM_ERROR, "Unable to create Surface - Cancelled") App.feViewRegenerate( 0 ) GoTo CLEANUP End If CONVERT: rc=App.feSurfaceConvert( -surf_ID, True ) If rc=FE_FAIL Then App.feAppMessage( FCM_ERROR, "Unable to convert Boundary to Surface - Cancelled") App.feViewRegenerate( 0 ) Exit Sub End If 'Remove "1 Surface(s) Deleted. 0 NonDeletable Surface(s) Skipped." message App.feAppManagePanes("Messages",1) SendKeys "^{END}", True '[CTRL+END] SendKeys "+{HOME}", True '[SHIFT+HOME] SendKeys "+{LEFT}", True '[SHIFT+LEFTARROW] SendKeys "{DEL}", True '[DEL] Wait 0.01 App.feAppMessage( FCM_NORMAL, "Surface"+Str(surf_ID)+" successfully created") CLEANUP: If curveSet2.Count<>0 Then pointSet2.Clear rc=pointSet2.AddSetRule(curveSet2.ID, FGD_POINT_ONCURVE) App.feDelete(FT_CURVE, curveSet2.ID) App.feDelete(FT_POINT, pointSet2.ID) End If App.feViewRegenerate(0) End Sub



If the curves aren't closed, then the macro create temporary curves, merge its endpoints (with specified tolerance) and try to create surface again. In this case there is a secondary entity selection box after error message (this is the failure of the feBoundaryFromCurves method, see https://community.plm.automation.siemens.com/t5/3D-Simulation-Femap-Forum/Issue-with-feBoundaryFromC...), here simply press the Cancel button (until fixing this method). In the end of the macro the temporaly curves will be deleted.


I think similar command will be very useful in Femap.


Best regards


Peter Kaderasz