why 1pyramid?(2)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
mrrclb48z
Posts: 54
Joined: Wed Feb 07, 2018 11:20 am

why 1pyramid?(2)

Post by mrrclb48z »

I want
2pyramid, Solid Only, DWire* Delete 

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
import Part
import DraftTools
import Draft

def fcPyramid(x,y,b,h):
       x1=x
       y1=y
       z1=0
       x2=x+b
       y2=y
       z2=0
       x3=x+b
       y3=y+b
       z3=0
       x4=x
       y4=y+b
       z4=0
       x5=x+b*.5
       y5=y+b*.5
       z5=h

       points=[FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2),FreeCAD.Vector(x3,y3,z3),FreeCAD.Vector(x4,y4,z4)]
       Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2),FreeCAD.Vector(x5,y5,z5)]
       Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x2,y2,z2),FreeCAD.Vector(x3,y3,z3),FreeCAD.Vector(x5,y5,z5)]
       Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x3,y3,z3),FreeCAD.Vector(x4,y4,z4),FreeCAD.Vector(x5,y5,z5)]
       Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x4,y4,z4),FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x5,y5,z5)]
       Draft.makeWire(points,closed=True,face=True,support=None)
       myWedgei='myPyramid_x' + str(x) + 'y' + str(y)
       App.activeDocument().addObject("Part::MultiFuse",myWedgei)
       App.activeDocument().Fusion.Shapes = [App.activeDocument().DWire,App.activeDocument().DWire001,App.activeDocument().DWire002,App.activeDocument().DWire003,App.activeDocument().DWire004]
       App.ActiveDocument.recompute()
#
b=1
h=1
fcPyramid(0,0,b,h)
fcPyramid(2,0,b,h)
#
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: why 1pyramid?(2)

Post by Chris_G »

mrrclb48z wrote: Sat Apr 07, 2018 2:14 pm why 1pyramid?
because you are always creating your fusion on the same objects (DWire, DWire001, etc ...) :

Code: Select all

App.activeDocument().Fusion.Shapes = [App.activeDocument().DWire ... DWire001 ... 
So, when you call your pyramid function the 1st time :
- you create objects DWire to DWire004
- you build your pyramid on objects DWire to DWire004
until now, that seems to work fine.

But on the second call to pyramid :
- you create objects DWire005 to DWire009
- you build your pyramid on objects DWire to DWire004 again !!!

You should assign your DWires to variables :

Code: Select all

w1 = Draft.makeWire(...)
and use these variables in your fusion :

Code: Select all

fuse.Shapes = [w1, w2, w3, w4, w5]
Here is your full script corrected :

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD
import Part
import DraftTools
import Draft

def fcPyramid(x,y,b,h):
       x1=x
       y1=y
       z1=0
       x2=x+b
       y2=y
       z2=0
       x3=x+b
       y3=y+b
       z3=0
       x4=x
       y4=y+b
       z4=0
       x5=x+b*.5
       y5=y+b*.5
       z5=h

       points=[FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2),FreeCAD.Vector(x3,y3,z3),FreeCAD.Vector(x4,y4,z4)]
       w1 = Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x2,y2,z2),FreeCAD.Vector(x5,y5,z5)]
       w2 = Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x2,y2,z2),FreeCAD.Vector(x3,y3,z3),FreeCAD.Vector(x5,y5,z5)]
       w3 = Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x3,y3,z3),FreeCAD.Vector(x4,y4,z4),FreeCAD.Vector(x5,y5,z5)]
       w4 = Draft.makeWire(points,closed=True,face=True,support=None)
       points=[FreeCAD.Vector(x4,y4,z4),FreeCAD.Vector(x1,y1,z1),FreeCAD.Vector(x5,y5,z5)]
       w5 = Draft.makeWire(points,closed=True,face=True,support=None)
       myWedgei='myPyramid_x' + str(x) + 'y' + str(y)
       fuse = App.activeDocument().addObject("Part::MultiFuse",myWedgei)
       fuse.Shapes = [w1, w2, w3, w4, w5]
       App.ActiveDocument.recompute()
#
b=1
h=1
fcPyramid(0,0,b,h)
fcPyramid(2,0,b,h)
#
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")

mrrclb48z
Posts: 54
Joined: Wed Feb 07, 2018 11:20 am

Re: why 1pyramid?(2)

Post by mrrclb48z »

Thank you
Post Reply