CAD Snap Utilities

@mano-wii

Thanks, I got it. It’s just the built-in Blender function


bpy.ops.view3d.select(location=(x, y))

I noticed Blender native actions with vertices and edges are blocked when the addon is running. For example vertex grabbing with the “G” key isn’t possible. How do you achive that?

To enable all blender native actions, just change the last line ‘RUNNING_MODAL’ to ‘PASS_THROUGH’ and delete the line “navigation(self, context, event)”.
But a warning, this can cause several problems, and requires more memory.

Here a new trial version with the new option “Ortho Mode (F8)”.
When you press the F8 key, the Constraints ‘X’, ‘Y’ and ‘Z’ are automatically enabled.

Feel free to test. :slight_smile:

Actually, i had a more potent approach in mind. ACAD ‘ortho’ mode restricts you exclusively to axes, giving you lightning fast generation of orthographic objects, but if you want to draw in an arbitrary direction you have to hit F8 in the middle of operation to shut down the restriction, and then F8 again to continue in ortho etc. The soft-snap would allow arbitrary drawing just as it does now, only when it comes to a few degrees from axis it would snap to it offering the possibility to grab that direction. If you continue diverting from that direction it lets go of the nearest axis and reverts to arbitrary mode… The degree threshold could be adjustable by the user, and would probably be calculated on the view matrix plane… stop me at any time…

EDIT: Haha, while i was writing the post you made the modification. You are really good :slight_smile: Ok , let’s give the ortho mode a shot :slight_smile:

@mano-wii

Thank you for your replies!

I asked, because I’d like to apply your findings to my addon. So I am interested how it works in general.

What is a general way to block default Blender actions, like grabbing with the “G” key?

Mano, it works! It feels like home :slight_smile: Great job!

A small suggestion, if it is possible - although F8 is famous for ortho mode, maybe it would be even more capable if you could map it to middle button press, all blenderheads know what comes after that :smiley:

I was thinking, if you could map it to middle mouse press (which is probably not occupied in this drawing mode), not only would the switch form arbitrary to ortho be faster and more familliar, there would be no need for the axis soft-snap also! It seems this would even be more capable than that…

I do not know exactly. The {‘RUNNING_MODAL’}, initialize a modal loop, this can help. In Sub-Forum “Python Support” you can have more chance to get the answer.

Let me see if I understand, while pressing the middle mouse button, the Ortho mode is enabled. When you release the MMB, the Ortho mode is disabled. Right?
It seems to be convenient.

No, just the short MMB press, something like the standard blender behaviour. Instead of F8 - short MMB press/release for ortho. Again, to leave ortho - short MMB press/release. This way we wouldn’t interfere with the in-operation orbit (MMB drag), which i think is one of the greatest features of this add-on.

Of course, if that is possible at all. Maybe there would be a collision between MMB drag and MMB press/release, it is just my wishful thinking. It is a breakthrough tool already!

@Okavango, the conflict with the navigation functions, makes this key change complicated. :\ So I think appropriate to continue with the ‘F8’.

Yeah, i agree. It was just an idea for comfort, the ortho function already being excellent.
Come to think of it, when using the MMB axis constraint in Blender (during grab or scale) the view navigation is disabled, so the conflict actually never happens.

Thanks Mano!

Ok, tested the ortho function a bit, i found few issues, hope this helps:

ortho on, OUTSIDE, snapping to outside object gives error in line 306

ortho on, INSIDE, dividing a face with edges gives overlapping new faces

ortho on, INSIDE, direction escapes to other axes that are sometimes not close to current position of pointer (not sure what is confusing it, maybe a SHIFT-lock could help, constraining the snap to chosen axis)

ortho off, INSIDE, if snap to the next point was orange (endpoint) and at that moment ortho is turned on, the ortho restriction is made from the snap, not from the last created point

Thank you very much @Okavango, this simplify things.

Issues solved:

  • ortho on, OUTSIDE, snapping to outside object gives error in line 306 (this was related to the “increment”.)
  • ortho off, INSIDE, if snap to the next point was orange (endpoint) and at that moment ortho is turned on, the ortho restriction is made from the snap, not from the last created point

I can not reproduce:

  • ortho on, INSIDE, dividing a face with edges gives overlapping new faces

Known limitation:

  • ortho on, INSIDE, direction escapes to other axes that are sometimes not close to current position of pointer (not sure what is confusing it, maybe a SHIFT-lock could help, constraining the snap to chosen axis)

This limitation occurs because the ortho mode ignores the point that the mouse should be snapped without constrain. This avoids double calculations. But is in the plans work out a better solution.

Attachments

mesh_snap_utilities_line.zip (8.59 KB)

The trick is to switch between returning {“RUNNING_MODAL”} and {“PASS_THROUGH”} in the operator’s modal(context, event) function.

{“RUNNING_MODAL”} blocks passing the event back to Blender.
{“PASS_THROUGH”} passes the event through.

@mano-wii: Thank you again!

Yep, you solved them!
As a matter of fact, i can’t reproduce the third one either anymore. You must have solved it with the other two :slight_smile:

As for the end of the line in ortho mode and it’s offline snap point (since they are divided in ortho mode) it is a tricky problem but i think it is solvable. The problem is when you choose a specific axis and go with your mouse pointer to search for the snap reference point which is in most cases somewhere sideways from the axis, the direction switches the axis thinking you are trying to choose another axis. The trick is to find a way to LOCK the snap to chosen axis and prevent it to jump from that axis while you are searching for the reference snap point elsewhere in 3D.
That is most probably some kind of key lock like ctrl or shift that you mentioned somewhere. So - click ‘Line’/ click in 3D / F8 / choose axis / hit ctrl to lock / choose snap point / choose next axis / hit ctrl… It seems complex, but i think it would be quite ok… Single click to lock, and single click to free it if you change your mind and want another axis… You could actually use this lock outside of orhto mode also, for every direction you choose to grab…

I have a complete suggestion for this hibrid ortho mode, if you want i could make some kind of diagram to help you polish it. I would be glad actually, having waited for something like this in Blender for a long time. You could use this snap mode in all the other features of your addon - measure, move, copy, etc.

@Okavango, I’m glad with suggestions :). Regarding the ortho mode, I already have in mind another solution. This would solve the problem mentioned of losing axis.
But for this, it necessary to rethink a lot of things in the script. So we shall wait.
I don’t intend to add a button that blocks, since the current solution of ortho is temporary. This also complicate a bit the use of the addon.
But I can change my mind depending on the need.

You are right, let’s see where will things evolve to.
Once again, apoligies to the retopo squad :slight_smile:

Just to be on the clear terms regarding the propositions, here are the diagrams i mentioned, hope you don’t mind. I am not quite sure these concepts are tehnically possible or work-efficient, but maybe it gives you some ideas…

Attachments

Mano_snap_ideas.zip (1.14 MB)