Show point labels next to them in FreeCAD

爱⌒轻易说出口 提交于 2019-12-13 03:24:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!