Sketch can not be closed correctly

Need help, or want to share a macro? Post here!
Uriel Rojo Martinez
Posts: 3
Joined: Fri Nov 09, 2018 7:52 pm

Sketch can not be closed correctly

Postby Uriel Rojo Martinez » Wed Jul 29, 2020 10:40 pm

Hello, everyone I'm working in a macro to generate lattice structures, one of the shapes that I'm working is this one: (Tetra-Chiral)
SNAG-0019.png
SNAG-0019.png (122.09 KiB) Viewed 338 times
The macro can adjust the chiral length, radio of circle and weight of shape. I'm in the final steps to get the sketch ready,
SNAG-0018.png
SNAG-0018.png (53.57 KiB) Viewed 338 times
but when I'm trying to close it, the sketch turns in wrong shapes, like this:
SNAG-0020.png
SNAG-0020.png (57.04 KiB) Viewed 338 times

I can't figure out how to close it and get a correct sketch, I am willing to spend time to learn and I would be glad if someone can point me in the right direction.
Thank you for your time.

Code: Select all


import FreeCAD
import Sketcher
import Part

tc_length = 5
tc_width = 1
tc_radius = 1

radius_in = float(tc_radius) - (float(tc_width)/2)
radius_out = float(tc_radius) + (float(tc_width)/2)

ActiveSketch = App.activeDocument().addObject('Sketcher::SketchObject','Sketch')
ActiveSketch = App.ActiveDocument.getObject('Sketch')

ActiveSketch.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000))
ActiveSketch.MapMode = "Deactivated"

