Sweep of face with hole: not working

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
manues
Posts: 11
Joined: Fri Nov 23, 2018 12:34 pm

Re: Sweep of face with hole: not working

Post by manues »

Hi,

thanks a lot for these last, most useful, inputs.

I have made a clean, commented version, which I share here. For me everything is fine now.

I just discovered an interesting swiping behavior, if going along non orthogonal intersections, where the profile cross-section starts to rotate out. But this has nothing to do with scripting I guess, but is just the general swiping behavior (not sure how this can be influenced). Below you will see the output of the provided code.

Thanks again.

Code: Select all


import os

import FreeCAD
import FreeCADGui
from FreeCAD import Vector, Rotation, Placement

import Draft
import Sketcher
import Part

DOC = FreeCAD.newDocument()

#*********************************************************
#Create the body "Construction" containing the profiles  ******************
sweepBody = DOC.addObject("PartDesign::Body", "Construction")

#*********************************************************
#Define the path "wire_01", along which the sweep will be perfomed. ********
#Defind the path corners
p1 = Vector(0, 0, 0)
p2 = Vector(1000, 1000, 0)
p3 = Vector(2000, 0, 0)
p4 = Vector(2000, 1000, 1000)
p5= Vector(2000, 0, 1000)
p6= Vector(0,0, 500)
p7= Vector(1000,1000, 500)
#Construct the wire
wire_01 = Draft.make_wire([p1, p2, p3,p4,p5,p6,p7], closed=False)
#Add the wire to the scope of the body, by adding it to its group property
sweepBody.addObject(wire_01) 

#*********************************************************
#Define sketch "xsection_01", which will be sweeped ********************
#Define the coners of an outer and innter rectangle, forming the profile face
# ... Outer rectangle corners
pp1 = Vector(-50, 50, 0)
pp2 = Vector(50, 50, 0)
pp3 = Vector(50, -50, 0)
pp4 = Vector(-50, -50, 0) 
# ... Inner rectangle corners
ppp1 = Vector(-30, 30, 0)
ppp2 = Vector(30, 30, 0)
ppp3 = Vector(30, -30, 0)
ppp4 = Vector(-30, -30, 0)
#Define the sketch object
xsection_01 = sweepBody.newObject("Sketcher::SketchObject", "X-section_01")
#Add the line segments of hte outer rectangle
xsection_01.addGeometry(Part.LineSegment(pp1,pp2), False) 
xsection_01.addGeometry(Part.LineSegment(pp2,pp3), False)
xsection_01.addGeometry(Part.LineSegment(pp3,pp4), False)
xsection_01.addGeometry(Part.LineSegment(pp4,pp1), False)
# ... connect its corner points
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 0,2,1,1))
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 1,2,2,1))
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 2,2,3,1))
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 3,2,0,1))
#Add the line segments of hte inner rectangle
xsection_01.addGeometry(Part.LineSegment(ppp1,ppp2), False) 
xsection_01.addGeometry(Part.LineSegment(ppp2,ppp3), False)
xsection_01.addGeometry(Part.LineSegment(ppp3,ppp4), False)
xsection_01.addGeometry(Part.LineSegment(ppp4,ppp1), False)
# ... connect its corner points
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 4,2,5,1))
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 5,2,6,1))
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 6,2,7,1))
xsection_01.addConstraint(Sketcher.Constraint("Coincident", 7,2,4,1))
# place and rotate the sketch to be at the beginning of wire_01 and normal to its first segment
xsection_01.Placement = Placement(Vector(0,0,0), Rotation(45, 90, 0))
xsection_01.recompute()

#*********************************************************
#Create the sweep Object, which is of "AdditivePipe" type
#Add sweep object to the containing Body "Construction"
sweepObject_01 = sweepBody.newObject("PartDesign::AdditivePipe", "Profile_01") 
#Define the spine (path along which the swipe is performed)
sweepObject_01.Spine = wire_01
#Define the profile to be swiped
sweepObject_01.Profile = xsection_01
#Defines how the profile cross-section behaves in corners, options are:
#"Transformed": no turning of cross-section, 
#"Right corner": cross-section remains in the sweep direction with sharp corners
#"Round corner": cross-section remains in the sweep direction with round corners
sweepObject_01.Transition = u"Right corner"

DOC.recompute()

The result is a follows:

Swipe along non orthogonal path
Swipe along non orthogonal path
nonOrthogonalPath.png (11.26 KiB) Viewed 248 times
manues
Posts: 11
Joined: Fri Nov 23, 2018 12:34 pm

Re: Sweep of face with hole: not working

Post by manues »

... when thinking about it, the rotation of the cross-section is probably a pure geometrical consequence. Otherwise the corners would not match.
Post Reply