Draw two boxes, but only can see one

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
johnwang
Veteran
Posts: 1382
Joined: Sun Jan 27, 2019 12:41 am

Draw two boxes, but only can see one

Post by johnwang »

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
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Draw two boxes, but only can see one

Post by mario52 »

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, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
johnwang
Veteran
Posts: 1382
Joined: Sun Jan 27, 2019 12:41 am

Re: Draw two boxes, but only can see one

Post by johnwang »

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
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
Post Reply