ActiveSketch.addGeometry(Part.Point(App.Vector(23.638113,22.152096,0)))
ActiveSketch.addConstraint(Sketcher.Constraint('DistanceX',-1,1,0,1,23.638113)) 
ActiveSketch.setDatum(0,App.Units.Quantity(str(float(tc_length))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('DistanceY',-1,1,0,1,22.152096)) 
ActiveSketch.setDatum(1,App.Units.Quantity(str(float(tc_length))+' mm'))

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(21.940510,7.252213,0),App.Vector(27.177204,6.708781,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(21.841702,5.720726,0),App.Vector(26.979591,4.979685,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(21.693497,4.386851,0),App.Vector(27.127804,3.448199,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(21.644096,2.855366,0),App.Vector(27.078396,1.966115,0)),True)
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',1,5.264816)) 
ActiveSketch.setDatum(2,App.Units.Quantity(str(float(tc_length))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',2,5.191054)) 
ActiveSketch.setDatum(3,App.Units.Quantity(str(float(tc_length))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',3,5.514777)) 
ActiveSketch.setDatum(4,App.Units.Quantity(str(float(tc_length))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',4,5.506576)) 
ActiveSketch.setDatum(5,App.Units.Quantity(str(float(tc_length))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 4, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Horizontal',4)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 3, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',3,1,4,1,3.073972)) 
ActiveSketch.setDatum(9,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 2, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',2,1,3,1,1.226519)) 
ActiveSketch.setDatum(11,App.Units.Quantity('180.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 1, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',1,1,4,1,2.453048)) 
ActiveSketch.setDatum(13,App.Units.Quantity('180.000000 deg'))

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(21.149603,5.411051,0),App.Vector(22.308653,7.066834,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(22.573580,5.146125,0),App.Vector(23.765741,6.835024,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(23.699509,4.848085,0),App.Vector(25.024137,6.735677,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(25.322180,5.113009,0),App.Vector(26.083841,6.536984,0)),True)
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',5,2.021142)) 
ActiveSketch.setDatum(14,App.Units.Quantity(str(float(tc_radius))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',6,2.067275)) 
ActiveSketch.setDatum(15,App.Units.Quantity(str(float(tc_radius))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',7,2.306001)) 
ActiveSketch.setDatum(16,App.Units.Quantity(str(float(tc_radius))+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',8,1.614878)) 
ActiveSketch.setDatum(17,App.Units.Quantity(str(float(tc_radius))+' mm'))

ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 5, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',1,1,5,1,0.645545)) 
ActiveSketch.setDatum(19,App.Units.Quantity('45.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 6, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',5,1,6,1,0.249573)) 
ActiveSketch.setDatum(21,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 7, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',5,1,7,1,0.170041)) 
ActiveSketch.setDatum(23,App.Units.Quantity('180.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 8, 1)) 

ActiveSketch.addConstraint(Sketcher.Constraint('Angle',8,1,6,1,1.325137)) 
ActiveSketch.setDatum(25,App.Units.Quantity('180.000000 deg'))

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(12.243484,5.150989,0),App.Vector(14.463294,8.946864,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(14.552089,4.618234,0),App.Vector(17.215860,8.702685,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(16.683104,4.418450,0),App.Vector(19.058304,7.970148,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(18.547745,4.107677,0),App.Vector(21.255917,7.459592,0)),True)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 6, 2, 9, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 3, 2, 9, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 5, 2, 10, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 1, 2, 10, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 8, 2, 11, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 2, 2, 11, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 7, 2, 12, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 4, 2, 12, 2)) 
ActiveSketch.delConstraint(19)

ActiveSketch.addGeometry(Part.Circle(App.Vector(12.154692,5.350770,0),App.Vector(0,0,1),1.588368),True)
ActiveSketch.addConstraint(Sketcher.Constraint('Radius',13,1.588368)) 
ActiveSketch.setDatum(33,App.Units.Quantity(str(float(tc_radius))+' mm'))

ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 13, 3)) 

ActiveSketch.addConstraint(Sketcher.Constraint('Tangent',13,9)) 
ActiveSketch.setVirtualSpace(33, True)

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(11.911286,6.644384,0),App.Vector(12.710419,6.622186,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(11.911286,6.133828,0),App.Vector(13.087788,6.178224,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 3, 2, 15, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',3,2,15,1,1.520765)) 
ActiveSketch.setDatum(37,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 15, 1, 14, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',14,1,15,1,0.004743)) 
ActiveSketch.setDatum(39,App.Units.Quantity('180.000000 deg'))

ActiveSketch.addConstraint(Sketcher.Constraint('Distance',15,2,9,9.275684)) 
ActiveSketch.setDatum(40,App.Units.Quantity(str(float(tc_width)/2)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',14,2,9,22.301083)) 
ActiveSketch.setDatum(41,App.Units.Quantity(str(float(tc_width)/2)+' mm'))

ActiveSketch.setVirtualSpace(40, True)
ActiveSketch.setVirtualSpace(41, True)
ActiveSketch.setVirtualSpace(37, True)
ActiveSketch.setVirtualSpace(39, True)

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10.507776,4.076612,0),App.Vector(12.129680,4.270049,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10.998811,3.421897,0),App.Vector(12.218960,3.615336,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 2, 2, 16, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',16,1,2,2,1.118869)) 
ActiveSketch.setDatum(43,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 16, 1, 17, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',16,1,17,1,0.386419)) 
ActiveSketch.setDatum(45,App.Units.Quantity('180.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',16,2,11,8.355116)) 
ActiveSketch.setDatum(46,App.Units.Quantity(str(float(tc_width)/2)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',17,2,11,22.685470)) 
ActiveSketch.setDatum(47,App.Units.Quantity(str(float(tc_width)/2)+' mm'))

ActiveSketch.setVirtualSpace(46, True)
ActiveSketch.setVirtualSpace(47, True)
ActiveSketch.setVirtualSpace(45, True)
ActiveSketch.setVirtualSpace(43, True)

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(9.554909,5.873902,0),App.Vector(9.182913,4.623993,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10.894097,5.516786,0),App.Vector(10.075705,4.222237,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 1, 2, 18, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',18,2,1,2,2.420150)) 
ActiveSketch.setDatum(49,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 18, 2, 19, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',19,2,18,2,1.094039)) 
ActiveSketch.setDatum(51,App.Units.Quantity('180.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',19,1,10,7.001580)) 
ActiveSketch.setDatum(52,App.Units.Quantity(str(float(tc_width)/2)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',18,1,10,2.620771)) 
ActiveSketch.setDatum(53,App.Units.Quantity(str(float(tc_width)/2)+' mm'))

ActiveSketch.setVirtualSpace(49, True)
ActiveSketch.setVirtualSpace(51, True)
ActiveSketch.setVirtualSpace(52, True)
ActiveSketch.setVirtualSpace(53, True)

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(8.905710,4.455854,0),App.Vector(9.039629,3.176186,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(9.709224,4.277296,0),App.Vector(9.634823,3.086906,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 4, 2, 20, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',1,1,20,2,0.125384)) 
ActiveSketch.setDatum(55,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 20, 2, 21, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',21,2,20,2,1.473877)) 
ActiveSketch.setDatum(57,App.Units.Quantity('180.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',21,1,12,10.619767)) 
ActiveSketch.setDatum(58,App.Units.Quantity(str(float(tc_width)/2)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',20,1,12,12.541294)) 
ActiveSketch.setDatum(59,App.Units.Quantity(str(float(tc_width)/2)+' mm'))

ActiveSketch.setVirtualSpace(59, True)
ActiveSketch.setVirtualSpace(58, True)
ActiveSketch.setVirtualSpace(57, True)
ActiveSketch.setVirtualSpace(55, True)

ActiveSketch.addGeometry(Part.Circle(App.Vector(8.452773,5.178742,0),App.Vector(0,0,1),1.443580),True)
ActiveSketch.addConstraint(Sketcher.Constraint('Radius',22,1.443580)) 
ActiveSketch.setDatum(60,App.Units.Quantity(radius_out))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 22, 3)) 
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(9.583646,5.297782,0),App.Vector(10.654998,6.696491,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10.312759,4.702586,0),App.Vector(11.503151,6.101296,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(10.640118,3.809793,0),App.Vector(12.232265,5.342422,0)),True)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(11.146033,3.422915,0),App.Vector(12.500103,4.464508,0)),True)
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',23,1.761869)) 
ActiveSketch.setDatum(62,App.Units.Quantity(radius_out))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',24,1.836688)) 
ActiveSketch.setDatum(63,App.Units.Quantity(radius_out))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',25,2.209951)) 
ActiveSketch.setDatum(64,App.Units.Quantity(radius_out))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',26,1.708339)) 
ActiveSketch.setDatum(65,App.Units.Quantity(radius_out))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 26, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',1,1,26,1,0.032547)) 
ActiveSketch.setDatum(67,App.Units.Quantity('45.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 25, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',25,1,26,1,0.045054)) 
ActiveSketch.setDatum(69,App.Units.Quantity('180.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 23, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',26,1,23,1,0.846113)) 
ActiveSketch.setDatum(71,App.Units.Quantity('90.000000 deg'))
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 24, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Angle',24,1,23,1,1.190530)) 
ActiveSketch.setDatum(73,App.Units.Quantity('180.000000 deg'))

ActiveSketch.setVirtualSpace(73, True)
ActiveSketch.setVirtualSpace(71, True)
ActiveSketch.setVirtualSpace(69, True)
ActiveSketch.setVirtualSpace(67, True)
ActiveSketch.setVirtualSpace(62, True)
ActiveSketch.setVirtualSpace(63, True)
ActiveSketch.setVirtualSpace(64, True)
ActiveSketch.setVirtualSpace(65, True)
ActiveSketch.setVirtualSpace(60, True)

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(8.170523,7.778833,0),App.Vector(9.256756,5.963487,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(7.515808,6.886040,0),App.Vector(8.750839,5.174853,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(7.054531,6.335484,0),App.Vector(8.527641,4.386219,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(6.861092,5.517090,0),App.Vector(8.185404,3.880302,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 23, 2, 30, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 14, 2, 30, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 26, 2, 29, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 18, 1, 29, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 16, 2, 28, 2)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 24, 2, 28, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 25, 2, 27, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 21, 1, 27, 2))
 
ActiveSketch.setVirtualSpace(67, False)
ActiveSketch.setVirtualSpace(67, True)
ActiveSketch.setVirtualSpace(67, False)

ActiveSketch.delConstraint(67)
ActiveSketch.addConstraint(Sketcher.Constraint('Tangent',22,30)) 

ActiveSketch.addGeometry(Part.LineSegment(App.Vector(8.584854,6.521563,0),App.Vector(10.526935,4.797472,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(9.813518,7.274614,0),App.Vector(12.449196,5.035278,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(11.775414,7.294431,0),App.Vector(13.757128,5.134363,0)),False)
ActiveSketch.addGeometry(Part.LineSegment(App.Vector(13.281515,7.056625,0),App.Vector(14.767800,5.213631,0)),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 15, 2, 31, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 19, 1, 32, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 17, 2, 33, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 20, 1, 34, 1)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Parallel',30,31)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Parallel',29,32)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Parallel',28,33)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Parallel',34,27)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',31,1.943902)) 
ActiveSketch.setDatum(90,App.Units.Quantity(str((float(tc_length)/3)*1)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',32,6.048099)) 
ActiveSketch.setDatum(91,App.Units.Quantity(str((float(tc_length)/3)*1)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',34,15.475498)) 
ActiveSketch.setDatum(92,App.Units.Quantity(str((float(tc_length)/3)*1)+' mm'))
ActiveSketch.addConstraint(Sketcher.Constraint('Distance',33,5.394029)) 
ActiveSketch.setDatum(93,App.Units.Quantity(str((float(tc_length)/3)*1)+' mm'))

ActiveSketch.delConstraint(90)
ActiveSketch.delConstraint(90)
ActiveSketch.delConstraint(91)
ActiveSketch.delConstraint(90)

ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',31,2,22)) 
ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',34,2,22)) 
ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',33,2,22)) 
ActiveSketch.addConstraint(Sketcher.Constraint('PointOnObject',32,2,22)) 

ActiveSketch.addGeometry(Part.Circle(App.Vector(9.015268,3.755115,0),App.Vector(0,0,1),0.539429),False)
ActiveSketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, 35, 3)) 
ActiveSketch.addConstraint(Sketcher.Constraint('Radius',35,0.539429)) 
ActiveSketch.setDatum(95,App.Units.Quantity(str(radius_in)+' mm'))

App.ActiveDocument.Sketch.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(3.238429,3.572829,0),App.Vector(0,0,1),1.260285),1.141848,1.537306),False)
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',36,2,31,2)) 
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',36,1,29,1)) 
App.ActiveDocument.Sketch.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(2.678770,3.414976,0),App.Vector(0,0,1),0.855130),-3.584613,-2.983830),False)
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',37,2,34,2)) 
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',37,1,30,2)) 
App.ActiveDocument.Sketch.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(3.224078,2.611363,0),App.Vector(0,0,1),0.793802),-1.987235,-1.365322),False)
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',38,2,33,2)) 
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',38,1,27,1)) 
App.ActiveDocument.Sketch.addGeometry(Part.ArcOfCircle(Part.Circle(App.Vector(3.970290,3.214073,0),App.Vector(0,0,1),0.879101),-0.394713,0.196885),False)
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',39,2,32,2)) 
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',39,1,28,1)) 
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Radius',36,1.257777)) 
App.ActiveDocument.Sketch.setDatum(104,App.Units.Quantity(str(radius_out)+' mm'))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Radius',39,0.879101)) 
App.ActiveDocument.Sketch.setDatum(105,App.Units.Quantity(str(radius_out)+' mm'))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Radius',38,0.793802)) 
App.ActiveDocument.Sketch.setDatum(106,App.Units.Quantity(str(radius_out)+' mm'))
App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Radius',37,0.855130)) 
App.ActiveDocument.Sketch.setDatum(107,App.Units.Quantity(str(radius_out)+' mm'))

ActiveSketch.setVirtualSpace(0, True)
ActiveSketch.setVirtualSpace(1, True)
ActiveSketch.setVirtualSpace(2, True)
ActiveSketch.setVirtualSpace(3, True)
ActiveSketch.setVirtualSpace(4, True)
ActiveSketch.setVirtualSpace(5, True)
ActiveSketch.setVirtualSpace(9, True)
ActiveSketch.setVirtualSpace(11, True)
ActiveSketch.setVirtualSpace(13, True)
ActiveSketch.setVirtualSpace(14, True)
ActiveSketch.setVirtualSpace(15, True)
ActiveSketch.setVirtualSpace(16, True)
ActiveSketch.setVirtualSpace(17, True)
ActiveSketch.setVirtualSpace(20, True)
ActiveSketch.setVirtualSpace(22, True)
ActiveSketch.setVirtualSpace(24, True)
ActiveSketch.setVirtualSpace(95, True)

App.ActiveDocument.recompute()

chrisb
Posts: 30875
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketch can not be closed correctly

Postby chrisb » Thu Jul 30, 2020 6:45 am

How about
- placing the center of the arcs in the center of the coordinate system
- make the ends of the arc coincident with the ends of the adjacent straight lines?

This consumes 6 DOF while adding such an arc adds only 5. Thus your Sketch would be overconstrained. You have to remove - or better not generate it - the point-on-object constraint.
If you still get the arc the wrong way round, you can try to switch the sequence of attachments, i.e. swap the ends.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Uriel Rojo Martinez
Posts: 3
Joined: Fri Nov 09, 2018 7:52 pm

Re: Sketch can not be closed correctly

Postby Uriel Rojo Martinez » Thu Jul 30, 2020 5:31 pm

chrisb wrote:
Thu Jul 30, 2020 6:45 am
How about
- placing the center of the arcs in the center of the coordinate system
- make the ends of the arc coincident with the ends of the adjacent straight lines?

This consumes 6 DOF while adding such an arc adds only 5. Thus your Sketch would be overconstrained. You have to remove - or better not generate it - the point-on-object constraint.
If you still get the arc the wrong way round, you can try to switch the sequence of attachments, i.e. swap the ends.
Very helpful, thanks!
ulrich1a
Posts: 1958
Joined: Sun Jul 07, 2013 12:08 pm

Re: Sketch can not be closed correctly

Postby ulrich1a » Thu Jul 30, 2020 8:27 pm

Uriel Rojo Martinez wrote:
Wed Jul 29, 2020 10:40 pm
I'm working in a macro to generate lattice structures
I would not try to generate a sketch in a makro, but generate the profile directly with Part lines and arcs and make a Part wire from it. As you can calculate all vertexes in the macro, you do not need the sketcher solver at all.

Ulrich