Hi, vocx,
Sorry for omitting information about my FreeCAD installation (I went through the important information, and I hope this was my only fault. Please, let me know of any others.)
Here it is:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16117 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: dbb4cc6415bac848a294f03b80f65e888d531742
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Portuguese/Brazil (pt_BR)
I also checked for information on copyObject on the Forum, and I did not see any clear answer to my question.
And in case anyone wants to play with the code, here it is:
Code: Select all
import FreeCAD, FreeCADGui, Part, Sketcher, math
App = FreeCAD
Gui = FreeCADGui
FreeCAD.newDocument("MirrorTest")
#---------------------------------------------------------------------------
# Set sketch vertices
#---------------------------------------------------------------------------
def SetVertices ():
v1 = FreeCAD.Vector(-30, -100.0, 0.0)
v2 = FreeCAD.Vector(40, -70.0, 0.0)
v3 = FreeCAD.Vector(0, 80.0, 0.0)
v4 = FreeCAD.Vector(-60, -70.0, 0.0)
Vertices = ([v1,v2,v3,v4])
return Vertices
#---------------------------------------------------------------------------
# Create original sketch
#---------------------------------------------------------------------------
def DefineSketch (Sketch, Vertices):
Sketch.addGeometry(Part.LineSegment(Vertices[0],Vertices[1]))
Sketch.addGeometry(Part.LineSegment(Vertices[1],Vertices[2]))
Sketch.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1))
Sketch.addGeometry(Part.LineSegment(Vertices[2],Vertices[3]))
Sketch.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1))
Sketch.addGeometry(Part.LineSegment(Vertices[3],Vertices[0]))
Sketch.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1))
Sketch.addConstraint(Sketcher.Constraint('Coincident',3,2,0,1))
#---------------------------------------------------------------------------
# Copy a sketch with translation and rotation
#---------------------------------------------------------------------------
def CopyMoveandRotateSketch (Sketch, Offx=100.0, Offy=100.0, Cx=0.0, Cy=0.0, Rotation=0.0, Axis='Y'):
Copy = App.ActiveDocument.copyObject(Sketch, False)
if Axis == 'X':
rot = FreeCAD.Rotation(FreeCAD.Vector(1,0,0), Rotation)
elif Axis == 'Y':
rot = FreeCAD.Rotation(FreeCAD.Vector(0,1,0), Rotation)
else:
rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,1), Rotation)
center = FreeCAD.Vector(Cx, Cy, 0.0)
newplace = FreeCAD.Placement(FreeCAD.Vector(Offx, Offy,0), rot, center)
Copy.Placement = newplace
return Copy
def CreateSketch (V):
Sketch=FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch')
DefineSketch (Sketch, V)
App.ActiveDocument.recompute()
return Sketch
#---------------------------------------------------------------------------
# Main program
#---------------------------------------------------------------------------
VHB = SetVertices()
Sketch1 = CreateSketch(VHB)
Sketch2 = CopyMoveandRotateSketch (Sketch1, 0.0, 200.0, 0.0, 0.0, 180.0, 'X')
Sketch3 = CopyMoveandRotateSketch (Sketch2, 0.0, 0.0, 0.0, 0.0, -45.0, 'Z')
Sketch1.Label='Sketch1'
Sketch2.Label='Sketch2'
Sketch3.Label='Sketch3'
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
Gui.activeDocument().activeView().viewTop()
As I said, I was expecting Sketch3 to be a rotated copy of Sketch2, not of Sketch1.
Thanks,
Julio