1

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:

enter image description here

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 that takes x,y,z and label and show the point automatically with the label next to it.

P.S. A summary of this effort can be found in this GitHub Gist.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • 1
    hi, you might create a special python feature object with all required properties. Then write a routine in `execute` method define your visualization logic ``` my_point = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', name) – zhukovgreen Aug 21 '18 at 17:01
  • What problems did you find while trying to write such a function? – Stop harming Monica Aug 21 '18 at 17:01
  • @ArtemZhukov would you please elaborate? – Foad S. Farimani Aug 21 '18 at 17:02
  • @Goyo I can only label one point. when I try to label the next it removes the first label. – Foad S. Farimani Aug 21 '18 at 17:03
  • It might be a bug in FreeCAD or that you are doing it wrong. Hard to tell without looking at your actual code. – Stop harming Monica Aug 21 '18 at 17:08
  • @Goyo it doesn't have to be the way I did it. Any other solution which labels the points would do. – Foad S. Farimani Aug 21 '18 at 17:11
  • 1
    Sorry for scatered reply, not enough time:) I was suggesting to create a separate python feature object which will realize your custom logic. Something like here: ``` my_point = FreeCAD.ActiveDocument.addObject('Part::FeaturePython', name) MyPoint(my_point) class MyPoint(object): def __init__(self, obj): """Initialize properties.""" obj.addProperty("App::AnnotationLabel","Y") obj.addProperty("App::AnnotationLabel","Y") obj.addProperty("App::AnnotationLabel","Z") ``` – zhukovgreen Aug 21 '18 at 17:11
  • 1
    Then add a view provider to it and create a Factory which creates your points in any coordinate – zhukovgreen Aug 21 '18 at 17:13
  • @ArtemZhukov thanks for the suggestions. I will try to understand this, but in any case if you had some time to post it in a response it would be highly appreciated. – Foad S. Farimani Aug 21 '18 at 17:14

1 Answers1

0

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]))
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193