Adding yarn to a layer to layer interlock

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
ggam
Posts: 4
Joined: Wed Jan 22, 2020 7:47 am

Adding yarn to a layer to layer interlock

Post by ggam »

Hello everyone,
I just started using TexGen and I am also very new to phyton.

I've already created the pattern for the binding yarns of my textile following the examples. I need to add another yarn very close to each binding yarn only on the top and bottom layers. Is that a way to set the position of that yarn using the same input as SetBinderPosition (1,1,0,0 for example) as opposed to the cartesian coordinates?

Image

I've also been looking at the documentation AddXYarn seems good for this case, however, it is not very clear to me what the vector PATTERN3D means.

Code: Select all

#LayerToLayer

nx = 4# number of x (warp & binder) yarns 
ny = 4#number of y (weft) yarns
sx = 1#x (warp / binder) yarn spacing
sy = 1#y (weft) yarn spacing
hx = 0.2#x (warp / binder) yarn heights
hy = 0.2#y ( weft) yarn heights

#number of layers

nweft = 5 #number of weft layers
nwarp = nweft -1 #number of warp layers
nbl = nweft - 2 #number of binder layers

#yarn dimensions and shape
wy = 0.8#width of yarns on y direction(weft)
wb = 0.4#binder yarn width
hb = 0.1#binder yarn heights


#create layer to layer textile
weave = CTextileLayerToLayer(nx,ny,sx,sy,hx,hy,nbl)

#setting ratio of warp to binder yarsn

rwarp = 0 #warp ratio
rbind = 1 #binder yarn ratio

weave.SetWarpRatio (rwarp)
weave.SetBinderRatio (rbind) #If the warp ratio is 0 then all yarns in the x direction will be binders

#setting up the layers
weave.SetupLayers(nwarp,nweft,nbl)

#set yarn dimensions: widths/heights

weave.SetYYarnWidths( wy )
weave.SetBinderYarnWidths( wb )
weave.SetBinderYarnHeights( hb )

#assign the z-positions to the binder yarns
P = [[0,3,2,1],[2,3,0,2],[3,0,2,2],[1,3,1,0]]

for y in xrange(0,nx): 
  offset = 0
  for x in range(0,ny):
    weave.SetBinderPosition(x,y,P[y][offset])
    offset = offset + 1

#Pattern3D = [1,0,0] 
#NewYarn = AddXYarn(1, Pattern3D)  

# Create a new textile to contain the combination pattern
CombiTextile = CTextile()

# Get yarn pattern from the 3D weave
Pattern = weave.GetYarns()

#Add yarns to the combined textile
for Yarn in Pattern:
    CombiTextile.AddYarn(Yarn)

#create the satin yarn
Yarnsatin = CYarn ()

#add nodes to the yarn
Yarnsatin.AddNode(CNode(XYZ(0,0,1)))
Yarnsatin.AddNode(CNode(XYZ(1,0,1)))
Yarnsatin.AddNode(CNode(XYZ(2,0,0)))
Yarnsatin.AddNode(CNode(XYZ(3,0,0)))

# Assign a constant cross-section all along the yarn of elliptical shape
Yarnsatin.AssignSection(CYarnSectionConstant(CSectionEllipse(0.4, 0.1)))

#adding the yarn to the textile
CombiTextile.AddYarn(Yarnsatin)
    
#add textile to database
AddTextile('Textile02',CombiTextile)

Thanks !
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Adding yarn to a layer to layer interlock

Post by louisepb »

Hi,

If you look in the scripting guide https://github.com/louisepb/TexGenScriptingGuide you will see that for the 3D textiles there is a two dimensional array of 'Cells' set up. For the 3D textiles each cell contains a vector of integers (the PATTERN3D is just a typedef for an integer) which describe the yarn at each vertical position in the cell. This can be either PATTERN3D_YYARN, PATTERN3D_XYARN or PATTERN3D_NOYARN which have the values 0,1 and 2 respectively. If you use the AddXYarn or AddYYarn functions the cells will automatically be defined using the vector passed to the function. As each cell in the 2D array contains a vector it essentially forms a 3D array specifying which yarn is at each crossover point. From this TexGen automatically builds the yarns (without you needing to specify coordinates) using the yarn sizes and spacings that you have defined.

I hope that makes some sense! (I think I probably need to improve the documentation!)
Louise
ggam
Posts: 4
Joined: Wed Jan 22, 2020 7:47 am

Re: Adding yarn to a layer to layer interlock

Post by ggam »

Dear Louise, thank you for the quick response!

The documentation says Add yarn of type XYARN or NOYARN parallel to the X axis.

So to add a new yarn just beside the first biding yarn that I have, for example, newyarn = weave.AddXYarn(1,1) where the first value is its grid position iy and the second value is the PATTERN3D_XYARN?

When I do that my program crashes and closes. Is that because the is already a XYarn on that position?

Thanks for the info!
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Adding yarn to a layer to layer interlock

Post by louisepb »

Hi,

