how to get the normal vector of a suface from a STL file

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
chopin1998
Posts: 2
Joined: Tue May 14, 2019 7:17 am

how to get the normal vector of a suface from a STL file

Post by chopin1998 »

i'm a newbie of freeCAD, and CAD...

i have a STL file, i need to know some normal vector of surfaces,

after lots of Google, here is my answer:

Gui.Selection.getSelectionEx()[0].SubObjects[0].Faces[0].normalAt(0,0).

But when i open my STL file, i cannot choose a surface by mouse?

what should i do?
Thank you very much!
Attachments
ufo.zip
(139.91 KiB) Downloaded 18 times
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to get the normal vector of a suface from a STL file

Post by wmayer »

Try this:

Code: Select all

def getNormal(cb):
    if cb.getEvent().getState() == coin.SoButtonEvent.UP:
        pp = cb.getPickedPoint()
        if pp:
            vec = pp.getNormal().getValue()
            index = coin.cast(pp.getDetail(), "SoFaceDetail").getFaceIndex()
            print ("Normal: {}, Face index: {}".format(str(vec), index))

from pivy import coin
meth=Gui.ActiveDocument.ActiveView.addEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), getNormal)

If you are done then run:

Code: Select all

Gui.ActiveDocument.ActiveView.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), meth)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: how to get the normal vector of a suface from a STL file

Post by Kunda1 »

#documentation
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
chopin1998
Posts: 2
Joined: Tue May 14, 2019 7:17 am

Re: how to get the normal vector of a suface from a STL file

Post by chopin1998 »

got it, need use part
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: how to get the normal vector of a suface from a STL file

Post by openBrain »

chopin1998 wrote: Wed May 15, 2019 4:35 am got it, need use part
I'm pretty sure this post will be highly useless if one has the same problem and land here... :roll:
mario52
Veteran
Posts: 4701
Joined: Wed May 16, 2012 2:13 pm

Re: how to get the normal vector of a suface from a STL file

Post by mario52 »

hi
Kunda1 wrote: Tue May 14, 2019 1:46 pm #documentation
done Get_the_normal_vector_of_a_suface_from_a_STL_file

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply