1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Function Release: AnalyzeSketch

Discussion in 'Alibre Script' started by NateLiqGrav, Sep 29, 2019.

  1. NateLiqGrav

    NateLiqGrav Alibre Super User

    This will Analyze the Sketch passed to it.
    The Verbose setting is optional. Setting that to True that will print the results automatically.
    The function will return either 0 (False indicating no problems to report) or it will return the integer quantities for each type of problem in a list in the order [DegenerateFigures, DisjointEnds, Intersections, OpenLoops, OverLaps]

    Code:
    def AnalyzeSketch(ThisSketch, Verbose = 0):
        # This will Analyze the Sketch passed to it.
        # The Verbose setting is optional. Setting that to True that will print the results automatically.
        # The function will return either 0 (False indicating no problems to report)
        # or it will return the integer quantities for each type of problem in a list
        # in the order [DegenerateFigures, DisjointEnds, Intersections, OpenLoops, OverLaps]
        myfigures = ThisSketch.Figures
        objSketch = myfigures[0].FigureObject().Sketch
        try:
            objSketch.BeginChange()
        except:
            pass
        results = objSketch.Analyze(1,1,1,1,1,0,0)
        try:
            objSketch.EndChange()
        except:
            pass
        if results.DegenerateFigures.Count or results.DisjointEnds.Count or results.Intersections.Count or results.OpenLoops.Count or results.OverLaps.Count:
            if Verbose:
                print('\nAnalyzing the sketch named "' + str(ThisSketch.Name) + '"')
                if results.DegenerateFigures.Count > 0:
                    print('Found ' +str(results.DegenerateFigures.Count) + ' DegenerateFigure(s)')
                if results.DisjointEnds.Count > 0:
                    print('Found ' +str(results.DisjointEnds.Count) + ' DisjointEnd(s)')
                if results.Intersections.Count > 0:
                    print('Found ' +str(results.Intersections.Count) + ' Intersection(s)')
                if results.OpenLoops.Count > 0:
                    print('Found ' +str(results.OpenLoops.Count) + ' OpenLoop(s)')
                if results.OverLaps.Count > 0:
                    print('Found ' +str(results.OverLaps.Count) + ' OverLap(s)')
                print('')
            return [int(results.DegenerateFigures.Count), int(results.DisjointEnds.Count), int(results.Intersections.Count), int(results.OpenLoops.Count), int(results.OverLaps.Count)]
        else:
            return 0
    
    Here is an example usage.
    Code:
    # example code
    prt = CurrentPart()
    mysketch = prt.GetSketch('Sketch<1>')
    results = AnalyzeSketch(mysketch, True) # Verbose setting is optional. Here I set it to True.
    if results:
        print('Oh No! We found something wrong when analyzing the sketch!')
        # do something
    else:
        print('The sketch looks good!')
        # do something
    As always comments are appreciated.
     

Share This Page