I've just taken a closer look at your original script. Are you trying to add an extra yarn to the second textile, CombiTextile, that you've created? If so, you have created this using the CTextile class. This only has information about the yarns with no extra information about their configuration as generated in the weave classes. If you want to add an extra yarn to this then you will need to generate the nodes using x,y,z coordinates. (Having said that TexGen shouldn't crash - I'll investigate that).

You can only use the AddXYarn function for the 3DWeave classes.

Hope that helps,
Louise
ggam
Posts: 4
Joined: Wed Jan 22, 2020 7:47 am

Re: Adding yarn to a layer to layer interlock

Post by ggam »

Hi,
You are right!. I deleted the CombiTextile but TexGen still crashes and closes when I add the Yarn to the weave.

Code: Select all

# LayerToLayer
import sys

sys.path.append("C:/Program Files/TexGen/Python/libxtra")
from TexGen.Core import *

nx = 4  # number of x (warp & binder) yarns
ny = 4  # number of y (weft) yarns
sx = 0.8  # x (warp / binder) yarn spacing
sy = 1  # y (weft) yarn spacing
hx = 0.2  # x (warp / binder) yarn heights
hy = 0.2  # y ( weft) yarn heights

# number of layers

nweft = 4  # number of weft layers
nwarp = nweft - 1  # number of warp layers
nbl = nweft - 2  # number of binder layers

# yarn dimensions and shape
wy = 0.8  # width of yarns on y direction(weft)
wb = 0.4  # binder yarn width
hb = 0.1  # binder yarn heights

# create layer to layer textile
weave = CTextileLayerToLayer(nx, ny, sx, sy, hx, hy, nbl)

# setting ratio of warp to binder yarsn

rwarp = 0  # warp ratio
rbind = 1  # binder yarn ratio

weave.SetWarpRatio(rwarp)
weave.SetBinderRatio(rbind)  # If the warp ratio is 0 then all yarns in the x direction will be binders

# setting up the layers
weave.SetupLayers(nwarp, nweft, nbl)

# set yarn dimensions: widths/heights

weave.SetYYarnWidths(wy)
weave.SetBinderYarnWidths(wb)
weave.SetBinderYarnHeights(hb)

# assign the z-positions to the binder yarns
P = [[3, 1, 0, 3], [2, 0, 2, 3],[0, 1, 0, 2], [2, 3, 2, 0]]

for y in xrange(0, nx):
    offset = 0
    for x in range(0, ny):
        weave.SetBinderPosition(x, y, P[y][offset])
        offset = offset + 1

NewYarn = weave.AddXYarn(1,1)


# add textile to database
AddTextile('Textile02', weave)
I still don't fully understand what arguments AddXYarn takes. Pattern3D, in this case, would be 1 (PATTERN3D_XYARN) to have a yarn parallel to the first binder?

Thank you for your response!

Gabrieal
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Adding yarn to a layer to layer interlock

Post by louisepb »

Hi,
Sorry for the delay in replying - I've been reminding myself how these functions work! I'd forgotten that AddXYarn will add a yarn at the position specified, pushing the PATTERN_3D value into the cell, therefore it's only suitable for use when you're building the layers up initially.

If I understand what you're trying to do, I think that the easiest thing would be for you to create the textile with a warp yarn stack between each binder. The warp yarns would then be built automatically and you would need to delete the middle one an move the upper and lower ones to the same level as the binder yarns. The modified code for this is below.

Code: Select all

# LayerToLayer
import sys

sys.path.append("C:/Program Files/TexGen/Python/libxtra")
from TexGen.Core import *

nx = 8  # number of x (warp & binder) yarns
ny = 4  # number of y (weft) yarns
sx = 0.8  # x (warp / binder) yarn spacing
sy = 1  # y (weft) yarn spacing
hx = 0.2  # x (warp / binder) yarn heights
hy = 0.2  # y ( weft) yarn heights

# number of layers

nweft = 4  # number of weft layers
nwarp = nweft - 1  # number of warp layers
nbl = nweft - 2  # number of binder layers

# yarn dimensions and shape
wy = 0.8  # width of yarns on y direction(weft)
wb = 0.4  # binder yarn width
hb = 0.1  # binder yarn heights

# create layer to layer textile
weave = CTextileLayerToLayer(nx, ny, sx, sy, 0.1, hy, nbl, True)

# setting ratio of warp to binder yarsn

rwarp = 1  # warp ratio
rbind = 1  # binder yarn ratio

weave.SetWarpRatio(rwarp)
weave.SetBinderRatio(rbind)  # If the warp ratio is 0 then all yarns in the x direction will be binders

# setting up the layers
weave.SetupLayers(nwarp, nweft, nbl)

# set yarn dimensions: widths/heights

weave.SetYYarnWidths(wy)
weave.SetWarpYarnWidths(0.4)
weave.SetBinderYarnWidths(wb)
weave.SetBinderYarnHeights(hb)

