Draft.downgrade and upgrade in python is not working

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
freecc
Posts: 158
Joined: Wed Feb 21, 2018 4:17 pm

Draft.downgrade and upgrade in python is not working

Post by freecc »

I am trying to use these commands on two 2D wires. I want to cut or fuse. I get these messages:

Code: Select all

No more downgrade possible
and:

Code: Select all

Unable to upgrade these objects.
The wires show in the document and I can use both commands in the GUI with the buttons for downgrade and upgrade. It creates two faces and in the other case one wire disappears. This is not what I want but one step at a time. Why doesn't it work in python?

Code: Select all

wireList=[W,W1]
wd=Draft.downgrade(wireList)
I have tried experimenting with the other variables in downgrade() to no avail
User avatar
brst
Posts: 87
Joined: Thu Apr 18, 2019 10:11 am
Location: Germany

Re: Draft.downgrade and upgrade in python is not working

Post by brst »

I am also facing that problem right now. :)
Did you find a solution in the meantime?

Greetings brst
FreeCAD rookie
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Draft.downgrade and upgrade in python is not working

Post by vocx »

freecc wrote: Sun Apr 15, 2018 9:02 am ...

The wires show in the document and I can use both commands in the GUI with the buttons for downgrade and upgrade. It creates two faces and in the other case one wire disappears. This is not what I want but one step at a time. Why doesn't it work in python?
...
Upgrade and downgrade accept a parameter to control exactly what type of operations are done, see Draft_Upgrade#Scripting, Draft_Downgrade#Scripting.

Code: Select all

addList, deleteList = Draft.upgrade(objects, delete=False, force=None)

# If force is given, it is the internal function to call to force a certain way of upgrading. It can be: "makeCompound", "closeGroupWires", "makeSolid", "closeWire", "turnToParts", "makeFusion", "makeShell", "makeFaces", "draftify", "joinFaces", "makeSketchFace", "makeWires", or "turnToLine".

Code: Select all

addList, deleteList = Draft.downgrade(objects, delete=False, force=None)

# If force is given, it is the internal function to call to force a certain way of downgrading. It can be: "explode", "shapify", "subtr", "splitFaces", "cut2", "getWire", or "splitWires".
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Mark81
Posts: 121
Joined: Tue Jul 12, 2022 2:21 pm

Re: Draft.downgrade and upgrade in python is not working

Post by Mark81 »

Have you ever find a solution?
I'm facing the same problem: from GUI the downgrade works fine (without any force argument), but when executed in my script it just tells "No more downgrade possible". Here my script:

Code: Select all

c = Part.makeCircle(radius, p, tg)
f = Part.Face(Part.Wire(c))
section = target.section(f)
Part.show(section)
doc.recompute() # not sure if it's needed
obj, foo = Draft.downgrade(section, delete=True)
Both obj and foo lists are empty.
The weird thing is if I send the very same command using the Python console, i.e.:

Code: Select all

Draft.downgrade(App.ActiveDocument.getObject('MyShape'))
it still works.
What should I do in my script in order to get downgrade to work?
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Draft.downgrade and upgrade in python is not working

Post by Chris_G »

Draft.downgrade needs a Document object.
You are passing a shape.
fixed code example :

Code: Select all

c = Part.makeCircle(radius, p, tg)
f = Part.Face(Part.Wire(c))
section = target.section(f)  # section is a shape
section_obj = Part.show(section)  # section_obj is a document object built from the shape
doc.recompute() # not sure if it's needed
obj, foo = Draft.downgrade(section_obj, delete=True)
Mark81
Posts: 121
Joined: Tue Jul 12, 2022 2:21 pm

Re: Draft.downgrade and upgrade in python is not working

Post by Mark81 »

Yeah, it works, thanks!
I RTFM but it wasn't clear enough to me it requires a Document object:
objects: Part::Feature or list
A single object to downgrade or a list
containing various such objects.
Post Reply