Select all points between two selected points

89 views
Skip to first unread message

Josh

unread,
Apr 24, 2014, 1:24:45 PM4/24/14
to rob...@googlegroups.com
When working with textured outlines, It would be helpful to select a range of points in-between two selected points. For instance, you may have a virtually straight line that you need to select and move. However, this line if broken up by many points creating the rough texture. It becomes tedious to select each point along this path in order to modify it. It'd be great if you could just select the begining point and the ending point and run a script to select all the points between them. 

with my limited python and RoboFab knowledge I was unable to get very far. My problem is not knowing how to reference points that aren't selected.

the beginning of my script:

from robofab.world import CurrentGlyph

glyph = CurrentGlyph()

selectedPoints = []

for contour in glyph.contours:
    if contour.selected:
        for point in contour.points:
            if point.selected:
                selectedPoints.append(point)

This builds a list of the selected points.

[<RPoint for unnamed_font.N[1][2]>, <RPoint for unnamed_font.N[1][14]>]

What I need to do is get the range between these two points (…N[1][3], …N[1][4], …N[1][5], …N[1][6], etc…) and add these to the list then do:

for i in selectedPoints:
  i.select(state=True)

I just don't know how to get those un-selected points.

Any help would be much appreciated.

Josh

Josh

unread,
Apr 24, 2014, 1:29:05 PM4/24/14
to rob...@googlegroups.com
Working in FontLab

Josh

unread,
Apr 25, 2014, 11:44:31 AM4/25/14
to rob...@googlegroups.com
I figured it out! I switched to using bPoints rather than points because you can acess the index number of bPoints which is what I needed.

my code:

# FLM: Select between points
from robofab.world import CurrentGlyph

glyph = CurrentGlyph()

selectedPoints = []

for contour in glyph.contours:
    if contour.selected:
        for point in contour.bPoints:
            if point.selected:
                selectedPoints.append(point)
if len(selectedPoints) > 0:
    fl.SetUndo()
    
allPoints = []
pointIndexes = []
for i in selectedPoints:
pointIndexes.append(i.index)

pt1 = min(pointIndexes)
pt2 = max(pointIndexes)

for contour in glyph.contours:
    if contour.selected:
        for point in contour.bPoints:
      allPoints.append(point)

for point in allPoints:
if point.index in range(pt1, pt2):
selectedPoints.append(point)

for i in selectedPoints:
i.select(state=True)

glyph.update()



It allows you to select one or more beginning/ending points and it will select all the points in-between. It's most helpful on diagonal stems where a rectangular marque takes too many passes to get all the points selected.



If anyone has a way to improve on the code please let me know.

Mark Simonson

unread,
Apr 25, 2014, 12:20:10 PM4/25/14
to rob...@googlegroups.com
Neat. 

The only flaw I can see is that, if the start point is between the two selected points, it selects the set of points that don't include the start point, which may not always be what you want. It may seldom be the case in actual use (start points are usually not placed in the middle of a diagonal section), but it's possible.

Mark

--
--
You received this message because you are subscribed to the Google Groups "RoboFab" group.
To post to this group, send email to rob...@googlegroups.com
To unsubscribe from this group, send email to robofab-u...@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 unsubscribe from this group and stop receiving emails from it, send an email to robofab+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh

unread,
Apr 25, 2014, 12:22:42 PM4/25/14
to rob...@googlegroups.com
Yeah, I did run into that. I just move the start point in that case.

Mark Simonson

unread,
Apr 25, 2014, 12:34:04 PM4/25/14
to rob...@googlegroups.com
I was going to add: It doesn't seem like there is a way to change the script to automatically "know" which of the two possible segments you mean, if including the start point were allowed.

Mark

Ramiro Espinoza

unread,
May 17, 2014, 6:57:18 AM5/17/14
to rob...@googlegroups.com
Hi there,

This is not strict Robofab but just Python, I hope you don’t mind helping me a bit with my silly script.

I am trying to filter and do some math on the CSV font sales reports I get from distributors. So far I managed to select the rows I need by:

import csv

