Macro CircularText

From FreeCAD Documentation
Revision as of 20:13, 21 August 2014 by Mario52 (talk | contribs) (Created page with "{{Macro/fr|Icon=Text-x-python|Name=Macro FCCircularText|Name/fr=Macro FCCircularText|Description=Cette macro crée votre texte autour d'un cylindre sur un angle désiré.|Auth...")

File:Text-x-python Macro FCCircularText

Description
Cette macro crée votre texte autour d'un cylindre sur un angle désiré.

Auteur: Mario52
Auteur
Mario52
Téléchargement
None
Liens
Version Macro
1.0
Dernière modification
None
Version(s) FreeCAD
None
Raccourci clavier
None
Voir aussi
None

Cette macro écris votre texte autour d'un cylindre sue un angle désigné et paramétrable dans la macro.

texte 360 degrees

Example

Here 180 degrees rotation

texte 180 degrees

Utilisation

set the following parameters

# configure begin
#################
PolicePath      = "C:/Windows/Polices/KLANG.TTF" # path font       #chemin de la police
rayon           = 10.0               # radius                      #rayon du cylindre
texte           = "FreeCad The Best" # your text                   #texte a afficher
                                     # PS: one space give an error #un espace donne une erreur ne pas en tenir compte
rotation        = 360                # must exceed the number of characters of text
                                     # doit être supérieur au nombre de caracteres du texte
SizeCaractere   = 5.0                # size font                   #hauteur du caractere

#################
# correction section here for radius 10 mm
# section correction ici pour un rayon de 10 mm
correctionAngle = 10.0               #angle correction tangent     #angle de correction pour affiner la tangent du a la largeur du caractere
correctionRayon = 0.15               #correct radius               #correction du rayon a cause de correctionAngle et suvant la grandeur du caractere
#################
#configure end
  1. PolicePath = "C:/Windows/Polices/KLANG.TTF"
    • your path font
  2. rayon = 10.0
    • radius of cylinder
  3. rotation = 180
    • rotation occupied by text 0 to ... max 360 (must exceed the number of characters of text)
  4. texte = "FreeCad The Best"
    • your text to display (PS: space gives an error not to consider)
  5. SizeCaractere = 5.0
    • size font
  6. here for radius 10 mm (change to another radius)
    1. correctionAngle = 10.0
      • correction angle of the tangent to narrow the width of the character
    2. correctionRayon = 0.15
      • radius compensation because of correctionAngle and depending on the size of the character

Script

Macro FCCircularText.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
*   Copyright (c) 2014 <mario52>                                          *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License (LGPL)    *
*   as published by the Free Software Foundation; either version 2 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
*                                                                         *
*   This software is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
*           WARNING! All changes in this file will be lost and            *  
*                  may cause malfunction of the program                   *
***************************************************************************
"""
# FCCircularText.FCMacro
# ver 0.1 20/08/2014
#
#OS: Windows Vista
#Word size: 32-bit
#Version: 0.14.3700 (Git)
#Branch: releases/FreeCAD-0-14
#Hash: 32f5aae0a64333ec8d5d160dbc46e690510c8fe1
#Python version: 2.6.2
#Qt version: 4.5.2
#Coin version: 3.1.0
#SoQt version: 1.4.1

import FreeCAD, FreeCADGui, Draft, Part
import FreeCAD, Part, PartGui, math
from math import sqrt, pi, sin, cos, asin, degrees, radians, tan

points   = 0.0
coor_X   = 0.0
coor_Y   = 0.0
coor_Z   = 0.0
vec      = 0
rotation = 0
ii       = 0
precision       = 0.0
correctionAngle = 0.0
correctionRayon = 0.0

# pointColor
red   = 1.0  # 1 = 255
green = 0.0  #
blue  = 0.0  #

points = []
del points[:]

# configure begin
#################
PolicePath      = "C:/Windows/Polices/KLANG.TTF" # path font       #chemin de la police
rayon           = 10.0               # radius                      #rayon du cylindre
texte           = "FreeCad The Best" # your text                   #texte a afficher
                                     # PS: one space give an error #un espace donne une erreur ne pas en tenir compte
rotation        = 360                # must exceed the number of characters of text
                                     # doit être supérieur au nombre de caracteres du texte
SizeCaractere   = 5.0                # size font                   #hauteur du caractere

#################
# correction section here for radius 10 mm
# section correction ici pour un rayon de 10 mm
correctionAngle = 10.0               #angle correction tangent     #angle de correction pour affiner la tangent du a la largeur du caractere
correctionRayon = 0.15               #correct radius               #correction du rayon a cause de correctionAngle et suvant la grandeur du caractere
#################
#configure end

vecligne=[FreeCAD.Vector(0.0,0.0,0.0),FreeCAD.Vector(rayon + correctionRayon,0.0,0.0)]      # 
ligne = Draft.makeWire(vecligne,closed=False,face=False,support=None)     # création de la ligne de base

ii     = -1
nombre = len(texte)

for i in range(0,360,(rotation/nombre)): # 360 a parametrer
    ii += 1
    a = FreeCAD.ActiveDocument.Line.Placement=App.Placement(App.Vector(0,0,0), App.Rotation(App.Vector(0,0,1),i), App.Vector(0,0,0))
    a = ligne.Shape.Edges[0].Vertexes[1] # fin
    coor_X = (a.Point.x)
    coor_Y = (a.Point.y)

    if ii < nombre:
        ss=Draft.makeShapeString(String=texte[ii],FontFile=PolicePath,Size=SizeCaractere,Tracking=0)
        plm=FreeCAD.Placement()
        plm.Base=FreeCAD.Vector(coor_X,coor_Y,coor_Z)
        plm = App.Placement(App.Vector(coor_X,coor_Y,coor_Z), App.Rotation(i+90+correctionAngle,0,90), App.Vector(0,0,0)) # pitch,roll...1
        ss.Placement=plm 
        ss.Support=None
    points += [FreeCAD.Vector(coor_X,coor_Y,coor_Z)]

Draft.makeBSpline(points,closed=True,face=False,support=None)    # makeBSpline

App.ActiveDocument.removeObject(ligne.Name)

## cercle de verification (avec le rayon donne)
## verification circle (with radius gives)
#pl=FreeCAD.Placement()
#pl.Rotation.Q=(0.0,-0.0,-0.0,1.0)
#pl.Base=FreeCAD.Vector(0.0,0.0,0.0)
#Circle = Draft.makeCircle(radius=10.0,placement=pl,face=False,support=None)
#FreeCADGui.getDocument("Sans_nom").getObject("Circle").LineColor = (1.0000000000,0.0000000000,0.0000000000)
#FreeCADGui.ActiveDocument.Circle.LineColor = (1.0000000000,0.0000000000,0.0000000000)

(not fully developed)

Currently:

  • ver 0.1

Links

To comment on the Extrude from curved surface of cylinder

Other languages: