Thanks. I apply expression, but it did not work.

when i apply it in model, it did not give me an error but when i move circle, it gives me this error:

Code: Select all

```
import Sketcher
import FreeCAD
import FreeCADGui as Gui
import Part
import Draft
font_size = 1500
XMIN = -1000
YMIN = -2000
XMAX = 10000
YMAX = 20000
o = 500
l = 1000
r = 1500
y1 = YMAX + o
y2 = y1 + 2 * l
y3 = y2 + l
y4 = y3 + l
yc = y4 + r
no_of_edge_in_on_axis = 4
# x_grid_group.addObject(x_sketch)
def create_x_grid(sketch, xcoord, text, i):
g = Part.makeLine(FreeCAD.Vector(xcoord, YMIN, 0), FreeCAD.Vector(xcoord, YMAX, 0))
Part.show(g)
# x_grid_group.addObject(g0)
g1 = sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(xcoord, y1, 0), FreeCAD.Vector(xcoord, y2, 0)))
g2 = sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(xcoord, y2, 0), FreeCAD.Vector(xcoord, y3, 0)))
g3 = sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(xcoord, y3, 0), FreeCAD.Vector(xcoord, y4, 0)))
g4 = sketch.addGeometry(Part.Circle(App.Vector(xcoord, yc, 0), App.Vector(0, 0, 1), r), False)
t = Draft.makeText(text) # , App.Vector(xcoord, yc - font_size / 3, 0))
t.ViewObject.FontSize = font_size
t.ViewObject.Justification = 'Center'
t.setExpression('.Placement.Base', f'{sketch.Name}.Geometry[{i}].Location')
# x_grid_group.addObject(t)
sketch.addConstraint(Sketcher.Constraint('DistanceX', g1, 1, xcoord))
sketch.addConstraint(Sketcher.Constraint('DistanceY', g1, 1, y1))
sketch.addConstraint(Sketcher.Constraint('Coincident', g1, 2, g2, 1))
sketch.addConstraint(Sketcher.Constraint('Coincident', g2, 2, g3, 1))
sketch.addConstraint(Sketcher.Constraint('Vertical', g1))
sketch.addConstraint(Sketcher.Constraint('Vertical', g3))
sketch.addConstraint(Sketcher.Constraint('Radius', g4, r))
sketch.addConstraint(Sketcher.Constraint('PointOnObject', g3, 2, g4))
sketch.addConstraint(Sketcher.Constraint('Perpendicular', g4, g3))
def create_grids(coords, texts, sketch, direction='x'):
if direction == 'x':
# x_circles_vertex_numbers = []
i = no_of_edge_in_on_axis - 1
for coord, text in zip(coords, texts):
# x_circles_vertex_numbers.append(i * 7)
create_x_grid(sketch, coord, text, i)
i += no_of_edge_in_on_axis
elif direction == 'y':
# y_circles_vertex_numbers = []
i = no_of_edge_in_on_axis - 1
for coord, text in zip(coords, texts):
# y_circles_vertex_numbers.append(i * 7)
create_x_grid(sketch, coord, text, i)
i += no_of_edge_in_on_axis
doc.recompute()
doc = App.newDocument("grid")
# x_grid_group = doc.addObject("App::DocumentObjectGroup", "x_grid")
x_sketch = doc.addObject('Sketcher::SketchObject', 'x_sketch')
create_grids([0, 500, 5000], ['A', 'B', 'C'], x_sketch)
# sketch.addConstraint(Sketcher.Constraint('Coincident',i+3,2,i+4,1))
```