Draw two boxes, but only can see one

Need help, or want to share a macro? Post here!
johnwang
Posts: 29
Joined: Sun Jan 27, 2019 12:41 am

Draw two boxes, but only can see one

Postby johnwang » Tue Jan 29, 2019 1:59 am

Hi,

I am using this code to draw many boxes (Set at 2 in code). It created Shape and Shape001 on the list, but I could only see one box.

Is it the same problem as this one (https://forum.freecadweb.org/viewtopic.php?f=22&t=33715) that my code can't find the the second Shape001 to make box?

Thanks for help

Regards,

John

Code: Select all

from FreeCAD import Base
import Part

Vx=[]
Vy=[]
Vz=[]

np=4

Vx.append(0)
Vy.append(10)
Vz.append(0)

Vx.append(30)
Vy.append(10)
Vz.append(0)

Vx.append(30)
Vy.append(-10)
Vz.append(0)

Vx.append(0)
Vy.append(-10)
Vz.append(0)

V=[]
L=[]
E=[]

W=[]
F=[]
P=[]

n=2

for i in range(n):
    for j in range(np):
	    V.append(Base.Vector(Vx[j]+i*100,Vy[j],Vz[j]))

    for j in range(np-1):
	    L.append(Part.LineSegment(V[j],V[j+1]))
    L.append(Part.LineSegment(V[np-1],V[0]))

    for j in range(np):
	    E.append(L[j].toShape())

    W.append(Part.Wire(E))
    F.append(Part.Face(W[i]))

    P.append(F[i].extrude(Base.Vector(0,0,10)))

    Part.show(P[i])
mario52
Posts: 2554
Joined: Wed May 16, 2012 2:13 pm

Re: Draw two boxes, but only can see one

Postby mario52 » Tue Jan 29, 2019 1:06 pm

hi

the 2 shape are in the same position

try this

Code: Select all

from FreeCAD import Base
import Part

Vx=[]
Vy=[]
Vz=[]

np=4

Vx.append(0)
Vy.append(10)
Vz.append(0)

Vx.append(30)
Vy.append(10)
Vz.append(0)

Vx.append(30)
Vy.append(-10)
Vz.append(0)

Vx.append(0)
Vy.append(-10)
Vz.append(0)

V=[]
L=[]
E=[]

W=[]
F=[]
P=[]

n=10

distancex = distancey = distancez = anglex = angley = anglez = 0.0    ##

for i in range(n):

    for j in range(np):
	    V.append(Base.Vector(Vx[j]+i*100,Vy[j],Vz[j]))

    for j in range(np-1):
	    L.append(Part.LineSegment(V[j],V[j+1]))
    L.append(Part.LineSegment(V[np-1],V[0]))

    for j in range(np):
	    E.append(L[j].toShape())

    W.append(Part.Wire(E))
    F.append(Part.Face(W[i]))

    P.append(F[i].extrude(Base.Vector(0,0,10)))

    P[i].Placement.Base.x = distancex    ## choice x placement
    P[i].Placement.Base.y = distancey    ## choice y placement
    P[i].Placement.Base.z = distancez    ## choice z placement
# or    P[i].Placement.Base = (distancex, distancey, distancez)  ## 

    P[i].Placement.Rotation = FreeCAD.Rotation(anglex, angley, anglez)  ## choice placement rotation

    Part.show(P[i])

    distancex += 10.0    ## choice x increment
    distancey += 10.0    ## choice y increment
    distancez += 10.0    ## choice z increment

    anglex += 10.0    ## choice x increment
    angley += 10.0    ## choice y increment
    anglez += 10.0    ## choice z increment


mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
johnwang
Posts: 29
Joined: Sun Jan 27, 2019 12:41 am

Re: Draw two boxes, but only can see one

Postby johnwang » Wed Jan 30, 2019 2:03 am

mario52 wrote:
Tue Jan 29, 2019 1:06 pm

the 2 shape are in the same position
Hi mario,

I use "+i*100 " in V.append(Base.Vector(Vx[j]+i*100,Vy[j],Vz[j])) to try to change position, but seems not work.

I want the boxes in different size.

John