[0.17 PDN] How to engrave a ShapeString in a PDN-Body

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!
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

Re: [0.17 PDN] How to engrave a ShapeString in a PDN-Body

Post by chrisb »

I'm glad Mario could help, so this is just for the record: please receive my apologies, I was on the wrong track. I won't detail it further, because there is no added value in doing so. Sorry for the confusion.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Mongrel_Shark
Posts: 138
Joined: Sat Oct 15, 2016 9:54 am
Location: Australia

Re: [0.17 PDN] How to engrave a ShapeString in a PDN-Body

Post by Mongrel_Shark »

All good Chris.
I have a lot of tolerance and patience for forum regulars. You guys are awesome. If it wasn't for freecad and the forum. I'd still be an unemployed disability pensioner ;) But now I am full time engineer :ugeek: Freecad is the best! I just wish I had time and skills to help out around here more. The aforementioned life change has left me a bit short of free time this year...

Back to the topic at hand
Any thoughts on better attaching those individual shape strings?? I've seen people mention attaching datum planes to sketches. This gives me an idea. Except i cant quite get it to work right.


I have modified Sketch 2 in the attached fcstd file. Before it was just a circle for visual alignment help. Now its a circle with 3 flat lines in it. and a construction line for angular constraint.

If I can attach datum planes to these 3 flats and lean the datum planes back to the apropiate 45 deg angle. Then we should be able to attach the letters to the dautum planes. If this works we should get parametric, curved, angled, text :D
Attachments
Circular text 45 PDN eg 0.2.fcstd
(369.42 KiB) Downloaded 21 times
mario52
Veteran
Posts: 4696
Joined: Wed May 16, 2012 2:13 pm

Re: [0.17 PDN] How to engrave a ShapeString in a PDN-Body

Post by mario52 »

hi
Mongrel_Shark wrote: Fri Aug 10, 2018 3:57 am Now who wants to show me how to helix text all the way around a ball? :mrgreen: I want to 3dprint a FREECAD IS THE BEST golf ball. Where instead of dimples it has text pocketed in. :mrgreen:
for the fun (code helix on sphere by UR_)

Code: Select all

import Draft, Part
import FreeCAD
import math
from math import degrees, radians
App = FreeCAD

__title__   = "Golf_ball"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__Wiki__    = ""
__version__ = "00.00"
__date__    = "21/08/2018"

def macro3DSpline_Helix_On_Sphere(Rayon = 5.0, rounds = 5.0):
    # 3dBsplineHelixOnSphere.FCMacro  by UR_	
    # https://www.forum.freecadweb.org/viewtopic.php?f=3&t=27567

    import Draft
    import math
    
    Rayon  = float(Rayon)
    rounds = float(rounds)
    step = 0.1           # rad

    tmin = -rounds / 2.0 * 2.0 * math.pi
    tmax =  rounds / 2.0 * 2.0 * math.pi
    
    pts=[]              # start values
    x = y = z = 0.0
    t = tmin

    print "Wait create Helix"
    FreeCADGui.updateGui()                                 # rafraichi l'ecran
    while t < tmax:
        z = t * Rayon / tmax
        r = math.sqrt(Rayon * Rayon - z * z)
        x = r * math.cos(t)
        y = r * math.sin(t)
        pts.append((x,y,z))
        t += step
    
    return Draft.makeBSpline(pts)
#macro3DSpline_Helix_On_Sphere(5.0, 5.0)

def creaGolf( rayon = 5.0, tours = 5.0, texte = "FreeCAD the best", hauteurTexte = 2.0, epaisseur = 0.0 ):

    doc = FreeCAD.ActiveDocument
    if doc == None:
        doc = FreeCAD.newDocument("Golf")

    ssstr = []
    lineD = []
    extrU = []
    extrN = []

    param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")# FontFile in parameter
    FontName = param.GetString("FontFile","")                               # FontFile in parameter

    Helice = macro3DSpline_Helix_On_Sphere(Rayon = rayon, rounds = tours)

    sphere = App.ActiveDocument.addObject("Part::Sphere","Sphere")
    sphere.Label = "Sphere"
    sphere.Radius = rayon
    nombre = len(texte)

    xx = 0.0                         # distance
    xx = Helice.Shape.Length
    points0  = Helice.Shape.discretize(Distance = (xx / (nombre-1)))

    cText = 0

    print "Wait create Character"
    FreeCADGui.updateGui()                                 # rafraichi l'ecran
    for pp in points0:
        points=[FreeCAD.Vector(0.0,0.0,0.0),FreeCAD.Vector(pp)]
        line = Draft.makeWire(points,closed=False,face=False,support=None)
        line.Length = rayon
        line.Label = "Line_" + texte[cText]
        lineD.append(line)

        direction = line.End.sub(line.Start)
        r = App.Rotation(App.Vector(0,0,1),direction)

        ss = Draft.makeShapeString(String=texte[cText], FontFile=FontName, Size=hauteurTexte,Tracking=0)

        plm = FreeCAD.Placement()
        plm.Base = FreeCAD.Vector(line.End)
        plm.Rotation.Q = r.Q

        ss.Placement=plm
        ss.Support=None
        ss.Label = "Golf_" + texte[cText]
        ssstr.append(ss.Name)

#        point = Draft.makePoint(pointsX[i])
#        print plm.Base," ",pointsX[i]


        #### extrude character
        if epaisseur != 0.0:
            f = FreeCAD.activeDocument().addObject('Part::Extrusion', 'Golf')
            f = App.activeDocument().getObject(f.Name)
            f.Base = App.activeDocument().getObject(ss.Name)
            f.DirMode = 1
            f.DirLink = (App.activeDocument().getObject(line.Name), ["Edge1"])
            f.LengthFwd = epaisseur
            f.Solid = True
            f.Reversed = False
            f.Symmetric = True
            f.Base.ViewObject.hide()
            App.ActiveDocument.recompute()

            extrU.append(f.Shape)
            extrN.append(f.Name)
            #### extrude character

        cText += 1
        if cText > len(texte):
            cText = 0
#        ####################
#


    #### create compound string
    print "Wait create Compound"
    FreeCADGui.updateGui()                                 # rafraichi l'ecran
    if epaisseur != 0.0:
        comp = Part.makeCompound(extrU)
        Part.show(comp)
        FreeCADGui.activeDocument().activeObject().ShapeColor = (1.0,0.0,0.0)

    #### create the cut sphere string
    print "Wait create cut sphere string"
    FreeCADGui.updateGui()                                 # rafraichi l'ecran
    cutSphereString = App.activeDocument().addObject("Part::Cut","Cut")
    App.activeDocument().Cut.Base = App.activeDocument().getObject(sphere.Name)
    App.activeDocument().Cut.Tool = App.activeDocument().Shape
    cutSphereString.Label = "Golf_ball"


    #### remove the tools
    print "Wait remove the tools"
    FreeCADGui.updateGui()                                 # rafraichi l'ecran

    #### remove string
    for i in ssstr:
        App.activeDocument().removeObject(i)

    #### remove helix
#    App.activeDocument().removeObject(Helice.Name)

    #### remove line directrice
    for i in lineD:
        App.activeDocument().removeObject(i.Name)

    #### remove the string extruded
    if epaisseur != 0.0:
        for i in extrN:
            App.activeDocument().removeObject(i)
    ####

    print "End__________"
    FreeCADGui.updateGui()                                 # rafraichi l'ecran
    App.ActiveDocument.recompute()
    Gui.SendMsgToActiveView("ViewFit")


## command line config
#creaGolf(rayon = (42.67/2.0) , tours = 5, texte = "FreeCAD the Best FreeCAD the Best FreeCAD the Best FreeCAD the Best FreeCAD the Best FreeCAD the Best FreeCAD the Best FreeCAD the Best", hauteurTexte = 3.0, epaisseur = 2.0)
creaGolf(rayon = (42.67/2.0) , tours = 3, texte = "FreeCAD the Best FreeCAD the Best", hauteurTexte = 5.0, epaisseur = 2.0)
#creaGolf(rayon = (42.67/2.0) , tours = 3, texte = "FreeCAD", hauteurTexte = 5.0, epaisseur = 10.0)

Golf_ball00.png
Golf_ball00.png (27.15 KiB) Viewed 392 times
but the character rotate 1 turn of 1 turn of sphere
Golf_ball01.png
Golf_ball01.png (24.48 KiB) Viewed 392 times
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