TechDraw API/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "Attributs de CosmeticView<br> Tag : identifiant unique. Chaîne de caractères.<br> Point : emplacement dans la vue. Vecteur.<br>")
No edit summary
 
(44 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{VeryImportantMessage|(Novembre 2018) Ces informations peuvent être incomplètes et obsolètes. Pour la dernière API, consultez [https://www.freecadweb.org/api autogenerated API documentation].}}
{{VeryImportantMessage|(Novembre 2018) Ces informations peuvent être incomplètes et obsolètes. Pour la dernière API, consultez [https://www.freecadweb.org/api autogenerated API documentation].}}
Ces fonctions font partie de l'[[TechDraw Workbench/fr|Atelier TechDraw]] et peuvent être utilisées dans [[macros/fr|macros]] et à partir de la console [[Python/fr|Python]] une fois que le module {{incode|TechDraw}} a été importé.
Ces fonctions font partie de l'[[TechDraw_Workbench/fr|atelier TechDraw]] et peuvent être utilisées dans des [[Macros/fr|macros]] et à partir de la console [[Python/fr|Python]] une fois que le module {{incode|TechDraw}} a été importé.


Vous trouverez de bons exemples de scripts TechDraw de base dans le site [https://github.com/FreeCAD/FreeCAD/tree/master/src/Mod/TechDraw/TDTest unit test scripts].
Vous trouverez de bons exemples de scripts TechDraw de base dans le site [https://github.com/FreeCAD/FreeCAD/tree/master/src/Mod/TechDraw/TDTest unit test scripts].
Line 8: Line 8:


Exemple :
Exemple :

{{Code|code=
{{Code|code=
import FreeCAD
import FreeCAD
Line 27: Line 28:
{{APIFunction|viewPartAsDxf|DrawViewPart|renvoie les bords de DrawViewPart au format Dxf.|chaîne de caractères}}
{{APIFunction|viewPartAsDxf|DrawViewPart|renvoie les bords de DrawViewPart au format Dxf.|chaîne de caractères}}
Exemple :
Exemple :

{{Code|code=
{{Code|code=
fileSpecDxf = "fcOut.dxf"
fileSpecDxf = "fcOut.dxf"
Line 40: Line 42:
{{APIFunction|viewPartAsSvg|DrawViewPart|renvoie les bords de DrawViewPart au format Svg.|chaîne de caractères}}
{{APIFunction|viewPartAsSvg|DrawViewPart|renvoie les bords de DrawViewPart au format Svg.|chaîne de caractères}}
Exemple :
Exemple :

{{Code|code=
{{Code|code=
fileSpecSvg = "fcOut.svg"
fileSpecSvg = "fcOut.svg"
Line 57: Line 60:
{{APIFunction|writeDXFView|DrawViewPart, FileName|enregistre DrawViewPart au format Dxf.|fichier}}
{{APIFunction|writeDXFView|DrawViewPart, FileName|enregistre DrawViewPart au format Dxf.|fichier}}
Exemple :
Exemple :

{{Code|code=
{{Code|code=
import TechDraw
import TechDraw
Line 64: Line 68:
{{APIFunction|writeDXFPage|DrawPage, FileName|enregistre DrawPage au format Dxf.|fichier}}
{{APIFunction|writeDXFPage|DrawPage, FileName|enregistre DrawPage au format Dxf.|fichier}}
Exemple :
Exemple :

{{Code|code=
{{Code|code=
import TechDraw
import TechDraw
Line 75: Line 80:
====Routines de CosmeticVertex (CV) accessibles à partir de Python====
====Routines de CosmeticVertex (CV) accessibles à partir de Python====


dvp = App.ActiveDocument.View #Les CV appartiennent à des vues<br>
dvp = App.ActiveDocument.View #Les CV appartiennent à des vues.<br>


ajoute un CosmeticVertex à p1 (coordonnées de la vue). Renvoie une balise unique.<br>
Ajoute un CosmeticVertex à p1 (coordonnées de la vue). Renvoie une balise unique.<br>
tag = dvp.makeCosmeticVertex(vector p1)
tag = dvp.makeCosmeticVertex(vector p1)


ajoute un CosmeticVertex à p1 (coordonnées du modèle 3D). Renvoie une balise unique.<br>
Ajoute un CosmeticVertex à p1 (coordonnées du modèle 3D). Renvoie une balise unique.<br>
tag = dvp.makeCosmeticVertex3d(vector p1)
tag = dvp.makeCosmeticVertex3d(vector p1)


renvoie un CosmeticVertex avec un identifiant unique.<br>
Renvoie un CosmeticVertex avec un identifiant unique.<br>
cv = dvp.getCosmeticVertex(string id)
cv = dvp.getCosmeticVertex(string id)


renvoie le CosmeticVertex avec le nom (Vertex6). Utilisé dans les sélections.<br>
Renvoie le CosmeticVertex avec le nom (Vertex6). Utilisé dans les sélections.<br>
cv = dvp.getCosmeticVertexBySelection(string name)
cv = dvp.getCosmeticVertexBySelection(string name)


supprime un CosmeticVertex d'une vue. Ne renvoie rien.<br>
Supprime un CosmeticVertex d'une vue. Ne renvoie rien.<br>
dvp.removeCosmeticVertex(object cv)
dvp.removeCosmeticVertex(object cv)


supprime tous les CosmeticVertices de la vue. Ne renvoie rien.<br>
Supprime tous les CosmeticVertices de la vue. Ne renvoie rien.<br>
dvp.clearCosmeticVertices()
dvp.clearCosmeticVertices()


Line 99: Line 104:
Point : emplacement dans la vue. Vecteur.<br>
Point : emplacement dans la vue. Vecteur.<br>


<!--T:28-->
********************************************************************************
********************************************************************************
{{Code|code=
{{Code|code=
Line 104: Line 110:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


<!--T:29-->
# Py CosmeticVertex demo
# Py CosmeticVertex demo
import FreeCAD
import FreeCAD
import TechDraw
import TechDraw


<!--T:30-->
v = App.ActiveDocument.View
v = App.ActiveDocument.View
p = App.Vector(-3.0, -3.0, 0.0)
p = App.Vector(-3.0, -3.0, 0.0)


<!--T:31-->
#make CV
#make CV
tag = v.makeCosmeticVertex(p)
tag = v.makeCosmeticVertex(p)
print("t: {}".format(tag))
print("t: {}".format(tag))


<!--T:32-->
#retrieve CV
#retrieve CV
cv = v.getCosmeticVertex(tag)
cv = v.getCosmeticVertex(tag)
Line 121: Line 131:




<!--T:34-->
cv2 = v.getCosmeticVertexBySelection("Vertex4")
cv2 = v.getCosmeticVertexBySelection("Vertex4")
print("New Point: {}".format(cv2.Point))
print("New Point: {}".format(cv2.Point))


<!--T:35-->
#make CV from 3d
#make CV from 3d
p3d = App.Vector(2.0, 2.0, 2.0)
p3d = App.Vector(2.0, 2.0, 2.0)
Line 132: Line 144:
}}
}}


<span id="CosmeticEdge_(CE)_routines_accessible_from_Python"></span>
====CosmeticEdge (CE) routines accessible from Python====
====Routines de CosmeticEdge (CE) accessibles à partir de Python====


dvp = App.ActiveDocument.View #CE's belong to views<br>
dvp = App.ActiveDocument.View #Les CE appartiennent à des vues.<br>


Make a CosmeticEdge from p1 to p2(View coordinates). Returns unique tag.<br>
Crée un CosmeticEdge de p1 à p2 (coordonnées de la vue). Renvoie une balise unique.<br>
tag = dvp.makeCosmeticLine(p1, p2)
tag = dvp.makeCosmeticLine(p1, p2)


Make a CosmeticEdge at center with radius radius(View coordinates). Returns unique tag.<br>
Crée un CosmeticEdge au centre avec un rayon (coordonnées de la vue). Retourne une balise unique.<br>
tag = dvp.makeCosmeticCircle(center, radius)
balise = dvp.makeCosmeticCircle(center, radius)


Make a CosmeticEdge at center with radius radius(View coordinates) from start angle to end angle. Returns unique tag.<br>
Crée un CosmeticEdge au centre avec un rayon rayon(coordonnées de la vue). Retourne une balise unique.<br>
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)


returns CosmeticEdge with unique id.<br>
Renvoie un CosmeticEdge avec un identifiant unique.<br>
ce = dvp.getCosmeticEdge(id)
ce = dvp.getCosmeticEdge(id)


returns CosmeticEdge by name (Edge25). Used in selections.<br>
Renvoie un CosmeticEdge avec le nom (Edge25). Utilisé dans les sélections.<br>
ce = dvp.getCosmeticEdgeBySelection(name)
ce = dvp.getCosmeticEdgeBySelection(name)


remove CosmeticEdge ce from View. Returns None.<br>
Supprime un CosmeticEdge d'une vue. Ne renvoie rien.<br>
dvp.removeCosmeticEdge(ce)
dvp.removeCosmeticEdge(ce)


remove all CosmeticLines from the View. Returns None.<br>
Supprime tous les CosmeticLines de la vue. Ne renvoie rien.<br>
dvp.clearCosmeticEdges()
dvp.clearCosmeticEdges()


Attributs de CosmeticEdge<br>
CosmeticEdge attributes<br>
Tag: unique identifier. String.<br>
Tag : identifiant unique. Chaîne de caractère.<br>
Format: appearance attributes (style, color, weight, visible). Tuple.<br>
Format : attributs d'apparence (style, couleur, poids, visible). Tuple.<br>


<!--T:47-->
********************************************************************************
********************************************************************************
{{Code|code=
{{Code|code=
Line 166: Line 180:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


<!--T:48-->
# Py CosmeticEdge demo
# Py CosmeticEdge demo
import FreeCAD
import FreeCAD
import TechDraw
import TechDraw


<!--T:49-->
#points
#points
org = App.Vector(0.0, 0.0, 0.0)
org = App.Vector(0.0, 0.0, 0.0)
Line 181: Line 197:
bottomLeft = FreeCAD.Vector(-5.0, -5.0, 0.0)
bottomLeft = FreeCAD.Vector(-5.0, -5.0, 0.0)


<!--T:50-->
#angles
#angles
arcStart = -45
arcStart = -45
arcEnd = 45
arcEnd = 45


<!--T:51-->
#styles
#styles
solid = 1
solid = 1
Line 199: Line 217:
shadow = (0.1, 0.1, 0.1, 0.0)
shadow = (0.1, 0.1, 0.1, 0.0)


<!--T:52-->
radius = 5.0
radius = 5.0
style = dashed
style = dashed
weight = weight75
weight = weight75


<!--T:53-->
dvp = App.ActiveDocument.View
dvp = App.ActiveDocument.View


<!--T:54-->
print(dvp)
print(dvp)


<!--T:55-->
print("making line")
print("making line")
tag = dvp.makeCosmeticLine(midTop,midBot,style, weight, pyBlue)
tag = dvp.makeCosmeticLine(midTop,midBot,style, weight, pyBlue)
Line 212: Line 234:
print("line tag: {}".format(tag))
print("line tag: {}".format(tag))


<!--T:56-->
print("making diagonal")
print("making diagonal")
dvp.makeCosmeticLine(bottomLeft,topRight,solid, weight, pyGreen)
dvp.makeCosmeticLine(bottomLeft,topRight,solid, weight, pyGreen)


<!--T:57-->
print("making circle")
print("making circle")
tag2 = dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)
tag2 = dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)
ce2 = dvp.getCosmeticEdge(tag2)
ce2 = dvp.getCosmeticEdge(tag2)


<!--T:58-->
print("making circleArc")
print("making circleArc")
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)


<!--T:59-->
#replace
#replace
print("making new format")
print("making new format")
Line 228: Line 254:
ce.Format = newFormat
ce.Format = newFormat


<!--T:61-->
print("removing CE with tag: {}".format(tag2))
print("removing CE with tag: {}".format(tag2))
dvp.removeCosmeticEdge(tag2)
dvp.removeCosmeticEdge(tag2)


<!--T:62-->
print("finished")
print("finished")
}}
}}


<span id="CenterLine_(CL)_routines_accessible_from_Python"></span>
====CenterLine (CL) routines accessible from Python====
====Routines de CenterLine (CL) accessibles à partir de Python====


make a new CenterLine<br>
Crée un nouveau CenterLine<br>
tag = dvp.makeCenterLine(subObjs, mode)<br>
tag = dvp.makeCenterLine(subObjs, mode)<br>


retrieve CenterLine with unique tag.<br>
Récupère un CenterLine avec une balise unique.<br>
cl = dvp.getCenterLine(tag)
cl = dvp.getCenterLine(tag)


retrieve CenterLine by subobject name. Used in selection.<br>
Récupère un CenterLine par nom de sous-objet. Utilisé dans la sélection.<br>
cl = dvp.getCenterLine("Edge5")
cl = dvp.getCenterLine("Edge5")


remove CenterLine cl from View. Returns None.<br>
Supprime un CenterLine cl d'une vue. Ne renvoie rien.<br>
dvp.removeCenterLine(cl)
dvp.removeCenterLine(cl)


Attributs de CenterLine<br>
CenterLine Attributes<br>
Tag : identifiant unique. Chaîne de caractères. En lecture seule.<br>
Tag: unique identifier. String. ReadOnly.<br>
Type: 0 - face, 1 - 2 line, 2 - 2 point. Integer. ReadOnly.<br>
Type : 0 - face, 1 - 2 lignes, 2 - 2 points. Entier. En lecture seule.<br>
Mode: 0 - vert, 1 - horiz, 2 - aligned. Integer.<br>
Mode : 0 - vertical, 1 - horizontal, 2 - aligné. Entier.<br>
Format: appearance attributes (style, color, weight, visible). Tuple.<br>
Format : attributs d'apparence (style, couleur, poids, visible). Tuple.<br>
HorizShift: left/right offset. Float.<br>
HorizShift : décalage gauche/droite. Flottant.<br>
VertShift: up/down offset. Float.<br>
VertShift : décalage haut/bas. Flottant.<br>
Rotation: rotation in degrees. Float.<br>
Rotation : rotation en degrés. Flottant.<br>
Extension: additional length to be added. Float.<br>
Extension : longueur supplémentaire à ajouter. Flottant.<br>
Flip: reverse the order of points for 2 point CenterLine. Boolean.<br>
Flip : inverse l'ordre des points pour une ligne centrale à 2 points. Booléen.<br>
Edges: names of source edges. List of string.<br>
Edges : noms des bords de la source. Liste de chaînes de caractères.<br>
Faces: names of source faces. List of string.<br>
Faces : noms des faces sources. Liste de chaînes de caractères.<br>
Points: names of source points (Vertices). List of string.<br>
Points : noms des points sources (sommets). Liste de chaînes de caractères.<br>


<!--T:70-->
********************************************************************************
********************************************************************************
{{Code|code=
{{Code|code=
Line 267: Line 297:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-


<!--T:71-->
# Py CenterLine demo
# Py CenterLine demo
import FreeCAD
import FreeCAD
Line 272: Line 303:
import TechDraw
import TechDraw


<!--T:72-->
start = FreeCAD.Vector (1.0, 5.0, 0.0) # middle, top
start = FreeCAD.Vector (1.0, 5.0, 0.0) # middle, top
end = FreeCAD.Vector(1.0, -5.0, 0.0) # middle, bottom
end = FreeCAD.Vector(1.0, -5.0, 0.0) # middle, bottom
Line 298: Line 330:
flip = False;
flip = False;


<!--T:73-->
dvp = App.ActiveDocument.View
dvp = App.ActiveDocument.View


<!--T:74-->
print("making face CenterLine")
print("making face CenterLine")
tag = dvp.makeCenterLine(faceNames,vMode)
tag = dvp.makeCenterLine(faceNames,vMode)
Line 305: Line 339:
print("cline tag: {}".format(tag))
print("cline tag: {}".format(tag))


<!--T:75-->
#replace
#replace
print("making new format")
print("making new format")
Line 312: Line 347:
cline.Extension = 10.0
cline.Extension = 10.0


<!--T:77-->
print("making edgeCenterLine")
print("making edgeCenterLine")
cline2 = dvp.makeCenterLine(edgeNames,hMode)
cline2 = dvp.makeCenterLine(edgeNames,hMode)


<!--T:78-->
print("making vertexCenterLine")
print("making vertexCenterLine")
cline3 = dvp.makeCenterLine(vertNames,aMode)
cline3 = dvp.makeCenterLine(vertNames,aMode)


<!--T:79-->
print("finished")
print("finished")
}}
}}


<span id="DrawViewPart_Geometry"></span>
===DrawViewPart Geometry===
===Géométrie de DrawViewPart===

[topoShapeEdge] = dvp.getVisibleEdges()
[topoShapeEdge] = dvp.getVisibleEdges()


Line 332: Line 372:
topoShapeVertex = dvp.getVertexBySelection("Vertex1")
topoShapeVertex = dvp.getVertexBySelection("Vertex1")


Redessine le graphique pour cette vue.<br>
dvp.requestPaint() Redraw the graphic for this View.
dvp.requestPaint()


{{TechDraw Tools navi{{#translation:}}}}
{{TechDraw Tools navi{{#translation:}}}}

Latest revision as of 21:01, 16 January 2024

(Novembre 2018) Ces informations peuvent être incomplètes et obsolètes. Pour la dernière API, consultez autogenerated API documentation.

Ces fonctions font partie de l'atelier TechDraw et peuvent être utilisées dans des macros et à partir de la console Python une fois que le module TechDraw a été importé.

Vous trouverez de bons exemples de scripts TechDraw de base dans le site unit test scripts.

Voir TechDrawGui API pour plus de fonctions.

Exemple :

import FreeCAD
import TechDraw

page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage', 'Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate', 'Template')
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.ViewObject.show()
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart', 'View')
rc = page.addView(view)
EdgeWalker(listOfEdges, [bool])

Description: crée des polylignes à partir des arêtes en entrée en parcourant le graphe planaire. Il est possible d'exclure la polyligne extérieure (OuterWire) en définissant le paramètre optionnel à false.

Returns: liste de polylignes triées par taille (décroissante)

findOuterWire(listOfEdges)

Description: trouve la polyligne extérieure (la plus grande) d'une liste d'arêtes (qui forment un graphe planaire).

Returns: polyligne extérieur

findShapeOutline(TopoShape, scale, direction)

Description: projette la forme dans la direction et trouve la polyligne extérieure du résultat.

Returns: polyligne de contour

viewPartAsDxf(DrawViewPart)

Description: renvoie les bords de DrawViewPart au format Dxf.

Returns: chaîne de caractères

Exemple :

fileSpecDxf = "fcOut.dxf"
v = App.ActiveDocument.View
s = TechDraw.viewPartAsDxf(v)
dxfEnd = "0\nEOF\n"
dxfFile = open(fileSpecDxf, "w")
dxfFile.write(s)
dxfFile.write(dxfEnd)
dxfFile.close()
viewPartAsSvg(DrawViewPart)

Description: renvoie les bords de DrawViewPart au format Svg.

Returns: chaîne de caractères

Exemple :

fileSpecSvg = "fcOut.svg"
v = App.ActiveDocument.View
s = TechDraw.viewPartAsSvg(v)
head = '<svg\n' + \
       '	xmlns="http://www.w3.org/2000/svg" version="1.1" \n' + \
       '	xmlns:freecad="http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace">\n'
tail = '\n</svg>'
svgFile = open(fileSpecSvg, "w")
svgFile.write(head)
svgFile.write(s)
svgFile.write(tail)
svgFile.close()
writeDXFView(DrawViewPart, FileName)

Description: enregistre DrawViewPart au format Dxf.

Returns: fichier

Exemple :

import TechDraw
TechDraw.writeDXFView(myPart,myFileName)
writeDXFPage(DrawPage, FileName)

Description: enregistre DrawPage au format Dxf.

Returns: fichier

Exemple :

import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)

Cosmétiques de DrawViewPart

Routines de CosmeticVertex (CV) accessibles à partir de Python

dvp = App.ActiveDocument.View #Les CV appartiennent à des vues.

Ajoute un CosmeticVertex à p1 (coordonnées de la vue). Renvoie une balise unique.
tag = dvp.makeCosmeticVertex(vector p1)

Ajoute un CosmeticVertex à p1 (coordonnées du modèle 3D). Renvoie une balise unique.
tag = dvp.makeCosmeticVertex3d(vector p1)

Renvoie un CosmeticVertex avec un identifiant unique.
cv = dvp.getCosmeticVertex(string id)

Renvoie le CosmeticVertex avec le nom (Vertex6). Utilisé dans les sélections.
cv = dvp.getCosmeticVertexBySelection(string name)

Supprime un CosmeticVertex d'une vue. Ne renvoie rien.
dvp.removeCosmeticVertex(object cv)

Supprime tous les CosmeticVertices de la vue. Ne renvoie rien.
dvp.clearCosmeticVertices()

Attributs de CosmeticView
Tag : identifiant unique. Chaîne de caractères.
Point : emplacement dans la vue. Vecteur.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Py CosmeticVertex demo
import FreeCAD
import TechDraw

v = App.ActiveDocument.View
p = App.Vector(-3.0, -3.0, 0.0)

#make CV
tag = v.makeCosmeticVertex(p)
print("t: {}".format(tag))

#retrieve CV
cv = v.getCosmeticVertex(tag)
print("cv: {}".format(cv))
print("Tag: {}".format(cv.Tag))


cv2 = v.getCosmeticVertexBySelection("Vertex4")
print("New Point: {}".format(cv2.Point))

#make CV from 3d
p3d = App.Vector(2.0, 2.0, 2.0)
print("3d point in: {}".format(p3d))
tag3d = v.makeCosmeticVertex3d(p3d)
cv3 = v.getCosmeticVertex(tag3d)
print("3d point out: {}".format(cv3.Point))

Routines de CosmeticEdge (CE) accessibles à partir de Python

dvp = App.ActiveDocument.View #Les CE appartiennent à des vues.

Crée un CosmeticEdge de p1 à p2 (coordonnées de la vue). Renvoie une balise unique.
tag = dvp.makeCosmeticLine(p1, p2)

Crée un CosmeticEdge au centre avec un rayon (coordonnées de la vue). Retourne une balise unique.
balise = dvp.makeCosmeticCircle(center, radius)

Crée un CosmeticEdge au centre avec un rayon rayon(coordonnées de la vue). Retourne une balise unique.
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)

Renvoie un CosmeticEdge avec un identifiant unique.
ce = dvp.getCosmeticEdge(id)

Renvoie un CosmeticEdge avec le nom (Edge25). Utilisé dans les sélections.
ce = dvp.getCosmeticEdgeBySelection(name)

Supprime un CosmeticEdge d'une vue. Ne renvoie rien.
dvp.removeCosmeticEdge(ce)

Supprime tous les CosmeticLines de la vue. Ne renvoie rien.
dvp.clearCosmeticEdges()

Attributs de CosmeticEdge
Tag : identifiant unique. Chaîne de caractère.
Format : attributs d'apparence (style, couleur, poids, visible). Tuple.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Py CosmeticEdge demo
import FreeCAD
import TechDraw

#points
org = App.Vector(0.0, 0.0, 0.0)
midTop = FreeCAD.Vector (1.0, 5.0, 0.0)   # middle, top
midBot = FreeCAD.Vector(2.0, -5.0, 0.0)      # middle, bottom
stdZ = FreeCAD.Vector(0.0, 0.0, 1.0)
center = FreeCAD.Vector(0.0, 0.0, 0.0)
arcCenter = FreeCAD.Vector(3.0, 3.0, 0.0)
vPt = FreeCAD.Vector(-3.0, 3.0, 0.0)
topRight = FreeCAD.Vector(5.0, 5.0, 0.0)
bottomLeft = FreeCAD.Vector(-5.0, -5.0, 0.0)

#angles
arcStart = -45
arcEnd = 45

#styles
solid = 1 
dashed = 2
dotted = 3
#weights
weight15 = 0.15
weight75 = 0.75
#colors
pyRed = (1.0, 0.0, 0.0, 0.0)
pyBlue = (0.0, 1.0, 0.0, 0.0)
pyGreen = (0.0, 0.0, 1.0, 0.0)
pyBlack = (0.0, 0.0, 0.0, 0.0)
shadow = (0.1, 0.1, 0.1, 0.0)

radius = 5.0
style = dashed
weight = weight75

dvp = App.ActiveDocument.View

print(dvp)

print("making line")
tag = dvp.makeCosmeticLine(midTop,midBot,style, weight, pyBlue)
ce = dvp.getCosmeticEdge(tag)
print("line tag: {}".format(tag))

print("making diagonal")
dvp.makeCosmeticLine(bottomLeft,topRight,solid, weight, pyGreen)

print("making circle")
tag2 = dvp.makeCosmeticCircle(center, radius, style, weight, pyRed)
ce2 = dvp.getCosmeticEdge(tag2)

print("making circleArc")
dvp.makeCosmeticCircleArc(arcCenter, radius, arcStart, arcEnd, style, weight, shadow)

#replace
print("making new format")
oldFormat = ce.Format
newFormat = (dotted,oldFormat[1], pyRed, True)
ce.Format = newFormat

print("removing CE with tag: {}".format(tag2))
dvp.removeCosmeticEdge(tag2)

print("finished")

Routines de CenterLine (CL) accessibles à partir de Python

Crée un nouveau CenterLine
tag = dvp.makeCenterLine(subObjs, mode)

Récupère un CenterLine avec une balise unique.
cl = dvp.getCenterLine(tag)

Récupère un CenterLine par nom de sous-objet. Utilisé dans la sélection.
cl = dvp.getCenterLine("Edge5")

Supprime un CenterLine cl d'une vue. Ne renvoie rien.
dvp.removeCenterLine(cl)

Attributs de CenterLine
Tag : identifiant unique. Chaîne de caractères. En lecture seule.
Type : 0 - face, 1 - 2 lignes, 2 - 2 points. Entier. En lecture seule.
Mode : 0 - vertical, 1 - horizontal, 2 - aligné. Entier.
Format : attributs d'apparence (style, couleur, poids, visible). Tuple.
HorizShift : décalage gauche/droite. Flottant.
VertShift : décalage haut/bas. Flottant.
Rotation : rotation en degrés. Flottant.
Extension : longueur supplémentaire à ajouter. Flottant.
Flip : inverse l'ordre des points pour une ligne centrale à 2 points. Booléen.
Edges : noms des bords de la source. Liste de chaînes de caractères.
Faces : noms des faces sources. Liste de chaînes de caractères.
Points : noms des points sources (sommets). Liste de chaînes de caractères.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Py CenterLine demo
import FreeCAD
import Part
import TechDraw

start = FreeCAD.Vector (1.0, 5.0, 0.0)   # middle, top
end = FreeCAD.Vector(1.0, -5.0, 0.0)      # middle, bottom
faceNames = ["Face0"]
edgeNames = ["Edge2", "Edge3"]
vertNames = ["Vertex1", "Vertex2"]
vMode = 0   #vertical
hMode = 1   #horizontal
aMode = 2   #aligned
#styles
solid = 1 
dashed = 2
dotted = 3
#weights
weight15 = 0.15
weight75 = 0.75
#colors
pyRed = (1.0, 0.0, 0.0, 0.0)
pyBlue = (0.0, 1.0, 0.0, 0.0)
pyBlack = (0.0, 0.0, 0.0, 0.0)
#adjustments
hShift = 1.0
vShift = 1.0
extend = 4.0
rotate = 30.0
flip = False;

dvp = App.ActiveDocument.View

print("making face CenterLine")
tag = dvp.makeCenterLine(faceNames,vMode)
cline = dvp.getCenterLine(tag)
print("cline tag: {}".format(tag))

#replace
print("making new format")
oldFormat = cline.Format
newFormat = (dotted,oldFormat[1], pyRed, True)
cline.Format = newFormat
cline.Extension = 10.0

print("making edgeCenterLine")
cline2 = dvp.makeCenterLine(edgeNames,hMode)

print("making vertexCenterLine")
cline3 = dvp.makeCenterLine(vertNames,aMode)

print("finished")

Géométrie de DrawViewPart

[topoShapeEdge] = dvp.getVisibleEdges()

[topoShapeEdge] = dvp.getHiddenEdges()

topoShapeEdge = dvp.getEdgeByIndex(i)
topoShapeEdge = dvp.getEdgeBySelection("Edge1")

topoShapeVertex = dvp.getVertexByIndex(i)
topoShapeVertex = dvp.getVertexBySelection("Vertex1")

Redessine le graphique pour cette vue.
dvp.requestPaint()