Is there way to export normals info without using GUI?[Solve

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
kwahoo
Posts: 687
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Is there way to export normals info without using GUI?[Solve

Post by kwahoo »

Hi!
I found that normal vectors created via FreeCADGui.ActiveDocument.ActiveObject.toString() are pretty useful. Is there a way to export similar info to:

Code: Select all

        Normal {
          vector [ -1 0 0,
              -1 0 0,
              -1 0 0,
              -1 0 0,
              1 0 0,
              1 0 0,
              1 0 0,
              1 0 0,
              0 -1 0,
              0 -1 0,
              0 -1 0,
              0 -1 0,
              0 1 0,
              0 1 0,
              0 1 0,
              0 1 0,
              0 0 -1,
              0 0 -1,
              0 0 -1,
              0 0 -1,
              0 0 1,
              0 0 1,
              0 0 1,
              0 0 1 ]

        }
but without GUI? Unfortunately writeInventor() cannot do this:(

EDIT: I got something after reading OpenInventor docs:

Code: Select all

from pivy import coin
import Part
box = Part.makeBox(10, 10, 10)
fcmesh = box.tessellate(0.1)
gen = coin.SoNormalGenerator(True)
for f in fcmesh[1]: #indexes
    #print f[0],f[1],f[2]
    v0 = fcmesh[0][f[0]]
    v1 = fcmesh[0][f[1]]
    v2 = fcmesh[0][f[2]] 
    #print v0, v1, v2
    sbv0 = coin.SbVec3f(v0)
    sbv1 = coin.SbVec3f(v1)
    sbv2 = coin.SbVec3f(v2)
    #gen.beginPolygon()
    gen.triangle(sbv0, sbv1, sbv2)
    #gen.endPolygon()

gen.generate(1.5) #generate with cease angle 1.5 rad
#gen.getNumNormals()
for i in range(gen.getNumNormals()):
   print gen.getNormal(i).getValue()
gives:

Code: Select all

(-1.0, 0.0, 0.0)
(-1.0, 0.0, 0.0)
(-1.0, 0.0, 0.0)
(-1.0, 0.0, 0.0)
(-1.0, 0.0, 0.0)
(-1.0, 0.0, 0.0)
(1.0, 0.0, 0.0)
(1.0, 0.0, 0.0)
(1.0, 0.0, -0.0)
(1.0, 0.0, 0.0)
(1.0, 0.0, 0.0)
(1.0, 0.0, 0.0)
(0.0, -1.0, 0.0)
(0.0, -1.0, 0.0)
(0.0, -1.0, 0.0)
(0.0, -1.0, 0.0)
(0.0, -1.0, 0.0)
(0.0, -1.0, 0.0)
(0.0, 1.0, 0.0)
(0.0, 1.0, -0.0)
(0.0, 1.0, 0.0)
(0.0, 1.0, 0.0)
(0.0, 1.0, 0.0)
(0.0, 1.0, 0.0)
(0.0, 0.0, -1.0)
(0.0, 0.0, -1.0)
(0.0, 0.0, -1.0)
(0.0, 0.0, -1.0)
(0.0, 0.0, -1.0)
(0.0, 0.0, -1.0)
(0.0, 0.0, 1.0)
(-0.0, 0.0, 1.0)
(0.0, 0.0, 1.0)
(0.0, 0.0, 1.0)
(0.0, 0.0, 1.0)
(0.0, 0.0, 1.0)
Post Reply