Incorrect propertiesU and propertiesV from NurbsSurface.getData

Incorrect propertiesU and propertiesV from NurbsSurface.getData

CADacombs
Enthusiast Enthusiast
715 Views
3 Replies
Message 1 of 4

Incorrect propertiesU and propertiesV from NurbsSurface.getData

CADacombs
Enthusiast
Enthusiast

Using the code below and the attached model, the values of NurbsSurface.propertiesU and NurbsSurface.propertiesV appear correct, but the two integers corresponding with these properties returned from NurbsSurface.getData() are sometimes not.  For example, a non-rational surface that is periodic along U and open along V is reported as:

 

NurbsSurface.propertiesU: 6
NurbsSurface.propertiesV: 1
propertiesU from getData: 4
propertiesV from getData: 4

 

 
 
 

 

import adsk.core, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        ent = ui.selectEntity("Select a face", "Faces")

        if not (isinstance(ent.entity.geometry, adsk.core.Surface)): return

        surface = ent.entity.geometry

        if surface.surfaceType != adsk.core.SurfaceTypes.NurbsSurfaceType:
            print("Not a NurbsSurface.")
            return
        
        ns = surface

        print("NurbsSurface.propertiesU: {}".format(ns.propertiesU))
        print("NurbsSurface.propertiesV: {}".format(ns.propertiesV))

        rc = ns.getData()
        if not rc[0]: return

        (
            propertiesU,
            propertiesV,
            ) = rc[-2:]

        print("propertiesU from getData: {}".format(propertiesU))
        print("propertiesV from getData: {}".format(propertiesV))

        #print(rc)

    except:
        if ui:
            sError = 'Failed:\n{}'.format(traceback.format_exc())
            print(sError)
            ui.messageBox(sError)

 

 
Thank you
0 Likes
716 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor

Hi @CADacombs .

 

I don't know why I can't get the correct information, but it seems that I can use SurfaceEvaluator to get the correct information.

 

I think the four red marks are the problem, please compare with the result using SurfaceEvaluator.

1.png

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        app.log(u'TextCommandWindow.Clear')

        while(True):

            sel = selectEnt("Select a face", "Faces")
            if not sel:
                break

            if not (isinstance(sel.entity.geometry, adsk.core.Surface)): return

            surface = sel.entity.geometry

            if surface.surfaceType != adsk.core.SurfaceTypes.NurbsSurfaceType:
                print("Not a NurbsSurface.")
                continue
            
            ns = surface
            app.log('---')
            app.log("NurbsSurface.propertiesU: {}".format(ns.propertiesU))
            app.log("NurbsSurface.propertiesV: {}".format(ns.propertiesV))

            rc = ns.getData()
            if not rc[0]: return

            (
                propertiesU,
                propertiesV,
                ) = rc[-2:]

            app.log("propertiesU from getData: {}".format(propertiesU))
            app.log("propertiesV from getData: {}".format(propertiesV))

            periodicityU, periodicityV= isPeriodicityUV(sel.entity)
            app.log(f"propertiesU from Evaluator: {periodicityU}")
            app.log(f"propertiesV from Evaluator: {periodicityV}")

    except:
        if ui:
            sError = 'Failed:\n{}'.format(traceback.format_exc())
            print(sError)
            ui.messageBox(sError)

# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d6b7d30a-972b-4117-9292-c0a87be8ba62
def isPeriodicityUV(face: adsk.fusion.BRepFace):
    eva: adsk.core.SurfaceEvaluator = face.evaluator

    _, periodicityU, periodicityV, _, _, _ = eva.getParamAnomaly()

    isPeriodicityU = True if periodicityU[0] != 0 else False
    isPeriodicityV = True if periodicityV[0] != 0 else False

    return isPeriodicityU, isPeriodicityV

def selectEnt(
        msg: str,
        filtterStr: str) -> adsk.core.Selection:

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None
Message 3 of 4

CADacombs
Enthusiast
Enthusiast

Not only for Periodicity of some surfaces, some of the Open and Closed values are also incorrect.  Below is a list of properties comparisons of all the closed surfaces in the provided model.  (Properties of the open surfaces are correct.)  The mismatched values are marked.

 

The workaround is to avoid using propertiesU and propertiesV from NurbsSurface.getdata.

 

                NurbsSurface.propertiesU, NurbsSurface.getData()[9]
                               NurbsSurface.propertiesV, NurbsSurface.getData()[10]
  
 Open:          F, F           T, F <--       
 Closed:        T, T           F, T <--       
 Periodic:      F, F           F, F           
 Rational:      F, F           F, F           
  
 Open:          F, F           T, F <--       
 Closed:        T, T           F, T <--       
 Periodic:      F, F           F, F           
 Rational:      T, T           T, T           
  
 Open:          F, F           T, F <--       
 Closed:        T, F <--       F, F           
 Periodic:      T, T           F, T <--       
 Rational:      F, F           F, F           
  
 Open:          F, F           T, F <--       
 Closed:        T, F <--       F, F           
 Periodic:      T, T           F, T <--       
 Rational:      T, T           T, T           
  
 Open:          T, T           F, T <--       
 Closed:        F, F           T, F <--       
 Periodic:      F, F           F, F           
 Rational:      F, F           F, F           
  
 Open:          T, T           F, T <--       
 Closed:        F, F           T, F <--       
 Periodic:      F, F           F, F           
 Rational:      T, T           T, T           
  
 Open:          T, T           F, T <--       
 Closed:        F, F           T, F <--       
 Periodic:      F, F           T, F <--       
 Rational:      F, F           F, F           
  
 Open:          T, T           F, T <--       
 Closed:        F, F           T, F <--       
 Periodic:      F, F           T, F <--       
 Rational:      T, T           T, T           
 

 

import adsk.core, traceback


def comparisonString(
    enum_to_check: int,
    enum_from_prop: int,
    enum_from_method: int) -> str:

    bP = bool(enum_to_check & enum_from_prop)
    bM = bool(enum_to_check & enum_from_method)

    return "{}, {} {}".format(
        str(bP)[0], str(bM)[0], "<--" if bM != bP else "   ")


def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        app = adsk.core.Application.cast(app)
        ui = app.userInterface

        app.log("{:<15}{:<15}".format(
            " ",
            "NurbsSurface.propertiesU, NurbsSurface.getData()[9]"))
        app.log("{:>30}{}".format(
            " ",
            "NurbsSurface.propertiesV, NurbsSurface.getData()[10]"))
        
        while True:
            try:
                sel = ui.selectEntity("Select a face", "Faces")
            except:
                break

            face = adsk.fusion.BRepFace.cast(sel.entity)

            if not (isinstance(face.geometry, adsk.core.Surface)): return

            surface = face.geometry

            if surface.surfaceType != adsk.core.SurfaceTypes.NurbsSurfaceType:
                app.log("Not a NurbsSurface.")
                return
        
            ns = adsk.core.NurbsSurface.cast(surface)

            propertiesU = ns.propertiesU
            propertiesV = ns.propertiesV

            nsp = adsk.core.NurbsSurfaceProperties

            getData = ns.getData()

            app.log(" ")

            s = "{:<15}{:<15}{:<15}".format(
                "Open:",
                comparisonString(
                    nsp.OpenNurbsSurface, ns.propertiesU, getData[9]),
                comparisonString(
                    nsp.OpenNurbsSurface, ns.propertiesV, getData[10]))
            app.log(s)

            s = "{:<15}{:<15}{:<15}".format(
                "Closed:",
                comparisonString(
                    nsp.ClosedNurbsSurface, ns.propertiesU, getData[9]),
                comparisonString(
                    nsp.ClosedNurbsSurface, ns.propertiesV, getData[10]))
            app.log(s)

            s = "{:<15}{:<15}{:<15}".format(
                "Periodic:",
                comparisonString(
                    nsp.PeriodicNurbsSurface, ns.propertiesU, getData[9]),
                comparisonString(
                    nsp.PeriodicNurbsSurface, ns.propertiesV, getData[10]))
            app.log(s)

            s = "{:<15}{:<15}{:<15}".format(
                "Rational:",
                comparisonString(
                    nsp.RationalNurbsSurface, ns.propertiesU, getData[9]),
                comparisonString(
                    nsp.RationalNurbsSurface, ns.propertiesV, getData[10]))
            app.log(s)

        app.log("\nEnd of script.")

    except:
        if ui:
            sError = 'Failed:\n{}'.format(traceback.format_exc())
            app.log(sError)
            ui.messageBox(sError)

 

Message 4 of 4

philpdxthesecond
Explorer
Explorer

Thanks for reporting this. Sorry it took a while to respond. 

Logged as FUS-138770.

Also reported more recently here.

0 Likes