creating revolve using python

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
kunal_shgkr
Posts: 9
Joined: Tue Feb 05, 2019 6:40 am

creating revolve using python

Post by kunal_shgkr »

My intention is to create a bend using revolve between two faces using this program. For revolve, I have created a profile which is a line on one of the edge and axis which is parallel to both faces.

Code: Select all

if indexofface1 == -1 or indexofface2 == -1:continue



RevolveAxis = RevolveAxisList[indexofface1]

LineRevolve = LinesRevolveList[indexofface1]

angle = FinalAngleList[indexofface1]

FreeCAD.ActiveDocument.addObject("Part::Revolution","Revolve")

FreeCAD.ActiveDocument.Revolve.Source = LineRevolve

revolve_axis_unit_vector = RevolveAxisDirList[indexofface1]



axispt = [0.0,0.0,0.0]

axispt[0] = revolve_axis_unit_vector[0]

axispt[1] = revolve_axis_unit_vector[1]

axispt[2] = revolve_axis_unit_vector[2]



FreeCAD.ActiveDocument.Revolve.Axis = (axispt[0],axispt[1],axispt[2])

FreeCAD.ActiveDocument.Revolve.Base = (1.43,40.24,-2)

FreeCAD.ActiveDocument.Revolve.Angle = angle

FreeCAD.ActiveDocument.Revolve.Solid = False

FreeCAD.ActiveDocument.Revolve.AxisLink = (LineRevolve, "Edge1")

FreeCAD.ActiveDocument.Revolve.Symmetric = False

FreeCADGui.ActiveDocument.Line.Visibility = False

FreeCADGui.ActiveDocument.recompute()

except:

print("Exception in RevolveFaces")
The code works fine till Revolve.Solid but once it reaches Revolve.AxisLink it throws this error.

Error -->

Code: Select all

<Exception> type of first element in tuple must be 'DocumentObject', not NoneType
https://imgur.com/hjiXw6O profile and axis for revolve
https://imgur.com/EPoSuLN this is how it looks because of error
https://imgur.com/rou0FGS this is how it is supposed to look

I've attached the FreeCAD file and the content from the report view.
It stops at 3.5(refer report view file) and throws error
Attachments
rev.FCStd
(6.91 KiB) Downloaded 14 times
report view.txt
(8.39 KiB) Downloaded 17 times
Last edited by kunal_shgkr on Mon Nov 29, 2021 6:53 am, edited 4 times in total.
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: creating revolve using python

Post by Chris_G »

Every time you add an object to the document by script, you must recompute the doc if you want to access it immediately.

Code: Select all

revolve = FreeCAD.ActiveDocument.addObject("Part::Revolution","Revolve")
FreeCAD.ActiveDocument.recompute()
revolve.Source = LineRevolve
...
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: creating revolve using python

Post by TheMarkster »

You can attach your images directly here instead of another hosting site. It is better because we can see them here without need to click to some other site. And when that hosting site deletes them after some time they are gone where if they are here they will be here when someone else searches and finds this posting. Easiest way is to drag and drop directly to the form where you type your message.

You should also attach the freecad file you are working on so that if someone has a suggest he can test it before offering it.

Chris already has offered a suggestion, which might fix the problem. Let us know if that worked or not.
kunal_shgkr
Posts: 9
Joined: Tue Feb 05, 2019 6:40 am

Re: creating revolve using python

Post by kunal_shgkr »

Chris_G wrote: Fri Nov 19, 2021 2:44 pm Every time you add an object to the document by script, you must recompute the doc if you want to access it immediately.

Code: Select all

revolve = FreeCAD.ActiveDocument.addObject("Part::Revolution","Revolve")
FreeCAD.ActiveDocument.recompute()
revolve.Source = LineRevolve
...
Thank you for suggestion. If I understand it correctly I've to add FreeCAD.ActiveDocument.recompute() everytime I call an Object. By the way I've written this code in a seprate python file and opened and ran the file in FreeCAD.
kunal_shgkr
Posts: 9
Joined: Tue Feb 05, 2019 6:40 am

Re: creating revolve using python

Post by kunal_shgkr »

TheMarkster wrote: Fri Nov 19, 2021 4:12 pm You can attach your images directly here instead of another hosting site. It is better because we can see them here without need to click to some other site. And when that hosting site deletes them after some time they are gone where if they are here they will be here when someone else searches and finds this posting. Easiest way is to drag and drop directly to the form where you type your message.

You should also attach the freecad file you are working on so that if someone has a suggest he can test it before offering it.

Chris already has offered a suggestion, which might fix the problem. Let us know if that worked or not.
I attached the images but they were not showing properly so I decided to to do this. Anyway I'll keep that in mind. As far as FreeCAD file is considered since this is just a snippet of code which generates a bend by using revolve command and the whole code generates CAD model. The main problem is that I can't share the whole code as this part of my company's project. Everything is working just fine but I got stuck at this step and even after googling whole day I couldn't find a solution therefore I posted here for help.
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: creating revolve using python

Post by Chris_G »

kunal_shgkr wrote: Fri Nov 19, 2021 4:49 pm Thank you for suggestion. If I understand it correctly I've to add FreeCAD.ActiveDocument.recompute() everytime I call an Object. By the way I've written this code in a seprate python file and opened and ran the file in FreeCAD.
I mean, every-time you create an object in the document with myObj = aDocument.addObject()
kunal_shgkr
Posts: 9
Joined: Tue Feb 05, 2019 6:40 am

Re: creating revolve using python

Post by kunal_shgkr »

Chris_G wrote: Fri Nov 19, 2021 10:01 pm
kunal_shgkr wrote: Fri Nov 19, 2021 4:49 pm Thank you for suggestion. If I understand it correctly I've to add FreeCAD.ActiveDocument.recompute() everytime I call an Object. By the way I've written this code in a seprate python file and opened and ran the file in FreeCAD.
I mean, every-time you create an object in the document with myObj = aDocument.addObject()
Thanks for the reply but it is still giving me the same error.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: creating revolve using python

Post by TheMarkster »

If you cannot add your company file perhaps you can create a new simplified file showing only the error and a snippet of (almost) working code for further analysis.
kunal_shgkr
Posts: 9
Joined: Tue Feb 05, 2019 6:40 am

Re: creating revolve using python

Post by kunal_shgkr »

TheMarkster wrote: Sat Nov 20, 2021 4:06 am If you cannot add your company file perhaps you can create a new simplified file showing only the error and a snippet of (almost) working code for further analysis.
Yep I can do that
kunal_shgkr
Posts: 9
Joined: Tue Feb 05, 2019 6:40 am

Re: creating revolve using python

Post by kunal_shgkr »

TheMarkster wrote: Sat Nov 20, 2021 4:06 am If you cannot add your company file perhaps you can create a new simplified file showing only the error and a snippet of (almost) working code for further analysis.
Sorry for replying this late. I've attached the FreeCAD file and the content from the report view.
It stops at 3.5 and throws the following error

Code: Select all

<Exception> type of first element in tuple must be 'DocumentObject', not NoneType 
Kindly look into it.
Attachments
revolve py code.txt
(2.12 KiB) Downloaded 41 times
rev.FCStd
(6.91 KiB) Downloaded 20 times
report view.txt
(8.39 KiB) Downloaded 23 times
Post Reply