Round edges script

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Round edges script

Postby ponysmasher » Sat Jul 03, 2010 10:04 pm

Wrote a menu script to do what I talked about in this thread: Filling in the gaps in joints

Download it here: Round edges script and extract in the scripts/menu/third party folder.

It adds a filled circle on either all end points or the points you've selected. Like this:
Image

I would have liked to make it automatically pick the right color but I don't know if that's possible. Now you have to have picked the proper color before running the script.

Options:
Image

Note: If you've created points with the add point tool and haven't set the width manually, AS gives the point a value of -1 so there doesn't seem to be a way to get the width information from these points. If you've selected such a point and run the script it will assume that the point has a width of four. I think that's the default width.

If you use the freehand tool or have used the width tool on the points then it will work as expected.
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Postby Víctor Paredes » Sat Jul 03, 2010 10:36 pm

Nice script, thanks!
Just a little addition, could the new circles' points be connected to the line?
this way, if you press tab to select an entire line, circles will be selected too.

thanks
Víctor Paredes - Former Moho 12 Product Manager
My Youtube Channel - My webinars
User avatar
Víctor Paredes
 
Posts: 4786
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland

Postby heyvern » Sat Jul 03, 2010 11:10 pm

I think I will cry!!! Tears of joy. What a fantastic script! Lots of new and old scripters kicking some Lua arse! ;)

Ponysmasher,

If you don't mind I am going to "fiddle" with the code a bit. For example I do most of my work, or a lot of it anyway, that doesn't involve changing the point width. I mostly use the "style" line width which as you know already is "different" but is still there to retrieve (I recently learned how to do this).

This is what you explained about the width of "-1" defaulting to "4". I want to fiddle with the code and see if I can get the STYLE width OR any "point width" to get the proper diameter of the "circle" round edge shape. At the same time I can grab the stroke color itself from the shape and apply that color as the fill.

If I get this to work I will send it to you with comments so you understand my changes and so you can keep it up to date on your end.

Great script.

-vern
User avatar
heyvern
 
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Postby ponysmasher » Sun Jul 04, 2010 12:14 am

I've added the option to bind the created shapes to the bone that the point is bound to.

I'm looking into your suggestion selgin. Didn't even think of that.

And yeah, I'd much appreciate it if you find and send me any solution heyvern.
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Postby ponysmasher » Sun Jul 04, 2010 12:32 am

And now I've added the option to connect the circles to the points. Thanks selgin!
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Postby ponysmasher » Sun Jul 04, 2010 12:38 am

Oops, uploaded a bad version. If anyone downloaded between this post and the last please download again. :oops:
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Postby Víctor Paredes » Sun Jul 04, 2010 1:09 am

Thank you so much, ponismasher!
you are very clever on your ideas and really fast coding!

playing with this script I realized more than ever that AS needs different options for points of curves. I hope SmithMicro and Mike be reading this kind of posts :roll:
Víctor Paredes - Former Moho 12 Product Manager
My Youtube Channel - My webinars
User avatar
Víctor Paredes
 
Posts: 4786
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland

Postby heyvern » Sun Jul 04, 2010 1:15 am

Ha ha!

Aren't you sneaky! I was wondering how the heck you would "easily" connect the circle to the line without having to rotate/offset the circle to line up with the end point.... HA! Brilliant solution. I would have tried to rotate the dang circle and wasted a bunch of time. :)

-vern
User avatar
heyvern
 
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Postby heyvern » Sun Jul 04, 2010 1:26 am

selgin wrote:playing with this script I realized more than ever that AS needs different options for points of curves. I hope SmithMicro and Mike be reading this kind of posts :roll:


I wish there was an EASY way to get the style/s of the shape of a point. The scripting really makes it difficult to find out what style a point is part of. Of course a point can be part of more than one shape... <sigh> haven't figured out how to handle THAT yet. Basically you have to go backwards... get the shape, find the edges and curves of a shape, then check if a point is in the curve of the shape you are working with. It's not "hard" just "confusing" keeping track. ;)

