Align Selection to Grease Pencil 1.2.3 (2.80)

This looks really interesting. I could see this being used for possibly car topology in the early stages. Does it slide the verts when you’re looking down on them? Or does it move them? Doing it in side view actually moves them, but if the addon could possibly have an addon that allowed the verts to slide into position (if it doesn’t already) that would be a useful thing to have.

This could also open up some more drawing options for the grease tool as well. Like making a perfect circle/square/misc shape with it or something. This could be a fun topology editor.

That’s may be interesting

Anyway, cool stuff!
Very powerful and nice feature!
Thank you for this!

At the moment it always directly moves verts, either horizontally or vertically in screen space. Having it actually slide the vertices is very high up on my wish list for where I want to take this script further, so I will definitely look into that. I’m not exactly sure how to go about it, or if it ends up being feasible, but I’ll figure something out (or ask for help). Will just take some time :slight_smile:

Thank you :slight_smile: That’s an interesting video for sure. Do you know what the current status of that feature is?

! This is a addon/script I’ve been waiting for since I discovered “resizing edge loops” doesn’t work that well.

Thanks a bunch!

Well, Gstretch tool from Looptools were written by Bartius Crouch (an author of Looptools) by my proposal and support a couple of years ago.
We’ve got a good progress since then - now Gstretch can
= Align loops to stroke with several algorhytms (including sliding with Project Method - if Gpencil stroke was drawn directly on surface)
= Straighten loops (if no Gpencil found on object at all)
= Generate wire loops (if there are strokes without loop selection found)

We’ve made Axis Restriction feature in 2.5.4 (on video), and there were even autolock by view planned, but we’ve left stable Gstretch (Looptools 2.5.2) for Blender 2.70 release.

Now we’ve left Gstretch development for some time.

Looks nice abd helpfull addon, but did n t seem to work for me:confused:
unfortunately i can t read this traceback thing

Attachments


This is a very interesting thing and inspires me to new work, since it is a little bit different from Gstretch.
Thank you so much for your effort and work!

But at first time using it I was despaired, since ran into the following issue.
I was testing your Addon on 2 different Windows machines with “fresh” Blender profiles (default settings) and when I selected a loop of verts, draw with the Grease Pencil and hit the Button (“Align verts to Gpencil Stroke”), then I get the following error:

Traceback (most recent call last):
File “C:\Users%username%\AppData\Roaming\Blender Foundation\Blender\2.70\scripts\addons\mesh_align_to_gpencil_view.py”, line 62, in execute
verts_world_2d = [location_to_region(obj.matrix_world * v.co) for v in verts_local_3d]
File “C:\Users%username%\AppData\Roaming\Blender Foundation\Blender\2.70\scripts\addons\mesh_align_to_gpencil_view.py”, line 62, in <listcomp>
verts_world_2d = [location_to_region(obj.matrix_world * v.co) for v in verts_local_3d]
File “C:\Users%username%\AppData\Roaming\Blender Foundation\Blender\2.70\scripts\addons\mesh_align_to_gpencil_view.py”, line 220, in location_to_region
return bpy_extras.view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d, worldcoords)
AttributeError: ‘module’ object has no attribute ‘view3d_utils’

location: <unknown location>:-1

With Blender 2.70, official release.

Now I wanted to know, if something is wrong with my Blender and I enabled (temporarily) Looptools where Gstrech worked fine and well I just played around and pressed “your” Button again…
The thing is, now it worked! :slight_smile:
When I enable Looptools (temporarily), your Addon will work as it should, until I close Blender and start it again without LoopTools turned on (then the same error comes up).
I discovered this, since I usually test new Addons before I add them to my “workspace Blender” and since I wanted to make sure and compare between them.
It seems, it is possible to reproduce this error by using a new (fresh) Blender “profile” (default settings, LoopTools not enabled), put your script in the addons-directory and enable it, select a vert loop and make a Grease Pencil stroke and hit “your” Button.
Then you will get the posted error message.
When you have Looptools enabled all the time it will work fine.

Anyways I love the Addon and hope, you will continue the work also with all the TO-DOs in your schedule! :slight_smile:

Greetings

EDIT:
oh, i see schoggi was faster - well, maybe this clarifies things :slight_smile:

That’s, probably, because of View Gpencil’s ‘drawing setting’ setup.
It’s unable to define stroke’s location in this mode.

Thank you both! I was simply missing an import (view3d_utils). Since I’ve had LoopTools enabled, and it is imported there as well, I never noticed that I had to import it myself. It’s fixed now, and the updated version of the script is available at the same link as before.

Ah, I see! That is interesting. The entire LoopTools bundle, alo is one of the addons that inspired me to try making my own. (Looptools and Bsurfaces, to be exact).
I am trying to avoid overlap with Gstretch as much as I can, and I think this script will be more for general alignment than just vertices. For instance objects, bones, spline points, etc.