with open(‘Sales-2013.csv', 'r') as csvfile:
    sales = csv.reader(csvfile)
    for row in sales:
        if “Fontname" in row:
            print ",".join(row)

The problems with this script is that I can successfully get the rows of single fonts but in the case of a font family, usually the first cell is “Fontname-something” and the script returns nothing, even when some cells later in the row the font name alone is present. I need to express:

if “fontname whatever” is present in the row, get me the row. 

or 

if “fontname whatever” is present in any of the row’s cells

Can you help me with it?

Thanks in advance.



David Březina

unread,
May 17, 2014, 7:16:35 AM5/17/14
to rob...@googlegroups.com
Hi Ramiro,

I think:

if row.find(“Fontname”) != -1:
print “,”.join(row)

is what you are looking for.

Personally, I have been using Google and Stack overflow (and Python docs) for the moments when I get stuck with something that someone must have solved already. Stack overflow in particular has been of great help.

Hope this helps,
David

Ramiro Espinoza

unread,
May 17, 2014, 7:28:30 AM5/17/14
to rob...@googlegroups.com

Hi David,

With this code, now I get:

    if row.find(“Kade”) != -1:
                ^
SyntaxError: invalid syntax

David Březina

unread,
May 17, 2014, 7:48:40 AM5/17/14
to rob...@googlegroups.com
You need to use “ (straight quotes), not “”. I guess it got auto-corrected on the way.

d

Ramiro Espinoza

unread,
May 17, 2014, 7:55:19 AM5/17/14
to rob...@googlegroups.com

Quotes corrected, but now:

AttributeError: 'list' object has no attribute ‘find'

David Březina

unread,
May 17, 2014, 8:01:11 AM5/17/14
to rob...@googlegroups.com
Right, it is because row is a list, not a string as I assumed. I will reply off list.

d

David Březina

unread,
May 17, 2014, 8:10:13 AM5/17/14
to rob...@googlegroups.com
Did not want to pollute the list too much, but here you go. Since you were using the “in” I assumed you are using that on string. I guess the row object is a list of strings (cells in the CSV row), so you need to get the contents of the first cell and then test it… in which case the “in” command should work just fine (no need for “find", stupid me). You need to study the CSV module docs to see how to get to the cell contents.

I guess it will be something like this (for cell in “item” column):

if “Fontname” in row[“item”]:
print “,”.join(row)

d

Ramiro Espinoza

unread,
Oct 10, 2014, 5:48:52 AM10/10/14
to rob...@googlegroups.com
Hi there,

I will soon start using Robofont. I have a couple of questions:

Will my FL/Robofab scripts work in the Robofont environment? Is not, what should I code differently? Is there any online help about it?
What about DialogKit? Should I use it in Robofont or there is a better way to make GUIs in Robofont?

Mark Simonson

unread,
Oct 10, 2014, 10:40:28 AM10/10/14
to rob...@googlegroups.com
On Oct 10, 2014, at 4:48 AM, Ramiro Espinoza <ram...@RE-TYPE.COM> wrote:

> I will soon start using Robofont. I have a couple of questions:
>
> Will my FL/Robofab scripts work in the Robofont environment? Is not, what should I code differently? Is there any online help about it?
> What about DialogKit? Should I use it in Robofont or there is a better way to make GUIs in Robofont?

Generally, yes, unless the script uses code based on the FontLab python API.

You don't need to explicitly import Robofab (or DialogKit maybe?). And you don't need to "update" the font in order for changes to appear in the UI like you do in FontLab using fl.UpdateFont(). Effects of your script will be seen immediately and automatically.

There are definitely better ways to make GUIs in Robofont. It includes a lot of stuff in its mojo API and you can also use Vanilla.

Mark

Tal Leming

unread,
Oct 10, 2014, 10:43:51 AM10/10/14
to rob...@googlegroups.com
DialogKit should work. If you are comfortable with that API, you can use Vanilla to make UIs that have a lot more possibilities. Here is the Vanilla documentation:

http://ts-vanilla.readthedocs.org/en/latest/

Tal

Ramiro Espinoza

unread,
Oct 10, 2014, 12:19:43 PM10/10/14
to rob...@googlegroups.com
Thanks Tal and Mark for the info.

Cheers.

Frederik Berlaen

unread,
Oct 12, 2014, 4:24:47 PM10/12/14
to rob...@googlegroups.com
He Ramiro

if you didnt use import FL or fontLab specific API callbacks, so only robofab to manipulate your data, it should just work out fine.

What about DialogKit? Should I use it in Robofont or there is a better way to make GUIs in Robofont?

you can use dialogKit in RoboFont
Tal's vanilla package has just more options to build an UI.

good luck 


gr Frederik



Ramiro Espinoza

unread,
Nov 13, 2014, 8:41:18 AM11/13/14
to rob...@googlegroups.com

Hi colleagues,

Newbie question: Am I at risk of messing up Robofab and/or Fontlab if I install Python 3 along side 2.7?
Is there any prevision I should take before installing it?
Reply all
Reply to author
Forward
0 new messages