且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 FreeCAD 中在它们旁边显示点标签

更新时间:2023-11-24 09:05:28

一种临时解决方案是使用文本.如果 vertices 是一个元组列表 (xi, yi, zi) 那么:

for vertexNum, enumerate(vertices) 中的顶点:p=Draft.makePoint(顶点[0],顶点[1],顶点[2])p.Label=str(vertexNum)Draft.makeText([str(vertexNum)],point=FreeCAD.Vector(vertex[0],vertex[1],vertex[2]))

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.

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]))