# assign the z-positions to the binder yarns
P = [[3, 1, 0, 3], [2, 0, 2, 3],[0, 1, 0, 2], [2, 3, 2, 0]]

for y in xrange(0, nx/2):
    offset = 0
    for x in range(0, ny):
        weave.SetBinderPosition(x, y*2+1, P[y][offset])
        offset = offset + 1

#NewYarn = weave.AddXYarn(1,1)


# add textile to database
AddTextile('Textile02', weave)
If you want to do this automatically then you'd need to get the Cell at the appropriate position for each warp yarn crossover and reset the values such that the value at 0 and the maximum cell position is set to PATTERN3D_XYARN and all the rest are set to PATTERN3D_NOYARN.

I hope that makes some sort of sense!
Louise
ggam
Posts: 4
Joined: Wed Jan 22, 2020 7:47 am

Re: Adding yarn to a layer to layer interlock

Post by ggam »

Hello,

As you suggested only left the top and bottom warps. When looping through the yarns in the middle to delete them, I noticed that the index of each yarn changed (after deleting yarn(1), the yarn(2) became yarn(1) for example) so I had to delete the second yarn of each column and loop it for the number of warp layers. Is there a better way to do it?

(hopefully, this is clearer on the code below)

Code: Select all

# LayerToLayer
import sys

sys.path.append("C:/Program Files/TexGen/Python/libxtra")
from TexGen.Core import *

nx = 8  # number of x (warp & binder) yarns
ny = 4  # number of y (weft) yarns
sx = 0.8  # x (warp / binder) yarn spacing
sy = 1  # y (weft) yarn spacing
hx = 0.1  # x (warp / binder) yarn heights
hy = 0.2  # y ( weft) yarn heights

# number of layers

nweft = 16  # number of weft layers
nwarp = nweft - 1  # number of warp layers
nbl = nweft - 2  # number of binder layers

# yarn dimensions and shape
wy = 0.8  # width of yarns on y direction(weft)
wx = 0.4  # width of yarns on x direction(warp)
wb = 0.4  # binder yarn width
hb = 0.1  # binder yarn heights

# create layer to layer textile
weave = CTextileLayerToLayer(nx, ny, sx, sy, hx, hy, nbl)

# setting ratio of warp to binder yarsn

rwarp = 1  # warp ratio
rbind = 1  # binder yarn ratio

weave.SetWarpRatio(rwarp)
weave.SetBinderRatio(rbind)  # If the warp ratio is 0 then all yarns in the x direction will be binders

# setting up the layers
weave.SetupLayers(nwarp, nweft, nbl)

# set yarn dimensions: widths/heights

weave.SetYYarnWidths(wy)
weave.SetWarpYarnWidths(wx)
weave.SetBinderYarnWidths(wb)
weave.SetBinderYarnHeights(hb)

# assign the z-positions to the binder yarns
P = [[0, 2, 3, 2], [3, 2, 0, 2], [2, 0, 2, 3], [2, 3, 2, 0]]

for y in xrange(0, nx / 2):
    offset = 0
    for x in range(0, ny):
        weave.SetBinderPosition(x, y * 2 + 1, P[y][offset])
        offset = offset + 1

# set warp pattern
weave.SwapPosition(0, 0, 1, 0)
weave.SwapPosition(1, 0, 1, 0)
#weave.SwapPosition(2, 0, 1, 0)
#weave.SwapPosition(3, 0, 1, 0)


# delete extra warps
weave.GetYarns()
for i in range(1, 14):
    weave.DeleteYarn(1)

for y in range(1, 14):
    weave.DeleteYarn(17)

for a in range(1, 14):
    weave.DeleteYarn(33)

for u in range(1, 14):
    weave.DeleteYarn(49)

# add textile to database
AddTextile('Textile02', weave)
Also, when swapping the position of the remaining yarns [1 1 0 0] they seem to push the weft as opposed to going on top of it.
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: Adding yarn to a layer to layer interlock

Post by louisepb »

Hi,

The issue of changing indices is really a programming issue rather than a TexGen one. The yarns are stored in a vector and the way that this works is that if an element is deleted then everthing after that is shifted up to fill the space. It is up to the programmer to keep a track of the index.

When deleting multiple elements from a vector it's often easier to delete from the end forward. That way the index of what you need to delete won't have changed. For example, for the first stack of warp yarns you could do

Code: Select all

for i in range(nwarp-2, 0, -1):
    weave.DeleteYarn(i)
For swapping the position remember that it is a vector containing the complete cell which for the warp yarn stack will be something like
[NO_YARN, WEFT, WARP, WEFT, WARP ... WARP, WEFT, NO_YARN] This is populated from the bottom so in order to swap the bottom warp to the no_yarn position you wil need SwapPostion(x,y, 2,0). The code has been written assuming that there won't be a yarn in the bottom position at warp yarn positions (as opposed to binders) so when it builds the textile it may still not have the yarn in the correct vertical position - you may still need to move it.

Hope that helps,
Louise
Post Reply