Macro using Draft.upgrade on Part.makeLoft result

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Hexaedron
Posts: 2
Joined: Wed Jun 19, 2019 9:57 am
Location: France

Macro using Draft.upgrade on Part.makeLoft result

Post by Hexaedron »

Hello every one !

I have been using FreeCAD for at least a year as a CAD software for my phd thesis. It is a nice tool to use, and I hope I'll provide something back to the software at the end of my project.

I want to create a 3D volume from given BSplines. I have an external code that create the points of such BSplines. I aim to create many different geometry just by changing the initial points of my Macro. I would need hundreds of geometry, so thought it was best to use macro only.

I was able to :
Create lists of BSplines
Upgrade such lists into "closed wires"
Make 4 lofts from the closed wires.

Now, I would like to upgrade my 4 lofts into a shell, then into a solid.
I can do it in the GUI by selecting the 4 lofts, and then "click" the Draft.Upgrade icon. I repeat this once to obtain the solid.
However, I don't want to do that on my 100s geometries. I would like to continue the Macro below instead.
I would like to add something like:

shell=[loft1,loft2,loft3,loft4]
shell=Draft.upgrade(shell,delete=True)
solide=Draft.upgrade(shell,delte=True)

But it doesn't work that way. I try with loft1-4.Shape, with and without Part.show(loft1-4), with same results. What bothers me is that I don't really now what the upgrade function needs from the loft to upgrade it, since a loft can be many thing, and the upgrade is applying on many objects.

Is there any more documentation on Draft.upgrade than presented here https://wiki.freecadweb.org/Draft_Upgrade ? Has anyone a recommendation for what I am trying to do? Any help appreciated :D

Code: Select all

import Draft
import Part
import FreeCAD
import PartDesign
import PartDesignGui
import Sketcher
from FreeCAD import Base
p0001=Base.Vector( 7.5000E+00,-7.5000E+00, 2.2000E+01)
p0002=Base.Vector(-7.5000E+00,-7.5000E+00, 2.2000E+01)
p0003=Base.Vector( 0.0000E+00,-1.4800E+01, 0.0000E+00)
p0004=Base.Vector( 1.0888E+01,-1.0025E+01, 0.0000E+00)
p0005=Base.Vector( 1.3923E+01, 3.4426E+00, 0.0000E+00)
p0006=Base.Vector( 8.7036E+00, 7.1126E+00, 0.0000E+00)
p0007=Base.Vector(-4.6804E-01, 7.1973E+00, 0.0000E+00)
p0008=Base.Vector(-8.7036E+00, 7.1126E+00, 0.0000E+00)
p0009=Base.Vector(-1.3923E+01, 3.4426E+00, 0.0000E+00)
p0010=Base.Vector(-1.0888E+01,-1.0025E+01, 0.0000E+00)
p0011=Base.Vector( 0.0000E+00,-1.3758E+01, 5.9088E+00)
p0012=Base.Vector( 1.0237E+01,-9.4247E+00, 5.0225E+00)
p0013=Base.Vector( 1.2872E+01, 2.8700E+00, 3.2889E+00)
p0014=Base.Vector( 8.3400E+00, 4.7635E+00, 6.5309E+00)
p0015=Base.Vector(-4.6804E-01, 2.7510E+00, 1.2216E+01)
p0016=Base.Vector(-8.3400E+00, 4.7635E+00, 6.5309E+00)
p0017=Base.Vector(-1.2872E+01, 2.8700E+00, 3.2889E+00)
p0018=Base.Vector(-1.0237E+01,-9.4247E+00, 5.0225E+00)
p0019=Base.Vector( 0.0000E+00,-1.2716E+01, 1.1818E+01)
p0020=Base.Vector( 9.5850E+00,-8.8248E+00, 1.0045E+01)
p0021=Base.Vector( 1.1821E+01, 2.2974E+00, 6.5778E+00)
p0022=Base.Vector( 7.9764E+00, 2.4144E+00, 1.3062E+01)
p0023=Base.Vector(-4.6804E-01, 3.5686E-01, 1.8794E+01)
p0024=Base.Vector(-7.9764E+00, 2.4144E+00, 1.3062E+01)
p0025=Base.Vector(-1.1821E+01, 2.2974E+00, 6.5778E+00)
p0026=Base.Vector(-9.5850E+00,-8.8248E+00, 1.0045E+01)
p0027=Base.Vector( 0.0000E+00,-1.5200E+01, 0.0000E+00)
p0028=Base.Vector( 1.1182E+01,-1.0295E+01, 0.0000E+00)
p0029=Base.Vector( 1.4323E+01, 3.5437E+00, 0.0000E+00)
p0030=Base.Vector( 9.0532E+00, 7.4598E+00, 0.0000E+00)
p0031=Base.Vector(-3.6184E-01, 7.6000E+00, 0.0000E+00)
p0032=Base.Vector(-9.0532E+00, 7.4598E+00, 0.0000E+00)
p0033=Base.Vector(-1.4323E+01, 3.5437E+00, 0.0000E+00)
p0034=Base.Vector(-1.1182E+01,-1.0295E+01, 0.0000E+00)
p0035=Base.Vector( 0.0000E+00,-1.4158E+01, 5.9088E+00)
p0036=Base.Vector( 1.0531E+01,-9.6956E+00, 5.0225E+00)
p0037=Base.Vector( 1.3264E+01, 2.9855E+00, 3.2889E+00)
p0038=Base.Vector( 8.5987E+00, 5.1266E+00, 6.5309E+00)
p0039=Base.Vector(-3.6184E-01, 3.1537E+00, 1.2216E+01)
p0040=Base.Vector(-8.5987E+00, 5.1266E+00, 6.5309E+00)
p0041=Base.Vector(-1.3264E+01, 2.9855E+00, 3.2889E+00)
p0042=Base.Vector(-1.0531E+01,-9.6956E+00, 5.0225E+00)
p0043=Base.Vector( 0.0000E+00,-1.3116E+01, 1.1818E+01)
p0044=Base.Vector( 9.8793E+00,-9.0957E+00, 1.0045E+01)
p0045=Base.Vector( 1.2205E+01, 2.4274E+00, 6.5778E+00)
p0046=Base.Vector( 8.1442E+00, 2.7934E+00, 1.3062E+01)
p0047=Base.Vector(-3.6184E-01, 7.5960E-01, 1.8794E+01)
p0048=Base.Vector(-8.1442E+00, 2.7934E+00, 1.3062E+01)
p0049=Base.Vector(-1.2205E+01, 2.4274E+00, 6.5778E+00)
p0050=Base.Vector(-9.8793E+00,-9.0957E+00, 1.0045E+01)
p0051=Base.Vector( 9.1579E-03,-1.4800E+01, 0.0000E+00)
p0052=Base.Vector( 1.0882E+01,-1.0031E+01, 0.0000E+00)
p0053=Base.Vector( 1.0894E+01,-1.0018E+01, 0.0000E+00)
p0054=Base.Vector( 1.3928E+01, 3.4356E+00, 0.0000E+00)
p0055=Base.Vector( 1.3918E+01, 3.4496E+00, 0.0000E+00)
p0056=Base.Vector( 8.7125E+00, 7.1091E+00, 0.0000E+00)
p0057=Base.Vector( 8.6947E+00, 7.1160E+00, 0.0000E+00)
p0058=Base.Vector(-4.5805E-01, 7.1973E+00, 0.0000E+00)
p0059=Base.Vector(-4.7804E-01, 7.1972E+00, 0.0000E+00)
p0060=Base.Vector(-8.6946E+00, 7.1158E+00, 0.0000E+00)
p0061=Base.Vector(-8.7126E+00, 7.1093E+00, 0.0000E+00)
p0062=Base.Vector(-1.3918E+01, 3.4496E+00, 0.0000E+00)
p0063=Base.Vector(-1.3928E+01, 3.4356E+00, 0.0000E+00)
p0064=Base.Vector(-1.0894E+01,-1.0018E+01, 0.0000E+00)
p0065=Base.Vector(-1.0882E+01,-1.0031E+01, 0.0000E+00)
p0066=Base.Vector(-9.1579E-03,-1.4800E+01, 0.0000E+00)
p0067=Base.Vector( 9.1579E-03,-1.5200E+01, 0.0000E+00)
p0068=Base.Vector( 1.1176E+01,-1.0302E+01, 0.0000E+00)
p0069=Base.Vector( 1.1188E+01,-1.0289E+01, 0.0000E+00)
p0070=Base.Vector( 1.4328E+01, 3.5365E+00, 0.0000E+00)
p0071=Base.Vector( 1.4318E+01, 3.5508E+00, 0.0000E+00)
p0072=Base.Vector( 9.0620E+00, 7.4562E+00, 0.0000E+00)
p0073=Base.Vector( 9.0443E+00, 7.4634E+00, 0.0000E+00)
p0074=Base.Vector(-3.5184E-01, 7.6000E+00, 0.0000E+00)
p0075=Base.Vector(-3.7184E-01, 7.6000E+00, 0.0000E+00)
p0076=Base.Vector(-9.0443E+00, 7.4632E+00, 0.0000E+00)
p0077=Base.Vector(-9.0620E+00, 7.4563E+00, 0.0000E+00)
p0078=Base.Vector(-1.4318E+01, 3.5508E+00, 0.0000E+00)
p0079=Base.Vector(-1.4328E+01, 3.5365E+00, 0.0000E+00)
p0080=Base.Vector(-1.1188E+01,-1.0289E+01, 0.0000E+00)
p0081=Base.Vector(-1.1176E+01,-1.0302E+01, 0.0000E+00)
p0082=Base.Vector(-9.1579E-03,-1.5200E+01, 0.0000E+00)
p0083=Base.Vector( 9.1797E-03,-1.3758E+01, 5.9088E+00)
p0084=Base.Vector( 1.0231E+01,-9.4313E+00, 5.0236E+00)
p0085=Base.Vector( 1.0242E+01,-9.4181E+00, 5.0215E+00)
p0086=Base.Vector( 1.2877E+01, 2.8647E+00, 3.2856E+00)
p0087=Base.Vector( 1.2867E+01, 2.8753E+00, 3.2923E+00)
p0088=Base.Vector( 8.3479E+00, 4.7621E+00, 6.5254E+00)
p0089=Base.Vector( 8.3321E+00, 4.7649E+00, 6.5363E+00)
p0090=Base.Vector(-4.5996E-01, 2.7509E+00, 1.2216E+01)
p0091=Base.Vector(-4.7613E-01, 2.7511E+00, 1.2216E+01)
p0092=Base.Vector(-8.3322E+00, 4.7648E+00, 6.5365E+00)
p0093=Base.Vector(-8.3478E+00, 4.7622E+00, 6.5253E+00)
p0094=Base.Vector(-1.2867E+01, 2.8753E+00, 3.2923E+00)
p0095=Base.Vector(-1.2877E+01, 2.8647E+00, 3.2856E+00)
p0096=Base.Vector(-1.0242E+01,-9.4181E+00, 5.0215E+00)
p0097=Base.Vector(-1.0231E+01,-9.4313E+00, 5.0236E+00)
p0098=Base.Vector(-9.1797E-03,-1.3758E+01, 5.9088E+00)
p0099=Base.Vector( 9.1799E-03,-1.4158E+01, 5.9088E+00)
p0100=Base.Vector( 1.0525E+01,-9.7022E+00, 5.0235E+00)
p0101=Base.Vector( 1.0537E+01,-9.6890E+00, 5.0215E+00)
p0102=Base.Vector( 1.3269E+01, 2.9800E+00, 3.2857E+00)
p0103=Base.Vector( 1.3260E+01, 2.9910E+00, 3.2922E+00)
p0104=Base.Vector( 8.6066E+00, 5.1250E+00, 6.5256E+00)
p0105=Base.Vector( 8.5907E+00, 5.1282E+00, 6.5362E+00)
p0106=Base.Vector(-3.5366E-01, 3.1536E+00, 1.2216E+01)
p0107=Base.Vector(-3.7003E-01, 3.1538E+00, 1.2216E+01)
p0108=Base.Vector(-8.5908E+00, 5.1281E+00, 6.5363E+00)
p0109=Base.Vector(-8.6065E+00, 5.1251E+00, 6.5254E+00)
p0110=Base.Vector(-1.3260E+01, 2.9910E+00, 3.2922E+00)
p0111=Base.Vector(-1.3269E+01, 2.9800E+00, 3.2857E+00)
p0112=Base.Vector(-1.0537E+01,-9.6890E+00, 5.0215E+00)
p0113=Base.Vector(-1.0525E+01,-9.7022E+00, 5.0235E+00)
p0114=Base.Vector(-9.1799E-03,-1.4158E+01, 5.9088E+00)
p0115=Base.Vector( 9.1324E-03,-1.2716E+01, 1.1818E+01)
p0116=Base.Vector( 9.5793E+00,-8.8312E+00, 1.0047E+01)
p0117=Base.Vector( 9.5907E+00,-8.8184E+00, 1.0043E+01)
p0118=Base.Vector( 1.1823E+01, 2.2937E+00, 6.5737E+00)
p0119=Base.Vector( 1.1818E+01, 2.3011E+00, 6.5820E+00)
p0120=Base.Vector( 7.9828E+00, 2.4152E+00, 1.3054E+01)
p0121=Base.Vector( 7.9701E+00, 2.4137E+00, 1.3069E+01)
p0122=Base.Vector(-4.6011E-01, 3.5671E-01, 1.8794E+01)
p0123=Base.Vector(-4.7598E-01, 3.5701E-01, 1.8793E+01)
p0124=Base.Vector(-7.9702E+00, 2.4136E+00, 1.3069E+01)
p0125=Base.Vector(-7.9827E+00, 2.4153E+00, 1.3054E+01)
p0126=Base.Vector(-1.1818E+01, 2.3011E+00, 6.5820E+00)
p0127=Base.Vector(-1.1823E+01, 2.2937E+00, 6.5737E+00)
p0128=Base.Vector(-9.5907E+00,-8.8184E+00, 1.0043E+01)
p0129=Base.Vector(-9.5793E+00,-8.8312E+00, 1.0047E+01)
p0130=Base.Vector(-9.1324E-03,-1.2716E+01, 1.1818E+01)
p0131=Base.Vector( 9.1370E-03,-1.3116E+01, 1.1818E+01)
p0132=Base.Vector( 9.8735E+00,-9.1021E+00, 1.0047E+01)
p0133=Base.Vector( 9.8850E+00,-9.0894E+00, 1.0043E+01)
p0134=Base.Vector( 1.2208E+01, 2.4234E+00, 6.5737E+00)
p0135=Base.Vector( 1.2203E+01, 2.4313E+00, 6.5820E+00)
p0136=Base.Vector( 8.1506E+00, 2.7940E+00, 1.3055E+01)
p0137=Base.Vector( 8.1377E+00, 2.7929E+00, 1.3069E+01)
p0138=Base.Vector(-3.5384E-01, 7.5949E-01, 1.8794E+01)
p0139=Base.Vector(-3.6985E-01, 7.5971E-01, 1.8794E+01)
p0140=Base.Vector(-8.1377E+00, 2.7928E+00, 1.3069E+01)
p0141=Base.Vector(-8.1506E+00, 2.7940E+00, 1.3054E+01)
p0142=Base.Vector(-1.2203E+01, 2.4313E+00, 6.5820E+00)
p0143=Base.Vector(-1.2208E+01, 2.4234E+00, 6.5737E+00)
p0144=Base.Vector(-9.8850E+00,-9.0894E+00, 1.0043E+01)
p0145=Base.Vector(-9.8735E+00,-9.1021E+00, 1.0047E+01)
p0146=Base.Vector(-9.1370E-03,-1.3116E+01, 1.1818E+01)
BS0001=Draft.makeBSpline([p0003,p0051,p0052,p0004])
BS0002=Draft.makeBSpline([p0004,p0053,p0054,p0005])
BS0003=Draft.makeBSpline([p0005,p0055,p0056,p0006])
BS0004=Draft.makeBSpline([p0006,p0057,p0058,p0007])
BS0005=Draft.makeBSpline([p0007,p0059,p0060,p0008])
BS0006=Draft.makeBSpline([p0008,p0061,p0062,p0009])
BS0007=Draft.makeBSpline([p0009,p0063,p0064,p0010])
BS0008=Draft.makeBSpline([p0010,p0065,p0066,p0003])
BS0009=Draft.makeBSpline([p0027,p0067,p0068,p0028])
BS0010=Draft.makeBSpline([p0028,p0069,p0070,p0029])
BS0011=Draft.makeBSpline([p0029,p0071,p0072,p0030])
BS0012=Draft.makeBSpline([p0030,p0073,p0074,p0031])
BS0013=Draft.makeBSpline([p0031,p0075,p0076,p0032])
BS0014=Draft.makeBSpline([p0032,p0077,p0078,p0033])
BS0015=Draft.makeBSpline([p0033,p0079,p0080,p0034])
BS0016=Draft.makeBSpline([p0034,p0081,p0082,p0027])
BS0017=Draft.makeBSpline([p0011,p0083,p0084,p0012])
BS0018=Draft.makeBSpline([p0012,p0085,p0086,p0013])
BS0019=Draft.makeBSpline([p0013,p0087,p0088,p0014])
BS0020=Draft.makeBSpline([p0014,p0089,p0090,p0015])
BS0021=Draft.makeBSpline([p0015,p0091,p0092,p0016])
BS0022=Draft.makeBSpline([p0016,p0093,p0094,p0017])
BS0023=Draft.makeBSpline([p0017,p0095,p0096,p0018])
BS0024=Draft.makeBSpline([p0018,p0097,p0098,p0011])
BS0025=Draft.makeBSpline([p0035,p0099,p0100,p0036])
BS0026=Draft.makeBSpline([p0036,p0101,p0102,p0037])
BS0027=Draft.makeBSpline([p0037,p0103,p0104,p0038])
BS0028=Draft.makeBSpline([p0038,p0105,p0106,p0039])
BS0029=Draft.makeBSpline([p0039,p0107,p0108,p0040])
BS0030=Draft.makeBSpline([p0040,p0109,p0110,p0041])
BS0031=Draft.makeBSpline([p0041,p0111,p0112,p0042])
BS0032=Draft.makeBSpline([p0042,p0113,p0114,p0035])
BS0033=Draft.makeBSpline([p0019,p0115,p0116,p0020])
BS0034=Draft.makeBSpline([p0020,p0117,p0118,p0021])
BS0035=Draft.makeBSpline([p0021,p0119,p0120,p0022])
BS0036=Draft.makeBSpline([p0022,p0121,p0122,p0023])
BS0037=Draft.makeBSpline([p0023,p0123,p0124,p0024])
BS0038=Draft.makeBSpline([p0024,p0125,p0126,p0025])
BS0039=Draft.makeBSpline([p0025,p0127,p0128,p0026])
BS0040=Draft.makeBSpline([p0026,p0129,p0130,p0019])
BS0041=Draft.makeBSpline([p0043,p0131,p0132,p0044])
BS0042=Draft.makeBSpline([p0044,p0133,p0134,p0045])
BS0043=Draft.makeBSpline([p0045,p0135,p0136,p0046])
BS0044=Draft.makeBSpline([p0046,p0137,p0138,p0047])
BS0045=Draft.makeBSpline([p0047,p0139,p0140,p0048])
BS0046=Draft.makeBSpline([p0048,p0141,p0142,p0049])
BS0047=Draft.makeBSpline([p0049,p0143,p0144,p0050])
BS0048=Draft.makeBSpline([p0050,p0145,p0146,p0043])
list_BS_ann_int=[BS0001,BS0002,BS0003,BS0004,BS0005,BS0006,BS0007,BS0008]
list_BS_ann_ext=[BS0009,BS0010,BS0011,BS0012,BS0013,BS0014,BS0015,BS0016]
list_BS_mid_int=[BS0017,BS0018,BS0019,BS0020,BS0021,BS0022,BS0023,BS0024]
list_BS_mid_ext=[BS0025,BS0026,BS0027,BS0028,BS0029,BS0030,BS0031,BS0032]
list_BS_leaf_int=[BS0033,BS0034,BS0035,BS0036,BS0037,BS0038,BS0039,BS0040]
list_BS_leaf_ext=[BS0041,BS0042,BS0043,BS0044,BS0045,BS0046,BS0047,BS0048]
list_BS_ann_int=Draft.upgrade(list_BS_ann_int, delete=True, force='makeWires')
list_BS_ann_ext=Draft.upgrade(list_BS_ann_ext, delete=True, force='makeWires')
list_BS_mid_int=Draft.upgrade(list_BS_mid_int, delete=True, force='makeWires')
list_BS_mid_ext=Draft.upgrade(list_BS_mid_ext, delete=True, force='makeWires')
list_BS_leaf_int=Draft.upgrade(list_BS_leaf_int, delete=True, force='makeWires')
list_BS_leaf_ext=Draft.upgrade(list_BS_leaf_ext, delete=True, force='makeWires')
loft1=Part.makeLoft([list_BS_ann_int[0][0].Shape,list_BS_ann_ext[0][0].Shape] ,False,False,False)
loft2=Part.makeLoft([list_BS_leaf_int[0][0].Shape,list_BS_leaf_ext[0][0].Shape] ,False,False,False)
loft3=Part.makeLoft([list_BS_ann_int[0][0].Shape,list_BS_mid_int[0][0].Shape,list_BS_leaf_int[0][0].Shape] ,False,False,False)
loft4=Part.makeLoft([list_BS_ann_ext[0][0].Shape,list_BS_mid_ext[0][0].Shape,list_BS_leaf_ext[0][0].Shape] ,False,False,False)
OS: Debian GNU/Linux 10 (buster)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16146 (Git)
Build type: Release
Branch: (HEAD detached at 0.18.4)
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.7
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)


PS : it seems that my first Draft.upgrade( Name, delete=True, force='makeWires') could use instead the force='closeWire'. I have tried, but the function fails... Hence my current Macro.
Magic is science we don't understand (yet).
User avatar
Chris_G
Veteran
Posts: 2602
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Macro using Draft.upgrade on Part.makeLoft result

Post by Chris_G »

Hello,
Daft.upgrade needs objects with valid shapes.
The shape creation of objects is sometimes delayed.
So, you need to recompute your document before calling Draft.upgrade :

Code: Select all

FreeCAD.ActiveDocument.recompute()
User avatar
Hexaedron
Posts: 2
Joined: Wed Jun 19, 2019 9:57 am
Location: France

Re: Macro using Draft.upgrade on Part.makeLoft result

Post by Hexaedron »

Hello,

I am taken aback by the delay of my answer. I apologize deeply.

Your answer did help me. Recomputing was necessary. I was able to continue to develop my shape, and now the whole model is ok I think !
Thank you for your time and your help :D
Magic is science we don't understand (yet).
Post Reply