EDIT:

Ah, yes, that is another problem. Thanks for reminding me to put this on my to-do list :slight_smile:

Thank your for fixing it so quick!
Yes, it now works really fine.

Just one other idea :slight_smile: (lol, I hope, I do not stress you too much)
I think it would be easier accessible, when you add the option to “Clear strokes on execute” even to the Tool shelf, instead of the Addon’s properties(?)

Works fine… excellent…thanx

Great tool. I was hoping to use it to coerce a circle of verts into a rough hexagon of verts, but ran into a bit of an anomaly.

In top view, ortho, create a circle. Tab into edit mode. Select all vertices. Now, with the grease pencil, draw an approximate circle (closed or not) around the previously created circle of vertices (grease pencil circle diameter a bit larger than original circle diameter). Now execute the addon.

I sort of expected the original circle of verts to expand to the diameter of the grease pencil circle (while maintaining their circular relationship), but instead, the vertices seem to swing wildly from the top of the grease circle to the bottom creating what resembles a poorly tesselated circle. It seems that the script needs to align to the NEAREST grease pencil vert or something, but not sure what else that would break.

I realize this test is not exactly what the tool is meant for (like aligning a string of vertices to a grease pencil line), but I’d be interested in an explanation of this behavior.

At the moment, this is intended/expected behaviour, but it is not ultimately desired. The script was, as you realize, developed for quick aligning of a small series of connected vertices. For that use case (and with my still limited experience with scripting) it made sense to search only horizontally or vertically, depending on the direction of the stroke. It’s just easiest.

I do want to make it possible to use e.g. the vertex normals instead of the very constrained method I use currently, but I have things to figure out before I can get there. In the meantime, the functionality you want is found in Gstretch (in LoopTools). It will do exactly what you want in this situation.

Here’s a breakdown of exactly what happens when you run my script: (This is helpful for myself as well, so bear with me :slight_smile: )

  • Get selected vertices.
  • Convert vertex positions to screen space.
  • Convert grease pencil stroke’s points to screen space.
  • Determine if stroke is currently horizontal or vertical on the screen. (World space direction is completely ignored)
  • For each vertex, if stroke is vertical, look horizontally for the closest stroke point. (Opposite if stroke is horizontal)
  • Get new vertex positions in screen space, convert to world space.
  • Move each vertex to its new position.

Here’s a small illustration that shows when it currently works and doesn’t. Orange lines are the directions vertices are looking for their nearest equivalent point on the stroke.


So in cases 1 and 2, it’s easy to determine what direction the stroke is flowing (using my simple code), and everything works like expected.
In case 3, I don’t really have a clue what my algorithm would say. (It checks if the total difference between the points in the X or Y axis is highest).
Case 4 is tricky. It can be either or, depending on the randomness of the stroke. It’s not optimal.

The positions of the verts in relation to the stroke don’t matter, they will always look for their closest neighbour in the direction they are told.

So I guess the conclusion is that, at the moment, the script requires the user to “play along” with its limitations. I will update the main post with a little explanation of this :slight_smile:

Attachments


Wow. Thanks for the complete and insightful explanation. I can see clearly now what it is doing and this will help in the future use of the tool.

I did play with GStretch a bit too (And BSurface). They are terrific tools also , but what I liked about yours was that it works in screen space. When I tried various GStretch tests, the vertices always ended up at the 3D position of the grease pencil. With yours, I like the fact that if I am top ortho view and draw with the grease pencil, none of my selected vertices will have their z coordinates moved, regardless of what z the grease pencil and/or 3D cursor is at. I will go back and see if there are other options in GStretch to play with.

Anyway, thanks again. I’m a scripting wannabe, and if this is one of your early scripts, then you are an inspiration!

hello
another small ( I hope) Problem popped up…
while trying to unwrap something… the traceback Thing showed up again, and the only Thing i am able to read in… is mesh align to grease pencil…
Help!!!

Attachments


Folk. Sincé the hotkey is so important for this to work flawlessly as yourself suggests, I would recommend to add an option in the addon options to configure a hotkey easily. Some people might not know the command “mesh.align_verts_to_gpencil”, to créate a custom hotkey

Traceback (most recent call last):
File “C:[…]\Blender Foundation\Blender\2.70\scripts\addons\mesh_align_to_gpencil_view.py”, line 92, in poll
if len(bpy.data.grease_pencil[-1].layers) is 0:
IndexError: bpy_prop_collection[-1]: out of range.

location: <unknown location>:-1

Hi, I got this error on doing “remove doubles”. Usage of the addon or using grease pencil wasn’t involved at all. Hope information is useful enough, sadly I can’t provide the model.

Yes me too! I have the same traceback with Blender r2.70 hash b64bdb2 !
Win Vista 32bites

I’ve got some problems with removing doubles, so I enabling addon when I need it.