I assume you are having this issue inside RoboFont
roboFab in RoboFont generate all objects on the fly / on request from the defcon data
so if you ask a contour for his points it will generate a list of Point objects, next them you request the same list, the point objects will be different objects (with the same reference defcon data)
why: a object wrapper can not contain any data
good luck!
"""
g = CurrentGlyph()
for con in g:
# cache the list localy
points = con.points
# loop over the cached list
for p in points:
if p.selected:
print p
print points
# ask the cached list for the index of the point object
print points.index(p)
"""
> Hi all,
> Is there anything wrong here?
> I'm still trying to delete points from a script and while digging found this happening:
> ################################
> g = CurrentGlyph()
> for con in g:
> for p in con.points:
> if p.selected:
> print p
> print con.points
> print con.points.index℗
> <Point x:240 y:736>
> [<Point x:370.0 y:493.245283127>, <Point x:453.0 y:595.245283127>, <Point x:240 y:736>, <Point x:27.0 y:595.245283127>, <Point x:110.0 y:493.0>, <Point x:240.0 y:592.0>]
> Traceback (most recent call last):
> File "<untitled>", line 8, in <module>
> ValueError: <Point x:240 y:736> is not in list
> ################################
> Any idea?
> Thanks as usual,
> Joancarles
> - - - - - - - - - - -
> Joancarles Casasín
> un senyor de lletres i de cičncies que passava per aquí
> www.casasin.com
> -- > You received this message because you are subscribed to the Google Groups "RoboFab" group.
> To post to this group, send email to robofab@googlegroups.com
> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
> Messages from newly joined members are subject to moderation.
> Download RoboFab and documentation at http://robofab.com
But as I understand, that means that I can pop or remove an element from the list but this doesn't affect the glyph.
I mean I'm removing the point from the list but not from the glyph itself.
All I want is to delete the currently selected points in a glyph.
Cheers,
jca
PD: The same happens within FontLab
El 25/06/2012, a les 14:22, Frederik Berlaen va escriure:
> I assume you are having this issue inside RoboFont
> roboFab in RoboFont generate all objects on the fly / on request from the defcon data
> so if you ask a contour for his points it will generate a list of Point objects, next them you request the same list, the point objects will be different objects (with the same reference defcon data)
> why: a object wrapper can not contain any data
> good luck!
> """
> g = CurrentGlyph()
> for con in g:
> # cache the list localy
> points = con.points
> # loop over the cached list
> for p in points:
> if p.selected:
> print p
> print points
> # ask the cached list for the index of the point object
> print points.index(p)
> """
- - - - - - - - - - -
Joancarles Casasín
un senyor de lletres i de cičncies que passava per aquí
www.casasin.com
On Jun 25, 2012, at 9:05 AM, Joancarles Casasín wrote:
> But as I understand, that means that I can pop or remove an element from the list but this doesn't affect the glyph.
> I mean I'm removing the point from the list but not from the glyph itself.
That's generally not advisable in RoboFab. The various lists that you are presented with are almost never tied to the raw objects that they wrap. (This is a long, complex story. Short version: many of the list-like objects that represent iterable data structures are illusions. Creating lists that respond to pop, del and so on was not something that we were able to achieve way back in the day.) The best way to remove things is with object.removeFoo(i) and so on.
El 25/06/2012, a les 15:12, Tal Leming va escriure:
> On Jun 25, 2012, at 9:05 AM, Joancarles Casasín wrote:
>> But as I understand, that means that I can pop or remove an element from the list but this doesn't affect the glyph.
>> I mean I'm removing the point from the list but not from the glyph itself.
> That's generally not advisable in RoboFab. The various lists that you are presented with are almost never tied to the raw objects that they wrap. (This is a long, complex story. Short version: many of the list-like objects that represent iterable data structures are illusions. Creating lists that respond to pop, del and so on was not something that we were able to achieve way back in the day.) The best way to remove things is with object.removeFoo(i) and so on.
Sure, that was my first attempt.
contour.removeSegment(i) is my first choice.
Now trying to manage how to deal with it : )
Thanks!
jca
- - - - - - - - - - -
Joancarles Casasín
un senyor de lletres i de cičncies que passava per aquí
www.casasin.com
A few weeks ago the removing of contours/segments of a glyph had been talked about. I think I understood the explanation why it didn't work but not how to solve it.
# My script with which I'm trying to remove all contours/segments of certain glyphs
from robofab.world import AllFonts
fonts = AllFonts()
removeContent = ['Eth', 'i.dot']
for f in fonts:
for g in removeContent:
if f[g]:
glyph = f[g]
for contour in glyph:
for segment in contour:
contour.removeSegment(segment.index)
f.update()
# The error
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "/Applications/robofab/RoboFab/Lib/robofab/objects/objectsFL.py", line 1854, in removeSegment
segment = self.segments[index]
IndexError: list index out of range
I'd be grateful for any pointer that explains what I'm doing wrong?
Thanks,
Martin
On Jun 25, 2012, at 16:41 , Joancarles Casasín wrote:
> El 25/06/2012, a les 15:12, Tal Leming va escriure:
>> On Jun 25, 2012, at 9:05 AM, Joancarles Casasín wrote:
>>> But as I understand, that means that I can pop or remove an element from the list but this doesn't affect the glyph.
>>> I mean I'm removing the point from the list but not from the glyph itself.
>> That's generally not advisable in RoboFab. The various lists that you are presented with are almost never tied to the raw objects that they wrap. (This is a long, complex story. Short version: many of the list-like objects that represent iterable data structures are illusions. Creating lists that respond to pop, del and so on was not something that we were able to achieve way back in the day.) The best way to remove things is with object.removeFoo(i) and so on.
> Sure, that was my first attempt.
> contour.removeSegment(i) is my first choice.
> Now trying to manage how to deal with it : )
> Thanks!
> jca
> - - - - - - - - - - -
> Joancarles Casasín
> un senyor de lletres i de cičncies que passava per aquí
> www.casasin.com
> -- > You received this message because you are subscribed to the Google Groups "RoboFab" group.
> To post to this group, send email to robofab@googlegroups.com
> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
> Messages from newly joined members are subject to moderation.
> Download RoboFab and documentation at http://robofab.com
I think the problem is that you are trying to modify the contour while you are iterating over it. This is a safer way to do it:
...
for contour in glyph:
toRemove = []
for segment in contour:
toRemove.append(segment.index)
toRemove.reverse()
for index in toRemove:
contour.removeSegment(index)
...
There's still a likelihood that this will raise a traceback when it gets to the last segment of a contour. If you are trying to remove all content from a glyph, the clear method is the best way to go:
> A few weeks ago the removing of contours/segments of a glyph had been talked about. I think I understood the explanation why it didn't work but not how to solve it.
> # My script with which I'm trying to remove all contours/segments of certain glyphs
> from robofab.world import AllFonts
> fonts = AllFonts()
> removeContent = ['Eth', 'i.dot']
> for f in fonts:
> for g in removeContent:
> if f[g]:
> glyph = f[g]
> for contour in glyph:
> for segment in contour:
> contour.removeSegment(segment.index)
> f.update()
> # The error
> Traceback (most recent call last):
> File "<string>", line 11, in <module>
> File "/Applications/robofab/RoboFab/Lib/robofab/objects/objectsFL.py", line 1854, in removeSegment
> segment = self.segments[index]
> IndexError: list index out of range
> I'd be grateful for any pointer that explains what I'm doing wrong?
> Thanks,
> Martin
> On Jun 25, 2012, at 16:41 , Joancarles Casasín wrote:
>> El 25/06/2012, a les 15:12, Tal Leming va escriure:
>>> On Jun 25, 2012, at 9:05 AM, Joancarles Casasín wrote:
>>>> But as I understand, that means that I can pop or remove an element from the list but this doesn't affect the glyph.
>>>> I mean I'm removing the point from the list but not from the glyph itself.
>>> That's generally not advisable in RoboFab. The various lists that you are presented with are almost never tied to the raw objects that they wrap. (This is a long, complex story. Short version: many of the list-like objects that represent iterable data structures are illusions. Creating lists that respond to pop, del and so on was not something that we were able to achieve way back in the day.) The best way to remove things is with object.removeFoo(i) and so on.
>> Sure, that was my first attempt.
>> contour.removeSegment(i) is my first choice.
>> Now trying to manage how to deal with it : )
>> Thanks!
>> jca
>> - - - - - - - - - - -
>> Joancarles Casasín
>> un senyor de lletres i de cičncies que passava per aquí
>> www.casasin.com
>> -- >> You received this message because you are subscribed to the Google Groups "RoboFab" group.
>> To post to this group, send email to robofab@googlegroups.com
>> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
>> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
>> Messages from newly joined members are subject to moderation.
>> Download RoboFab and documentation at http://robofab.com
> - - - Communication and Type Design:
> - - - http://www.MartinPlus.com > - - - The Foundry with Typefaces by MartinPlus:
> - - - http://www.MartinPlusFonts.com > phone +49 (0)30 88 72 79 70
> mobile +49 (0)15 20 35 45 006
> -- > You received this message because you are subscribed to the Google Groups "RoboFab" group.
> To post to this group, send email to robofab@googlegroups.com
> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
> Messages from newly joined members are subject to moderation.
> Download RoboFab and documentation at http://robofab.com
> I think the problem is that you are trying to modify the contour while you are iterating over it. This is a safer way to do it:
> ...
> for contour in glyph:
> toRemove = []
> for segment in contour:
> toRemove.append(segment.index)
> toRemove.reverse()
> for index in toRemove:
> contour.removeSegment(index)
> ...
> There's still a likelihood that this will raise a traceback when it gets to the last segment of a contour. If you are trying to remove all content from a glyph, the clear method is the best way to go:
> for f in fonts:
> for g in removeContent:
> f[g].clear()
> f.update()
> ###
> Tal
> On Aug 5, 2012, at 12:47 PM, Martin Wenzel wrote:
>> Hi everybody,
>> A few weeks ago the removing of contours/segments of a glyph had been talked about. I think I understood the explanation why it didn't work but not how to solve it.
>> # My script with which I'm trying to remove all contours/segments of certain glyphs
>> from robofab.world import AllFonts
>> fonts = AllFonts()
>> removeContent = ['Eth', 'i.dot']
>> for f in fonts:
>> for g in removeContent:
>> if f[g]:
>> glyph = f[g]
>> for contour in glyph:
>> for segment in contour:
>> contour.removeSegment(segment.index)
>> f.update()
>> # The error
>> Traceback (most recent call last):
>> File "<string>", line 11, in <module>
>> File "/Applications/robofab/RoboFab/Lib/robofab/objects/objectsFL.py", line 1854, in removeSegment
>> segment = self.segments[index]
>> IndexError: list index out of range
>> I'd be grateful for any pointer that explains what I'm doing wrong?
>> Thanks,
>> Martin
>> On Jun 25, 2012, at 16:41 , Joancarles Casasín wrote:
>>> El 25/06/2012, a les 15:12, Tal Leming va escriure:
>>>> On Jun 25, 2012, at 9:05 AM, Joancarles Casasín wrote:
>>>>> But as I understand, that means that I can pop or remove an element from the list but this doesn't affect the glyph.
>>>>> I mean I'm removing the point from the list but not from the glyph itself.
>>>> That's generally not advisable in RoboFab. The various lists that you are presented with are almost never tied to the raw objects that they wrap. (This is a long, complex story. Short version: many of the list-like objects that represent iterable data structures are illusions. Creating lists that respond to pop, del and so on was not something that we were able to achieve way back in the day.) The best way to remove things is with object.removeFoo(i) and so on.
>>> Sure, that was my first attempt.
>>> contour.removeSegment(i) is my first choice.
>>> Now trying to manage how to deal with it : )
>>> Thanks!
>>> jca
>>> - - - - - - - - - - -
>>> Joancarles Casasín
>>> un senyor de lletres i de cičncies que passava per aquí
>>> www.casasin.com
>>> -- >>> You received this message because you are subscribed to the Google Groups "RoboFab" group.
>>> To post to this group, send email to robofab@googlegroups.com
>>> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
>>> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
>>> Messages from newly joined members are subject to moderation.
>>> Download RoboFab and documentation at http://robofab.com
>> - - - Communication and Type Design:
>> - - - http://www.MartinPlus.com >> - - - The Foundry with Typefaces by MartinPlus:
>> - - - http://www.MartinPlusFonts.com >> phone +49 (0)30 88 72 79 70
>> mobile +49 (0)15 20 35 45 006
>> -- >> You received this message because you are subscribed to the Google Groups "RoboFab" group.
>> To post to this group, send email to robofab@googlegroups.com
>> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
>> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
>> Messages from newly joined members are subject to moderation.
>> Download RoboFab and documentation at http://robofab.com
> -- > You received this message because you are subscribed to the Google Groups "RoboFab" group.
> To post to this group, send email to robofab@googlegroups.com
> To unsubscribe from this group, send email to robofab-unsubscribe@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
> Messages from newly joined members are subject to moderation.
> Download RoboFab and documentation at http://robofab.com