Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get geometry (loop) from specific face

1 REPLY 1
Reply
Message 1 of 2
xenia.pie
193 Views, 1 Reply

Get geometry (loop) from specific face

Hi all,

 

I'm trying to get the geometry of a face for generating up and down faces and be able to generate an SVG of those.

I get to see the geometry of both faces, but for some models the geometry is a bit wrong.

Context:

I loop first through the loops of the face and check count of edges, if edges.count ==1 then is a circle or ellipse and I get the geometry generating the svg path for each specify type. (this is working fine)

 

But if the edges.count > 1 then I loop through coEdges of the loop to get the curve type and also to identify if the segment is reversed.

            else:
                path = ""
                start = None
                end = None
                c = 0

                for coEdge in loop.coEdges:
                    reversed = False
                    edge = coEdge.edge
                    curve_type = edge.geometry.curveType
                    # determine if edge is reversed
                    isOpposedToEdge = coEdge.isOpposedToEdge
                    isParamReversed = coEdge.isParamReversed

                    (returnBool, startPoint, endPoint) = edge.evaluator.getEndPoints()

                    if self.getTwoD(u, v, endPoint) == end or self.getTwoD(u, v, endPoint) == start:
                        reversed = True
                    if self.getTwoD(u, v, startPoint) == start:
                        print('wrong direction')
                    start = self.getTwoD(u, v, startPoint)
                    end = self.getTwoD(u, v, endPoint)
                    

                    if c == 0:
                        if coEdge.isOpposedToEdge and coEdge.isParamReversed:
                            path = f"M {end[0]} {end[1]}  "
                            path += self.getLineArcPath(start, edge, face, reversed, direction, coEdge)
                            start,end = end,start
                        else: 
                            path = f'M {start[0]} {start[1]}  '
                            path += self.getLineArcPath(end, edge, face, reversed, direction, coEdge)
                        c += 1
                        
                    else:
                        if coEdge.isOpposedToEdge and coEdge.isParamReversed or reversed:
                     
                            path += self.getLineArcPath(start, edge, face, reversed, direction,coEdge)
                            start,end = end,start
                        else:
       
                            path += self.getLineArcPath(end, edge, face, reversed, direction,coEdge)
                        c += 1

 

If curve.type is 0 then it's a line segment:

if curve_type == 0:
  path = f"L {end[0]} {end[1]}  "

and if curve.type == 1 it's a curve segment:

elif curve_type == 1:
            face_normal = face.geometry.normal
            arc_normal = edge.geometry.normal
            opp_or_equal = self.check_vectors(face_normal,arc_normal)
            arc = edge.geometry
            rx = str(arc.radius)
            ry = str(arc.radius)
            rotation = "0"
            large_arc_flag = "0"
            sweep_flag = "0"

            angle = abs(arc.endAngle - arc.startAngle)
            if angle >= 3.141592653589793 :
                large_arc_flag = "1"
            if direction == 'up':
                if coEdge.isParamReversed ==  True and coEdge.isOpposedToEdge == True and opp_or_equal == 'opposite':
                    sweep_flag = "1"
                if coEdge.isParamReversed ==  False and coEdge.isOpposedToEdge == False and opp_or_equal == 'equal':
                    sweep_flag = "1"
            if direction == 'down':
                if coEdge.isParamReversed ==  True and coEdge.isOpposedToEdge == True and opp_or_equal == 'opposite':
                    sweep_flag = "0"
                if coEdge.isParamReversed ==  False and coEdge.isOpposedToEdge == False and opp_or_equal == 'equal' or reversed:
                    sweep_flag = "1"
                if coEdge.isParamReversed ==  True and coEdge.isOpposedToEdge == True and opp_or_equal == 'equal':
                    sweep_flag = "1"
                if coEdge.isParamReversed ==  False and coEdge.isOpposedToEdge == False and opp_or_equal == 'opposite' or reversed:
                    sweep_flag = "1"
            x = str(end[0])
            y = str(end[1])

            path =f"A {rx} {ry} {rotation} {large_arc_flag} {sweep_flag} {x} {y} "

 

I have separated between up and down faces (direction) since the arc normal and plane/face normal will be different and hence the sweep_flag will change since I'm using the same plane for both.

The question is, how to get the right segment direction and determine large_arc_flag and sweep_flag in order to have the outline of the face properly defined.

This same code works for some models and doesn't for others.. so maybe there's a simpler way of determine the paths?

xeniapie_0-1645197516210.png

This model is alright.

 

xeniapie_1-1645198549387.png

Up faces - working fine

 

xeniapie_3-1645198946980.png

down faces - some line are ok, but the arcs are randomly wrong

 

Any comments will be appreciated.

Thanks

 
 

1 REPLY 1
Message 2 of 2
kandennti
in reply to: xenia.pie

Hi @xenia.pie .

 

I would like to try it, but I couldn't because the code you provided is partial and you didn't provide any data (f3d) that doesn't work.
Therefore, it is very likely that I do not understand the meaning of your question.

 

 

I have created a simple script to check.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


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

        msg: str = 'Select Face'
        selFiltter: str = 'Faces'
        sel: adsk.core.Selection = selectEnt(msg, selFiltter)
        if not sel:
            return

        face = sel.entity

        app.log(u'TextCommandWindow.Clear')
        for loop in face.loops:
            app.log(f'** loop start **  isOuter:{loop.isOuter}')
            for coEdge in loop.coEdges:
                geoType = coEdge.edge.geometry.objectType.split('::')[-1]
                st, ed =  getPoints(coEdge.geometry)
                msgLst = [
                    f'---',
                    f'edge type:{geoType}',
                    f'isOpposedToEdge:{coEdge.isOpposedToEdge}',
                    f'isParamReversed:{coEdge.isParamReversed}',
                    f' start point: {st.asArray()}',
                    f' end point: {ed.asArray()}',
                ]
                app.log('\n'.join(msgLst))
            app.log('** loop end **\n')

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

def getPoints(geo):
    eva: adsk.core.CurveEvaluator2D = geo.evaluator
    _, st, ed = eva.getEndPoints()

    return st, ed

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

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None

 

I tried it with the attached f3d file and noticed that the isOpposedToEdge property is different for arcs created with 3D fillets and arcs created with sketches.

1.png

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report