how to get the coordinates of nodes which belong last yarn

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
LijunGu
Regular
Posts: 30
Joined: Mon Jun 01, 2020 4:49 am

how to get the coordinates of nodes which belong last yarn

Post by LijunGu »

Hello Dr. Louise,

Tried to search the answer in the forum, unfortunately failed.

Background is that i want to create a new yarn based on the nodes of last yarn. So i want to get the coordinates of those nodes.

Things like:

# Script recorded by TexGen v3.12.0
AddTextile('test', CTextile())

yarn = CYarn()
yarn.AddNode(CNode(XYZ(0, 0, 0)))
yarn.AddNode(CNode(XYZ(2.5, 0, 0)))
yarn.AddNode(CNode(XYZ(5, 0, 0)))
yarn.AddNode(CNode(XYZ(7.5, 0, 0)))
yarn.AddNode(CNode(XYZ(10, 0, 0)))
GetTextile('test').AddYarn(yarn)

yarnsection = CYarnSectionInterpNode( bool(1), bool(0), bool(1))
section = CSectionEllipse(1, 0.2)
yarnsection.AddSection(section)
section = CSectionEllipse(1, 0.2)
yarnsection.AddSection(section)
section = CSectionEllipse(1, 0.2)
yarnsection.AddSection(section)
section = CSectionEllipse(1, 0.2)
yarnsection.AddSection(section)
section = CSectionEllipse(1, 0.2)
yarnsection.AddSection(section)
textile = GetTextile('test')
textile.GetYarn(0).AssignSection(yarnsection)

interpolation = CInterpolationBezier(bool(1))
textile = GetTextile('test')
textile.GetYarn(0).AssignInterpolation(interpolation)

domain = CDomainPlanes()
domain.AddPlane(PLANE(XYZ(1, 0, 0), 0))
domain.AddPlane(PLANE(XYZ(-1, 0, 0), -10))
domain.AddPlane(PLANE(XYZ(0, 1, 0), -5))
domain.AddPlane(PLANE(XYZ(0, -1, 0), -5))
domain.AddPlane(PLANE(XYZ(0, 0, 1), -5))
domain.AddPlane(PLANE(XYZ(0, 0, -1), -5))
GetTextile('test').AssignDomain(domain)
GetRenderWindow('test').RenderDomain('test')
GetRenderWindow('test').RemoveNodes()
GetRenderWindow('test').RemovePaths()

TempYarn_node_1=yarn.GetNode(-5)

TempYarnNode1_coor=GetPosition(TempYarn_node_1)
TempYarnNode1_x=TempYarnNode1_coor[0]
TempYarnNode1_y=TempYarnNode1_coor[1]
TempYarnNode1_z=TempYarnNode1_coor[2]

When i tried to print variable 'TempYarnNode1_x', showing error, please check the attached file.

thank you and have a nice day!

Best regards!
Attachments
error.JPG
error.JPG (16.24 KiB) Viewed 7066 times
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: how to get the coordinates of nodes which belong last ya

Post by louisepb »

Hi,

It looks like you have created a yarn in the user interface and recorded the script. If you want to duplicate the yarn in the GUI you can select the yarn in the main window or in the Outliner window and then select the Duplicate Yarn option in the Outliner window. This will create an exact duplicate of the yarn so you may need to select it in the Outliner window to be able to move it, either using the arrows or by entering a new position in the Modeller tab of the Controls window. Alternatively you can select the individual nodes and see the positions in the Modeller tab.

If you want to get the positions using the Python console you will need to first get the textile, yarn and then the nodes using the Python API functions. You may find the scripting guide useful https://github.com/louisepb/TexGenScriptingGuide

Hope that helps,
Louise
LijunGu
Regular
Posts: 30
Joined: Mon Jun 01, 2020 4:49 am

Re: how to get the coordinates of nodes which belong last ya

Post by LijunGu »

Hello Dr. Louise,

Thank you for your feedback.

It works after checked the section 2.3 of the scripting guide.

Should be like this,for example:

N1=XYZ(xi,yi,zi)
coor_x=N1.x

Have a nice day!

Best regards!
LijunGu
Regular
Posts: 30
Joined: Mon Jun 01, 2020 4:49 am

Re: how to get the coordinates of nodes which belong last ya

Post by LijunGu »

Hello Dr. Louise,

Again for this question. My script look like this:

loop 1:
# yarn 0
for i in range(2): # i means warp direction, 2 warps
for j in range(6): # j means number of master nodes along warp direction
if i-1<0:
N[j]=XYZ(dx*j,0,0)
yarn.AddNode(CNode(N[j]))
textile.AddYarn(yarn)

loop 2:
# yarn 1
for i in range(2):
for j in range(6):
if i-1==0:
# Node_coor=GetPosition(N[i-1][j]) # failed!
# Node_coor=Yarn[0].GetPosition(N[i-1][j]) #failed!
# Node_coor=textile.Yarn[0].GetPosition(N[i-1][j]) #failed!
# Node_coor=CNode.GetPosition(N[i-1][j]) #failed!
N[j]=XYZ(dx*j,0,Node_coor.z)
yarn.AddNode(CNode(N[j]))
textile.AddYarn(yarn)

Loop 3, loop 4...

For loop 2, I want to create the nodes based on the loop 1 which means nodes of yarn 0.

How can i get the coordinates of yarn 0?

Have a nice day for all of you in your team!
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: how to get the coordinates of nodes which belong last ya

Post by louisepb »

Hello,

The simplest way would be to create a different array for your second loop so that you still have the array from the first and use that.

Failing that, you are almost there in the sections that you have marked as failed but you need to use the yarn.GetNode function to get the nodes and then you can do a node.GetPosition to get the XYZ coordinate.

Hope that helps,
Louise
Post Reply