Assigning yarn sections

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
joncrookston
Expert User
Posts: 27
Joined: Wed Apr 11, 2007 4:03 pm
Location: Nottingham, UK

Assigning yarn sections

Post by joncrookston »

Hey all,

I'm trying to do something fairly simple - read a tg3 file, assign a section mesh to the yarns and save the textile. I'm having a bit of a struggle to do this. My approach is:

Code: Select all

from TexGen.Core import *

path = 'c:/'
input = path+'old.tg3'
output = path+'new.tg3'

ReadFromXML(input)
textile = GetTextile()

mesh = CSectionMeshRectangular(2, True)
#textile.AssignSectionMesh(mesh) # I tried this, but no luck

for i in range(textile.GetNumYarns()):
        yarn=textile.GetYarn(i)
        yarnSection = yarn.GetYarnSection()
        section = yarnSection.GetSection() # It fails here
        section.AssignSectionMesh(mesh)

SaveToXML(output)
Does anyone have an idea? My yarn sections are of type CYarnSectionConst, but I can't seem to get hold of the function:

Code: Select all

const CSection &  GetSection () const  
(definition at line 45 of file YarnSectionConstant.h)
to be able to get access to the section itself. I always end up with this error:

Code: Select all

NotImplementedError: Wrong number of arguments for overloaded function 'CYarnSection_GetSection'.
  Possible C/C++ prototypes are:
    GetSection(TexGen::YARN_POSITION_INFORMATION const,int,bool)
    GetSection(TexGen::YARN_POSITION_INFORMATION const,int)
Does anyone have an idea?

In the longer term, if I want to use non-constant sections will I have to assign the section mesh when I create the yarns, or is there some other way around this problem? It seems that AssignSectionMesh() can be used on the textile if it's a CTextileWeave, but mine is a CTextile. Is it this which needs to change?

Cheers,
Jon.
wr
Contributor
Posts: 35
Joined: Tue Aug 28, 2007 8:33 am
Location: Ringkoebing, DK

Post by wr »

I think CTextile should really be virtual.

Why are you not using a CTextileWeave? I.e. change the written tg3 file to contain a CTextileWeave rather than a CTextile?

W
joncrookston
Expert User
Posts: 27
Joined: Wed Apr 11, 2007 4:03 pm
Location: Nottingham, UK

Post by joncrookston »

Yeah, good idea. I was trying to make it work on some existing files, but this could be a workaround.

I tried it and couldn't make it work though. After quite a lot of digging, I think the reason is that there is no code implemented to load a CTextileWeave from XML. The relevant code is in TexGen.cpp:

Code: Select all

00174 bool CTexGen::LoadTiXmlElement(TiXmlElement &Element)
00175 {
00176     bool bOverwrite = false;
00177     FOR_EACH_TIXMLELEMENT(pTextile, Element, "Textile")
00178     {
00179         string Name = pTextile->Attribute("name");
00180         const string* pType = pTextile->Attribute(string("type"));
00181         if (pType)
00182         {
00183             if (*pType == "CTextileWeave2D")
00184                 AddTextile(Name, CTextileWeave2D(*pTextile), bOverwrite);
00185             else if (*pType == "CTextileWeave3D")
00186                 AddTextile(Name, CTextileWeave3D(*pTextile), bOverwrite);
00187             else
00188                 AddTextile(Name, CTextile(*pTextile), bOverwrite);
00189         }
00190     }
00191     return true;
00192 }
Does it make sense to add

Code: Select all

else if (*pType == "CTextileWeave")
    AddTextile(Name, CTextileWeave(*pTextile), bOverwrite);
between lines 186 & 187?

I seem to be having some other problems with CTextileWeave, like not being able to add yarns successfully to the textile (in python) until after using a function which causes the textile to be built. More about that later, when I've got a bit more idea what's causing it.
joncrookston
Expert User
Posts: 27
Joined: Wed Apr 11, 2007 4:03 pm
Location: Nottingham, UK

Post by joncrookston »

I made the change as suggested in my last post and recompiled. Now after loading and 'Get'ing the textile, I definitely have a CTextileWeave as reported by

Code: Select all

print textile.GetType()
However, when I get to

Code: Select all

textile.AssignSectionMesh(mesh)
I get the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Progra~1\Python24\lib\site-packages\TexGen\Core.py", line 2079, in <lambda>
__getattr__ = lambda self, name: _swig_getattr(self, CTextile, name)
File "C:\Progra~1\Python24\lib\site-packages\TexGen\Core.py", line 34, in _swig_getattr
raise AttributeError,name
AttributeError: AssignSectionMesh
Line 2079 of Core.py is in the class definition for CTextile, rather than CTextileWeave. Could this be a swig issue or something else?

Any suggestions gratefully received.

Cheers,
Jon.
Post Reply