TechDraw API/de: Difference between revisions
(Updating to match new version of source page) |
(Updating to match new version of source page) |
||
Line 74: | Line 74: | ||
===DrawViewPart Cosmetics=== |
===DrawViewPart Cosmetics=== |
||
dvp.makeCosmeticVertex(point) |
|||
====CosmeticVertex (CV) routines accessible from Python==== |
|||
dvp.makeCosmeticLine(start,end,style, weight, pyGreen) |
|||
dvp = App.ActiveDocument.View #CV's belong to views <br> |
|||
dvp.makeCosmeticCircle(center, radius, style, weight, pyRed) |
|||
add a CosmeticVertex at p1 (View coordinates). Returns unique tag.<br> |
|||
tag = dvp.makeCosmeticVertex(vector p1) |
|||
add a CosmeticVertex at p1 (3d model coordinates). Returns unique tag. <br> |
|||
tag = dvp.makeCosmeticVertex3d(vector p1) |
|||
returns CosmeticVertex with unique id.<br> |
|||
cv = dvp.getCosmeticVertex(string id) |
|||
returns CosmeticVertex with name (Vertex6). Used in selections.<br> |
|||
cv = dvp.getCosmeticVertexBySelection(string name) |
|||
replaces CosmeticVertex in View. Returns True/False.<br> |
|||
bool = dvp.replaceCosmeticVertex(object cv) |
|||
remove CosmeticVertex from View. Returns None.<br> |
|||
dvp.removeCosmeticVertex(object cv) |
|||
remove all CosmeticVertices from the View. Returns None.<br> |
|||
dvp.clearCosmeticVertices() |
|||
CosmeticView attributes<br> |
|||
Tag: unique identifier. String.<br> |
|||
Point: location within view. Vector.<br> |
|||
******************************************************************************** |
|||
{{Code|code= |
|||
#!/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)) |
|||
#replace CV |
|||
p2 = App.Vector(4.0, 3.0, 0.0) |
|||
cv.Point = p2 |
|||
v.replaceCosmeticVertex(cv) |
|||
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)) |
|||
}} |
|||
====CosmeticEdge (CE) routines accessible from Python==== |
|||
dvp = App.ActiveDocument.View #CE's belong to views<br> |
|||
Make a CosmeticEdge from p1 to p2(View coordinates). Returns unique tag.<br> |
|||
tag = dvp.makeCosmeticLine(p1, p2) |
|||
Make a CosmeticEdge at center with radius radius(View coordinates). Returns unique tag.<br> |
|||
tag = dvp.makeCosmeticCircle(center, radius) |
|||
Make a CosmeticEdge at center with radius radius(View coordinates) from start angle to end angle. Returns unique tag.<br> |
|||
tag = dvp.makeCosmeticCircleArc(center, radius, start, end) |
|||
returns CosmeticEdge with unique id.<br> |
|||
ce = dvp.getCosmeticEdge(id) |
|||
returns CosmeticEdge by name (Edge25). Used in selections.<br> |
|||
ce = dvp.getCosmeticEdgeBySelection(name) |
|||
replace CosmeticEdge ce in dvp PropertyCosmeticEdgeList. ce.Tag must match an existing tag.<br> |
|||
bool = dvp.replaceCosmeticEdge(ce) |
|||
remove CosmeticEdge ce from View. Returns None.<br> |
|||
dvp.removeCosmeticEdge(ce) |
|||
remove all CosmeticLines from the View. Returns None.<br> |
|||
dvp.clearCosmeticEdges() |
|||
CosmeticEdge attributes<br> |
|||
Tag: unique identifier. String.<br> |
|||
Format: appearance attributes (style, color, weight, visible). Tuple.<br> |
|||
******************************************************************************** |
|||
{{Code|code= |
|||
#!/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) |
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("replacing CE with tag: {}".format(ce.Tag)) |
|||
ce = dvp.getCosmeticEdge(tag) |
|||
rc = dvp.replaceCosmeticEdge(ce) |
|||
print("replace returns: {}".format(rc)) |
|||
print("removing CE with tag: {}".format(tag2)) |
|||
dvp.removeCosmeticEdge(tag2) |
|||
print("finished") |
|||
}} |
|||
====CenterLine (CL) routines accessible from Python==== |
|||
make a new CenterLine<br> |
|||
tag = dvp.makeCenterLine(subObjs, mode)<br> |
|||
retrieve CenterLine with unique tag.<br> |
|||
cl = dvp.getCenterLine(tag) |
|||
retrieve CenterLine by subobject name. Used in selection.<br> |
|||
cl = dvp.getCenterLine("Edge5") |
|||
replace CenterLine cl in dvp PropertyCenterLineList. cl.Tag must match an existing tag.<br> |
|||
bool = dvp.replaceCenterLine(cl) |
|||
remove CenterLine cl from View. Returns None.<br> |
|||
dvp.removeCenterLine(cl) |
|||
CenterLine Attributes<br> |
|||
Tag: unique identifier. String. ReadOnly.<br> |
|||
Type: 0 - face, 1 - 2 line, 2 - 2 point. Integer. ReadOnly.<br> |
|||
Mode: 0 - vert, 1 - horiz, 2 - aligned. Integer.<br> |
|||
Format: appearance attributes (style, color, weight, visible). Tuple.<br> |
|||
HorizShift: left/right offset. Float.<br> |
|||
VertShift: up/down offset. Float.<br> |
|||
Rotation: rotation in degrees. Float.<br> |
|||
Extension: additional length to be added. Float.<br> |
|||
Flip: reverse the order of points for 2 point CenterLine. Boolean.<br> |
|||
Edges: names of source edges. List of string.<br> |
|||
Faces: names of source faces. List of string.<br> |
|||
Points: names of source points (Vertices). List of string.<br> |
|||
******************************************************************************** |
|||
{{Code|code= |
|||
#!/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("replacing CL with tag: {}".format(cline.Tag)) |
|||
rc = dvp.replaceCenterLine(cline) |
|||
print("replace returns: {}".format(rc)) |
|||
print("making edgeCenterLine") |
|||
cline2 = dvp.makeCenterLine(edgeNames,hMode) |
|||
print("making vertexCenterLine") |
|||
cline3 = dvp.makeCenterLine(vertNames,aMode) |
|||
print("finished") |
|||
}} |
|||
===DrawViewPart Geometry=== |
===DrawViewPart Geometry=== |
Revision as of 18:20, 15 December 2019
Diese Funktionen sind Teil des TechDraw-Arbeitsbereichs und können in Makros oder mit dem Python-Interpreter verwendet werden, sobald der TechDraw
-Arbeitsbereich importiert wurde.
Good examples of basic TechDraw scripting can be found in the unit test scripts.
Siehe die TechDrawGui-API für weitere Funktionen.
Beispiel:
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)
Description: Creates wires from edges in input by planar graph traversal. Optionally exclude the OuterWire by setting optional parameter to false.
Returns: List of wires sorted by size (descending)
Description: Finds the OuterWire (largest) of a list of edges (that form a planar graph).
Returns: Outer wire
Description: Project shape in direction and find outer wire of result.
Returns: Outline wire
Description: Return the edges of a DrawViewPart in Dxf format.
Returns: String
Example:
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()
Description: Return the edges of a DrawViewPart in Svg format.
Returns: String
Example:
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()
Example:
import TechDraw
TechDraw.writeDXFView(myPart,myFileName)
Example:
import TechDraw
TechDraw.writeDXFPage(myPage,myFileName)
DrawViewPart Cosmetics
CosmeticVertex (CV) routines accessible from Python
dvp = App.ActiveDocument.View #CV's belong to views
add a CosmeticVertex at p1 (View coordinates). Returns unique tag.
tag = dvp.makeCosmeticVertex(vector p1)
add a CosmeticVertex at p1 (3d model coordinates). Returns unique tag.
tag = dvp.makeCosmeticVertex3d(vector p1)
returns CosmeticVertex with unique id.
cv = dvp.getCosmeticVertex(string id)
returns CosmeticVertex with name (Vertex6). Used in selections.
cv = dvp.getCosmeticVertexBySelection(string name)
replaces CosmeticVertex in View. Returns True/False.
bool = dvp.replaceCosmeticVertex(object cv)
remove CosmeticVertex from View. Returns None.
dvp.removeCosmeticVertex(object cv)
remove all CosmeticVertices from the View. Returns None.
dvp.clearCosmeticVertices()
CosmeticView attributes
Tag: unique identifier. String.
Point: location within view. Vector.
#!/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))
#replace CV
p2 = App.Vector(4.0, 3.0, 0.0)
cv.Point = p2
v.replaceCosmeticVertex(cv)
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))
CosmeticEdge (CE) routines accessible from Python
dvp = App.ActiveDocument.View #CE's belong to views
Make a CosmeticEdge from p1 to p2(View coordinates). Returns unique tag.
tag = dvp.makeCosmeticLine(p1, p2)
Make a CosmeticEdge at center with radius radius(View coordinates). Returns unique tag.
tag = dvp.makeCosmeticCircle(center, radius)
Make a CosmeticEdge at center with radius radius(View coordinates) from start angle to end angle. Returns unique tag.
tag = dvp.makeCosmeticCircleArc(center, radius, start, end)
returns CosmeticEdge with unique id.
ce = dvp.getCosmeticEdge(id)
returns CosmeticEdge by name (Edge25). Used in selections.
ce = dvp.getCosmeticEdgeBySelection(name)
replace CosmeticEdge ce in dvp PropertyCosmeticEdgeList. ce.Tag must match an existing tag.
bool = dvp.replaceCosmeticEdge(ce)
remove CosmeticEdge ce from View. Returns None.
dvp.removeCosmeticEdge(ce)
remove all CosmeticLines from the View. Returns None.
dvp.clearCosmeticEdges()
CosmeticEdge attributes
Tag: unique identifier. String.
Format: appearance attributes (style, color, weight, 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("replacing CE with tag: {}".format(ce.Tag))
ce = dvp.getCosmeticEdge(tag)
rc = dvp.replaceCosmeticEdge(ce)
print("replace returns: {}".format(rc))
print("removing CE with tag: {}".format(tag2))
dvp.removeCosmeticEdge(tag2)
print("finished")
CenterLine (CL) routines accessible from Python
make a new CenterLine
tag = dvp.makeCenterLine(subObjs, mode)
retrieve CenterLine with unique tag.
cl = dvp.getCenterLine(tag)
retrieve CenterLine by subobject name. Used in selection.
cl = dvp.getCenterLine("Edge5")
replace CenterLine cl in dvp PropertyCenterLineList. cl.Tag must match an existing tag.
bool = dvp.replaceCenterLine(cl)
remove CenterLine cl from View. Returns None.
dvp.removeCenterLine(cl)
CenterLine Attributes
Tag: unique identifier. String. ReadOnly.
Type: 0 - face, 1 - 2 line, 2 - 2 point. Integer. ReadOnly.
Mode: 0 - vert, 1 - horiz, 2 - aligned. Integer.
Format: appearance attributes (style, color, weight, visible). Tuple.
HorizShift: left/right offset. Float.
VertShift: up/down offset. Float.
Rotation: rotation in degrees. Float.
Extension: additional length to be added. Float.
Flip: reverse the order of points for 2 point CenterLine. Boolean.
Edges: names of source edges. List of string.
Faces: names of source faces. List of string.
Points: names of source points (Vertices). List of string.
#!/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("replacing CL with tag: {}".format(cline.Tag))
rc = dvp.replaceCenterLine(cline)
print("replace returns: {}".format(rc))
print("making edgeCenterLine")
cline2 = dvp.makeCenterLine(edgeNames,hMode)
print("making vertexCenterLine")
cline3 = dvp.makeCenterLine(vertNames,aMode)
print("finished")
DrawViewPart Geometry
[topoShapeEdge] = dvp.getVisibleEdges()
[topoShapeEdge] = dvp.getHiddenEdges()
- Seiten: Neue Standardvorlage, Neue Vorlagenauswahl
- Ansichten: Neue Ansicht, Neue Projektionsgruppe, Neue Schnittansicht, Neue Detailansicht, Neue Notiz, Neue Draft-Ansicht, Neuer Arch Zeichnungsausschnitt, Tabelle
- Ausschnitte: Ausschnittfenster, Ausschnittfenster hinzufügen, Ausschnittfenster entfernen
- Bemaßungen: Längenbemaßung, Horizontale Längenbemaßung, Vertikale Längenbemaßung, Radiusbemaßung, Durchmesserbemaßung, Winkelbemaßung, Winkelbemaßung m. drei Scheitelpunkten, Bemaßungen verlinken
- Ausschmückung: Schraffur, Geometrische Schraffur, Symbol, Bild, Anzeige ein-/ausschalten
- Dienstprogramme: SVG speichern, DXF speichern
- Zusätzliches: Einstellungen, Import-Export Einstellungen; Schraffur, Liniengruppe, Vorlagen