问题
I want to create some points in FreeCAD and have their labels displayed next to them. My final goal is to implement this feature request I placed in OpenFOAM repo.
I tried creating some points in draft workbench and label them with:
App.newDocument("test")
Gui.activateWorkbench("DraftWorkbench")
import Draft
point00=Draft.makePoint(0.0,0.0,0.0)
point00.Label = "0"
point01=Draft.makePoint(1.0,0.0,0.0)
point01.Label = "1"
point03=Draft.makePoint(0.0,1.0,0.0)
point03.Label = "2"
Now from here if I add the code blow:
a=App.ActiveDocument.addObject("App::AnnotationLabel","Annotation")
a.LabelText=["0"]
it will label the first point:
How can I do the same for all of the points I create automatically? my goal is to have some points with labels shown next to them. preferably to have a function which takes x,y,z and label and show the point automatically with the label next to it.
回答1:
One temporary solution is to use text. if vertices
is a list of tuples (xi, yi, zi)
then:
for vertexNum, vertex in enumerate(vertices):
p=Draft.makePoint(vertex[0],vertex[1],vertex[2])
p.Label=str(vertexNum)
Draft.makeText([str(vertexNum)],point=FreeCAD.Vector(vertex[0],vertex[1],vertex[2]))
来源:https://stackoverflow.com/questions/51953163/show-point-labels-next-to-them-in-freecad