I still have no idea what the number "486" means and why it is so important in programming AS. The line width values are divided by "486". So the "4" value for the default line width is 4 / 486 = 0.0055555556900799. Actually... it isn't even "486". It's a very long float: 486.00002111512241280517468337226. What the heck? Why not just use freaking "4"? ;)

If anyone can tell me what that number represents... I would love to know.

-vern
User avatar
heyvern
 
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Postby ponysmasher » Sun Jul 04, 2010 1:30 am

Didn't even think of another way. Sometimes having a simple mind pays off...

And yeah, I really think AS needs built in rounded end points. Looks so much more pleasing.
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Postby ponysmasher » Sun Jul 04, 2010 1:47 am

After some quick looking into it, the number seems to be the height of your project, vern.

First of all 4/486 is not 0.0055555556900799 (Duh, everyone knows that... :wink: )

I tried making a project that was 1280x720, made a point with a width of 1 in the GUI and looked at the internal number: 0.00138888892252

0.00138888892252 x 720 = 1.0000000242144 (That is, 1)

Made a new project, this time 480 in height. Made a point with a width of 1.
Internal number: 0.0020833334419876

0.0020833334419876 x 480 = 1.000000052154048 (Again, pretty close to 1)

Still in the 480px high project. Made a point with a width of 5. Internal number: 0.010416666977108
0.010416666977108 x 480 = 5,00000014901184

Yep, think that's it.

I guess if your project is taller than it is wide it would probably go by width instead.
Last edited by ponysmasher on Sun Jul 04, 2010 1:55 am, edited 3 times in total.
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Postby sbtamu » Sun Jul 04, 2010 1:48 am

You guys are coming up with stuff so fast I can't keep up. It's going to take me another year at least to understand basic Pro functions and you keep tossing new scripts at me. :D :D :D

I haven't had to learn this much stuff since Graduate school. I feel really challenged since AS7 has came out and that's a good thing, I'm loving it.

Thanks guys,

P.S.

vern hit 5500 post. Next goal 6k. :D :D :D
Sorry for bad animation

http://www.youtube.com/user/sbtamu
sbtamu
 
Posts: 1900
Joined: Tue Dec 15, 2009 5:05 am
Location: Texas

Postby heyvern » Sun Jul 04, 2010 3:01 am

Good grief...

It's all coming back now. Yes. line widths and similar values are all based on the HEIGHT of the freaking project or something like that. I remember now yes. My project IS set to a height of 486. Doesn't matter anyway. I am not converting any line widths at all. Just using the straight values.

I got it working the way I want... sort of. It's kind of backwards right now and I have to rethink. It is very tricky and needs some more work and here's why:

Suppose you have a vector that CROSSES another vector and is connected. Both of these vectors have different shapes with different line widths in the style. I have to put the "for each shape" loop around the "for each point" loop. I had it the other way around with the shape loop inside the point loop. It worked fine with only one stroke shape but not with multiple stroke shapes.

It's sooooo freaking confusing... shapes with curves, curves with edges, points in curves and edges shapes, styles, line widths versus point widths... AAAHHHGGGHHH! Taking a break to let it percolate in my brain. ;)


-vern
User avatar
heyvern
 
Posts: 6964
Joined: Fri Sep 02, 2005 4:49 am

Postby Imago » Sun Jul 04, 2010 9:14 am

Why I can't add it in the toolbar?
Even if I put the line in the tools.txt, the icon will appear in "other" not in "draw" as I want.
Sorry for my bad english... Q_Q
User avatar
Imago
 
Posts: 698
Joined: Wed Dec 10, 2008 9:48 am
Location: Sardinia

Postby ponysmasher » Sun Jul 04, 2010 10:21 am

Added the option to use current stroke color instead of fill. Makes more sense.

Fixed an error where if you put a circle on the middle of a line and chose to connect it, the curvature would be set to peaked.

The link is updated

Imago wrote:Why I can't add it in the toolbar?
Even if I put the line in the tools.txt, the icon will appear in "other" not in "draw" as I want.


I've actually never edited the tools.txt so I don't know how that works. Sorry.
User avatar
ponysmasher
 
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles

Next

Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests