danfalck

headless_freecad_webgl.py

May 12th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. FREECADPATH = '/home/danfalck/cadcam/freecad/freecad1/lib'
  6. sys.path.append(FREECADPATH)
  7. import FreeCAD, Part, Drawing, importWebGL
  8.  
  9. box = Part.makeBox(100,100,100)
  10. box.translate(box.CenterOfMass.multiply(-1))
  11.  
  12. cylx = Part.makeCylinder(25, 100, FreeCAD.Base.Vector(0,1,0), FreeCAD.Base.Vector(0,90,0))
  13. cylx.translate(cylx.CenterOfMass.multiply(-1))
  14.  
  15. cyly = Part.makeCylinder(25, 100, FreeCAD.Base.Vector(0,1,0), FreeCAD.Base.Vector(90,0,0))
  16. cyly.translate(cyly.CenterOfMass.multiply(-1))
  17.  
  18. cylz = Part.makeCylinder(25, 100)
  19. cylz.translate(cylz.CenterOfMass.multiply(-1))
  20.  
  21. hole = cylx.fuse(cyly).fuse(cylz)
  22.  
  23. test = box.cut(hole).common(Part.makeSphere(50))
  24.  
  25. Part.show(test)
  26.  
  27. Shape = FreeCAD.ActiveDocument.Shape.Shape
  28.  
  29. visibleG0,visibleG1,hiddenG0,hiddenG1 = Drawing.project(Shape,FreeCAD.Base.Vector(1,1,1))
  30. resultSVG = Drawing.projectToSVG(Shape,FreeCAD.Base.Vector(1,0.2,1))
  31. # if 0 is used instead of dv, the image is rendered incorrectly
  32. #resultSVG = Drawing.projectToSVG(Shape,FreeCAD.Base.Vector(0,dv,1))
  33.  
  34.  
  35.  
  36.  
  37. #with open('test.html', 'w') as f:
  38. #  f.write('<html>')
  39. #  f.write('<body>')
  40. #  f.write('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-100 -100 200 200">')
  41. #  f.write(resultSVG)
  42. #  f.write('</svg>')
  43. #  f.write('</html>')
  44. #  f.write('</body>')
  45.  
  46. def drawIt():
  47.     result = ''
  48.     result+='<html>'
  49.     result+='<body>'
  50.     result+='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-100 -100 200 200">'
  51.     result+= resultSVG
  52.     result+= '</svg>'
  53.     result+='</html>'
  54.     result+='</body>'
  55.     return result
  56.    
  57.  
  58. def drwsolid():
  59.     solidlist = [test]
  60.     result = ''
  61.     result+= importWebGL.getHTML(solidlist)
  62.     return result
Add Comment
Please, Sign In to add comment