Last active
August 29, 2015 14:04
-
-
Save mangtronix/0b5010766d105874a3d5 to your computer and use it in GitHub Desktop.
Attempt to project text onto a cylinder and then extrude for embossing in FreeCAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Part, Draft | |
from FreeCAD import Base | |
v=Base.Vector | |
doc=App.ActiveDocument | |
font="/Users/mangtronix/src/blender/release/datafiles/bfont.ttf" | |
# ShapeString text | |
ss=Draft.makeShapeString(String=u"Hi",FontFile=font,Size=2.0,Tracking=0) | |
# Circle at text center | |
c=Part.makeCircle(2,ss.Shape.BoundBox.Center,v(0,0,1)) | |
s=Part.makeCylinder(4,10, v(1,-3,-10), v(0,1,0)) | |
f=s.Face1 | |
p=f.makeParallelProjection(c,v(0,0,1)) | |
sf = doc.addObject("Part::Feature","Cylinder") | |
sf.Shape = s | |
pf = doc.addObject("Part::Feature","Circle projection") | |
pf.Shape = p | |
cf = doc.addObject("Part::Feature","Circle") | |
cf.Shape = c | |
sp=None | |
try: | |
sp=f.makeParallelProjection(ss.Shape,v(0,0,1)) | |
# XXX this generates this traceback | |
# Traceback (most recent call last): | |
# File "<input>", line 1, in <module> | |
# Exception: /Users/family/FreeCAD-deps/oce-src/src/BRepProj/BRepProj_Projection.cxx: projected shape is neither wire nor edge | |
spf = App.ActiveDocument.addObject("Part::Feature", "Text projection") | |
spf.Shape = sp | |
except Exception,e: | |
FreeCAD.Console.PrintWarning(e) | |
def projectAndFuseWires(face, shape, dir): | |
projected_wires = [] | |
for wire in shape.Wires: | |
projected_wires.append(face.makeParallelProjection(wire, dir)) | |
fused = projected_wires[0] | |
for wire in projected_wires[1:]: | |
fused = fused.fuse(wire) | |
return fused | |
fused = projectAndFuseWires(s, ss.Shape, v(0,0,1)) | |
fused_feature = doc.addObject("Part::Feature", "Fused projections") | |
fused_feature.Shape = fused | |
h_wire = ss.Shape.Wires[0] | |
projected_wires = f.makeParallelProjection(h_wire,v(0,0,1)) | |
front_projected_wire = projected_wires.Wires[1] | |
front_feature = doc.addObject("Part::Feature", "Front projected H") | |
front_feature.Shape = front_projected_wire | |
h_face = Part.makeFilledFace(Part.__sortEdges__(front_projected_wire.Edges)) | |
h_face_feature = doc.addObject("Part::Feature", "H face") | |
h_face_feature.Shape = h_face | |
extrusion = doc.addObject("Part::Extrusion", "Extruded H") | |
extrusion.Base = h_face_feature | |
extrusion.Dir = v(0,0,1) | |
extrusion.Solid = True | |
# OS: Mac OS X | |
# Word size: 64-bit | |
# Version: 0.14.3703 (Git) | |
# Branch: releases/FreeCAD-0-14 | |
# Hash: c6edd47334a3e6f209e493773093db2b9b4f0e40 | |
# Python version: 2.7.5 | |
# Qt version: 4.8.6 | |
# Coin version: 3.1.3 | |
# SoQt version: 1.5.0 | |
# OCC version: 6.7.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment