Trouble using sweep in macro

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
salgerman
Posts: 18
Joined: Sat May 14, 2011 4:10 pm

Trouble using sweep in macro

Post by salgerman »

Newbie, here.

I too am having a hard time sweeping.

To start with, after clicking on Sweep icon and getting the Task tab with the two panels...the "thing" (profile) that I want to sweep is not even listed on the left panel...how come?

Up above, I read that somebody was also starting to believe that the profile must be created in Sketcher, but maybe not...for me, it so happens that the one 'profile' that shows up in the list was created in Sketcher, and the one created with Draft.makeWire() is not listed...is makeWire not eligible? is it not an Edge? Needless to say, I am having difficulty telling wires and edges apart.

I would appreciate some guidance.

Thanks
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Can't get sweep to work.

Post by NormandC »

Attaching your file would allow us to guide you. How did you create your profile? Also, what FreeCAD version are you using? The sweep tool may not work the same between different versions.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Can't get sweep to work.

Post by jmaustpc »

salgerman wrote:I would appreciate some guidance.
Like Norm said
normandc wrote:Also, what FreeCAD version are you using?
Please post your FreeCAD help menus about freecad when asking for help. This is one of those cases where it does make a difference.

What happens is that the FreeCAD code looks at the items in your project and tries to determine which items it could use for a sweep and only shows you "valid" items and sketches that produce "valid" items. What is "valid" depends very much on which version of FreeCAD you are using. Various extra items have been added to the code at different times.

A vertex can only be used as a first or last profile in a sweep, so you must have other profiles as well if you are using a vertex. E.g. you can go from a vertex to a circle.

At one time Draft items caused complications as they were faces in the underlying code not just the edge/wire they displayed as. So a Draft circle was actually a circular face not a circle like Part_Circle which was only a closed edge. Yorik has changed some of this in the latest version so Draft can produce Part objects. I think that is still optional behaviour that is a setting in FreeCAD options... it was last time I looked.

At one time we added some code that extracted a wire from a face in the code so that a user could then select a face and use it as a sweep profile....

Anyway as you can see, answering you gets complicated quickly.

The simple answer is get the latest version (or at least a reasonably recent 0.14) if you want to use sweep to its fullest extent.

If you are on one of the Ubuntu Linux then use the PPA to install a only one day old version of 0.14 (which Norm and Werner have set up)

If you are on Windows go to the web site
http://www.freecadweb.org/
and click on the Windows link under downloads on the home page, which will take you to SourceForge where you can download various versions and pick a recent FreeCAD 0.14 (download a ".msi").

Sweep can be used to create so complicated shapes ........ and hence can be lots of fun! :)

Jim
salgerman
Posts: 18
Joined: Sat May 14, 2011 4:10 pm

Re: Can't get sweep to work.

Post by salgerman »

Hey, guys, thanks for such prompt replies.

I am using the latest stable release:

Version 0.13
Revision 1828
Release Date 2013/01/28
OS Windows 7
Platform 32-bit

On my Windows 7, 64-bit machine.

My session at the console goes something like this:

Code: Select all


# === this is what it appears in the console upon new document creation

# Python 2.6.2 (r262:71600, Jun 22 2009, 21:44:05) [MSC v.1500 32 bit (Intel)] on win32
# Type 'help', 'copyright', 'credits' or 'license' for more information.

import WebGui
from StartPage import StartPage
WebGui.openBrowserHTML(StartPage.handle(),App.getResourceDir() + 'Mod/Start/StartPage/','Start page')
App.newDocument()
App.setActiveDocument("Unnamed")
App.ActiveDocument=App.getDocument("Unnamed")
Gui.ActiveDocument=Gui.getDocument("Unnamed")

# ==== this is what I am pasting into the console and the feedback I am getting 

from FreeCAD import Base, Draft, Part

p1 = Base.Vector(-5.0, -1.5, 0.0)
p2 = Base.Vector( 5.0, -1.5, 0.0)
p3 = Base.Vector( 5.0,  1.5, 0.0)
p4 = Base.Vector(-5.0,  1.5, 0.0)

pts = [p1,p2,p3,p4]
profileWire = Draft.makeWire(pts,closed=True,face=False)

# [Vector (-5, -1.5, 0), Vector (5, -1.5, 0), Vector (5, 1.5, 0), Vector (-5, 1.5, 0)]
# True

p1 = Base.Vector( 0.0, 0.0,  0.0)
p2 = Base.Vector( 0.0, 0.0,  5.0)
p3 = Base.Vector( 0.0, 2.0,  8.0)
p4 = Base.Vector( 0.0, 2.0, 10.0)
p5 = Base.Vector( 0.0, 0.0, 15.0)

pts = [p1,p2,p3,p4, p5]
pathWire = Draft.makeWire(pts,closed=False,face=False)
# [Vector (0, 0, 0), Vector (0, 0, 5), Vector (0, 2, 8), Vector (0, 2, 10), Vector (0, 0, 15)]
# False

conductor = Part.makeSweepSurface(pathWire, profileWire)

#>>>  Traceback (most recent call last):
#>>>    File "<input>", line 1, in <module>
#>>>  TypeError: argument 1 must be Part.TopoShape, not App.FeaturePython

pathWireShape = pathWire.Shape
conductor = Part.makeSweepSurface(pathWireShape, profileWire)

#>>>  Traceback (most recent call last):
#>>>   File "<input>", line 1, in <module>
#>>>  TypeError: argument 2 must be Part.TopoShape, not App.FeaturePython

profileWireShape = profileWire.Shape
conductor = Part.makeSweepSurface(pathWireShape, profileWireShape)

#>>>  Traceback (most recent call last):
#>>>    File "<input>", line 1, in <module>
#>>>  Exception: Spine shape is not an edge

What to do?

Thanks, again for you help.
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Trouble using sweep in macro

Post by NormandC »

salgerman,

I split your request from the original topic in Help about using FreeCAD. Please notice that we created a new forum for help requests concerning use of python scripting. The previous topic was about using the sweep command through the GUI. So your problem is completely different.
salgerman
Posts: 18
Joined: Sat May 14, 2011 4:10 pm

Re: Trouble using sweep in macro

Post by salgerman »

Thanks.

The only reason why I posted in this thread was because, before posting, I did a Search first to make sure my problem hadn't been addressed already; but after reading the post I was still in trouble.

In any case, I would take help in anyway I can get it...script-based or GUI-base...I can always extract the commands after using the GUI, this how I am supplementing my learning FreeCAD, anyway.

Thank you very much for all your assistance.

Germán
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Trouble using sweep in macro

Post by jmaustpc »

Hi salgerman

it does not like this line
pathWire = Draft.makeWire(pts,closed=False,face=False)

rather than using a Draft wire, if you use a Part_wire I think it could work.

You might get somewhere with Part.makePolygon it makes a polygon which is just a wire through the given points if open.

It gets complicated.

According to the help information, Part.makeSweepSurface requires an edge for a path and for a profile. IE a Part edge not a Draft edge and not a wire.

As a matter of interest in the latest FreeCAD 0.14, these Draft items you have made can be swept with the gui. Here is a screen shot.
sweep-in-gui.jpeg
sweep-in-gui.jpeg (58.6 KiB) Viewed 3862 times
here is my FreeCAD help about

OS: Ubuntu 12.04.3 LTS
Platform: 64-bit
Version: 0.14.2754 (Git)
Branch: master
Hash: 8a26361c2bb749a419ad6cad7bf1e4b3cfe162ac
Python version: 2.7.3
Qt version: 4.8.2
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.5.0

Honestly if you want to be able to use sweep, you really need to upgrade to a recent version of FreeCAD 0.14. We have added functionality to sweep since development of 0.13 finished.

Jim
salgerman
Posts: 18
Joined: Sat May 14, 2011 4:10 pm

Re: Trouble using sweep in macro

Post by salgerman »

I tried Part.Wire...no luck.

Downloading FreeCAD 0.14

For the record...that is one confusing thing that I am still trying to understand...why would there be Part.Wire and Draft.Wire? A wire should be a wire should be a wire...anyway...one day....
salgerman
Posts: 18
Joined: Sat May 14, 2011 4:10 pm

Re: Trouble using sweep in macro

Post by salgerman »

Well, I finally got something...and, yes, I am still confused about wires and edges...I guess it does not help that I have been trying a couple of different things and one expects wires and the other edges.

Anyway, here is the code
from FreeCAD import Base, Draft, Part

p1 = Base.Vector(-5.0, -1.5, 0.0)
p2 = Base.Vector( 5.0, -1.5, 0.0)
p3 = Base.Vector( 5.0, 1.5, 0.0)
p4 = Base.Vector(-5.0, 1.5, 0.0)

pts = [p1,p2,p3,p4]

line1=Part.Line(p1,p2)
line2=Part.Line(p2,p3)
line3=Part.Line(p3,p4)
line4=Part.Line(p4,p1)

#-----------------------------------------------
# sprofile = Part.Shape([line1,line2,line3,line4])
# wprofile = Part.Wire(sprofile.Edges)
#-----------------------------------------------
# OR
#-----------------------------------------------
myWire = Draft.makeWire(pts, closed=True, face=False)
myWire.FilletRadius=0.5
myWire.Placement.Base = Base.Vector(0.0,0.0,0.0)

myWireEdges = myWire.Shape.Edges
wprofile = Part.Wire(myWireEdges)
#-----------------------------------------------

p1 = Base.Vector( 0.0, 0.0, 0.0)
p2 = Base.Vector( 0.0, 0.0, 5.0)
p3 = Base.Vector( 0.0, 2.0, 8.0)
p4 = Base.Vector( 0.0, 2.0, 10.0)
p5 = Base.Vector( 0.0, 0.0, 15.0)

pts = [p1,p2,p3,p4, p5]

line1=Part.Line(p1,p2)
line2=Part.Line(p2,p3)
line3=Part.Line(p3,p4)
line4=Part.Line(p4,p5)

spath = Part.Shape([line1,line2,line3,line4])
wpath = Part.Wire(spath.Edges)

sweep = Part.Wire(wpath).makePipeShell([wprofile],True,False)
#sweep = Part.makeSweepSurface(myPathEdge,myProfileEdge)

strand = App.ActiveDocument.addObject("Part::Feature","Sweep")
strand.Shape = sweep

Gui.ActiveDocument.resetEdit()
Gui.ActiveDocument.update()
Gui.SendMsgToActiveView("ViewFit")
Questions:

1.-
If I use Part.Shape with 4 lines for my profile, it ends up rectangular with square corner; so, for now, I seem to be going the long way around using Draft.makeWire and setting its *.FillerRadius afterwards, then I work my way back to a Part.Wire

Is there an easy way to get a round-corner rectangle using Part.Shape or something similar? By easy, I mean by simply specifying a fillet radius and not having to create round corners explicitely.

2.-
For "sweeping", I am presently using what seems a rather convoluted (and obscure?) way:
sweep = Part.Wire(wpath).makePipeShell([wprofile],True,False)
where makePipeShell does not even seem to be well documented...just picked up the line from somewhere in the wiki. The profile and trajectory arguments are supposed to be Wires.

How do I go about using Part.makeSweepSurface which seems to be more elegant but requires and Edge for each argument?

And most importantly, with the little that I figured, an Edge seems to be just a straight line, right? That this mean that makeSweepSarface is always going to be straight too?

Thanks,

Germán
Post Reply