Making an Add-on for Precision Drawing Tools (CAD)

How right I was :brain:, I wonder why I never thought of doing this before:

import bpy
from mathutils import Vector
areas = [a for a in bpy.context.screen.areas if a.type == 'VIEW_3D']
if len(areas) == 1:
    vm = areas[0].spaces.active.region_3d.view_matrix
    vm = vm.to_3x3().normalized().inverted()
    vl = Vector((1,0.5,0))
    vw = vm @ vl
    bpy.context.scene.cursor.location = vw

I will now implement this.

Cheers, Clock.

2 Likes

Now I have two new things:

  1. View Plane for all Options.
  2. Rotate View to set Values.

I think it is time to check everything and make sure no bugs have crept in. I had fun finding out how to convert Eulers to Quaternions, you would think someone might have written a standard routine to do that, but apparently not, or not one I could find like numpy.euler_to_quaternion(), that would have been nice, good job I am good at maths :grin:. I also had to invert the view matrix in order to get the Intersection commands to work in view mode as opposed to standard XYZ plane modes.

So now I can rotate a view to a set orientation, then extrude, etc. stuff in the view plane, including by delta and direction at angle, I am happy! :joy:

Cheers, Clock. :cocktail:

PS. I have absolutely no idea how to get View Align to Active tools to make any senseā€¦

4 Likes

I have added a new function; ā€œFind Centre Of Circle And Radius from Three Pointsā€, or ā€œArc Centreā€ as I called it to save writing a longer version of ā€œWar & Peaceā€ on the menuā€¦

Here I have selected three verices and clicked the ā€œArc Centreā€ button, the cursor has been placed at the centre of the circle that passes through these points and the ā€œDisā€ variable has been set to the circleā€™s radius. All operations that make sense work now, clearly extruding, or duplication geometry to this point would be just plain silly.

I also made this part:

The significant bit being that the part is all made from extruding geometry a known distance at a known angle, then there was the normal issue of placing the cursor correctly (I donā€™t mean guessing) to spin the geometry when it does not lie on any known axis. This I did by placing the cursor using my PDT tools.

Here is what I mean, in order to spin the geometry for the next curve to the right of the highlighted vertex, the cursor must be 1.5 units at -55 degrees from this vertex:

47

I have always had to ā€œfudgeā€ this before, or enter difficult maths into the cursor location boxes, not any more!

Cheers, Clock. :coconut:

8 Likes

Another Change:

I modified the Intersect function so it now uses Objects as well as Vertices, in this first one the cursor has been moved to the intersect of imaginary lines drawn through Empty-1 to Empty-3, then Empty-2 to Empty-4 as shown in the Order variable:

In Move mode, it moves the active object to this location, rather than the cursor:

Cheers, Clock. :mantelpiece_clock:

Oh yes, I forgot in my old age/drunken stupor, I also modified the Arc Centre command to use Objects as well.

4 Likes

I think I am about there now:

26

I can now ā€œOrbitā€, or ā€œRollā€ the view by a given amount. Here I have been orbiting and rolling the view by 27.5 degrees (System commands like ā€œOrbit Leftā€ only work at 15 degrees). I have then placed a plane in View orientation and tapered one edge by 10 degrees. This is similar to the Shear command only I can work in angles not offsets.

Can anyone think of anything else that might be useful? Seriously, let me know what you think chaps and chapesses. :boy: :girl:

Cheers, Clock. :coconut:

EDIT:

Perfect Isometric View (think about it):

(Orbit right 45 degrees, orbit up 35.2644 degrees)

@jesterKing your wish has been granted!

3 Likes

Is feedback from just a hobbyist, with no CAD experience to boot, worthwhile? I downloaded the add on dated from late August and Iā€™m attempting to just get a spline profile like whatā€™s shown here going: https://www.youtube.com/watch?v=-rCZNFARSfQ&t=117s

I figured out the panel well enough to do simple absolute and delta moves/extrudes but not much else. So besides the feedback that the numeric inputs are very far away from the buttons that actually use them, it would be unfair for me to give any other feedback without understanding how to really use this :slight_smile:

Do you have a practical example tutorial that goes over one of your blueprints or shapes above so that I can get a better idea of the workflow thatā€™s supposed to be used (especially for doing extrudes along an angle over a certain distance)?

3 Likes

Good point! I changed that:

I donā€™t have tutorials yet, I only started this project on 1st August, but a quick idea of what to do for a profile would be, assuming you are drawing in Front View (set Plane to X-Z) and assuming you have units at Millimetres:

  1. Place cursor at 0,0,4 for example: Operation set to Cursor, X,Y & Z set to 0 0 & 4, Click Absolute
  2. Add Single Vertex in normal Blender way.
  3. Draw first Edge: Operation set to Extrude, Set Dis to 4, set Ang to -90, Click Direction
  4. Draw second Edge: Set Dis to 12 Ang to -30, Click Direction.
  5. Draw third Edge: Set X to 20 Y to 0 Z to 0, Click Delta.

A lot of dimensions are missing from that drawingā€¦ so itā€™s hard to tell exactly what is going on. But that should show some kind of workflow.

Now, there seems to be an area where you need to project a line of unknown length at -30 degrees on this profile, rather than what I did above. So for that you could do this:


Draw These Edges as before, length of sloped edge is not important.

07
Draw This New Edge.

42
Select These vertices with your mouse, not a Box in order Horizontal Line vertices, followed by Sloped Line vertices. The order is not important provided the first two are one line and the second two are the other.


Operation is Move, All/Active is checked, Click Intersect.

Some of the names of the buttons have changed since that version, but this should help you until I get the help file done. I need to do some more checking before I upload this version, I am not sure I have all the bugs out yet.

If you hover your mouse over the buttons, etc. I have provided some Tool-Tips that might be useful also.

The latest version has a new Plane set of Front, Top, Right and View, so you can now set odd view angles and work in the view plane, you will have to wait for this until the bug checking is done, hopefully not too long, maybe this weekend.

Thanks for the feedback, often you can look at something for ever and miss obvious points when you write the thing yourself. You grow with it I suppose, so feedback is very important.

Cheers, Clock.

4 Likes

Ah, success! I had to hit the Direction button to use those Distance/Angle values. I guess thatā€™s confusing too. I was just clicking Delta as I figured I wanted to start at the vertex I was at and just delta from there at a given angle. Perhaps a different UI layout that keeps the buttons even closer to the values that will be used could be explored.

I keep my unit scale in meters, so Iā€™d like to type ā€œ4mmā€ into your value inputs. Change your FloatProperties to include the unit field to allow for this (see FloatProperty docs for reference):

Scene.pdt_delta_x = FloatProperty(name='X Coord', default=0.0, precision=5, description="X Coord Delta", unit='LENGTH')

I may play more tomorrow. Have you explored the ability to assign lengths and angles after edges have already been extruded or created? So if I lay down an edge of 20 mm and then later decide I want it 25 mm. I can just click vert1 and vert2, enter 25 mm, and it would extend vert2 another 5 mm along its direction?

Or perhaps creating your own viewport-based Extrude operator that would allow the user to do a mouse extrude in the viewport and then use the Redo panel to adjust the distance/angle etc. afterwards (to make it more polygon-modeler-friendly)?

OK, Done that.

Hereā€™s your wheel, approx:

Just select vertex to ā€œextendā€, set Angle (you can set the angle using the A/D 2D button, this also measures the distance between the two vertices you select, no need to do this if you havenā€™t changed the angle, Active Vertex is the centre of the Angle, set Distance (5mm), Set Operation to Move, click Direction.

Or in new version (when I upload it), set Percentage to 125 (or 25/20100*), select the two vertices on the edge, Active Vertex will be moved, set Operation to Move, click Percent. Percentages can be larger than 100, currently this moves the Cursor, or places new Vertices outside the two selected vertices if % is greater than 100. Negative values flip things around the opposite way!

46
Before.

12
After.

I am exploring having a Command entry box, so commands like CA0,0,4 would move the Cursor to Absolute 0,0,4 in XYZ and EI2,34 would Extrude the selected vertex 2 units at 34 degrees in the active Plane. But this will be in a later version.

Cheers, Clock.

2 Likes

At the moment I have this:

21

In this case ci1,40 moves the cursor 1 unit at 40 degrees from the active vertex, but I have had to make a button to the right to execute the command. I would like to execute the command when I press Return instead.

After a considerable amount of internet searching I cannot find how to do this, is it possible, it would be a better solution. Can anyone help me here?

Cheers, Clock.

1 Like

great work ! you have all my encouragements !

1 Like

Oh well, what did I say earlier about getting help hereā€¦

I have now worked it out, but I may need to work on my error messages a bit:

06

Cheers, Clock. :rofl::rofl::rofl::rofl::rofl:

1 Like

remind me of this :grin:

1 Like

ROFL ā€¦ Yes I know what you are thinking, sometimes I just need to ask for help in order to work it out for myself. But this seems to mean that I donā€™t get any now.

But I am happy in my own little world!

Cheers, Clock. :cocktail::cocktail::cocktail::cocktail::cocktail::cocktail::cocktail::cocktail:

2 Likes

Yay, just made this with my PDT tools:

Started with a vertex at 0,0,0 - Command na,,
Extruded it 10 in X - Command ed10,,
Extruded it 2@60deg - Command ei2,60
Carried on until I got to the bit where I needed to Intersect two edges.
Used Normal Tool to place cursor for holes.
Extruded it all in Y - Command ed,2,
Put Black Lines on it.

Terms n = new vertex, e = extrude, a = absolute, d = delta, i = distance@angle there are more obviously for other operations.

I am happy, now I need to check every option thoroughly for bugs. First though I have to make my dinner, as I have been left ā€œHome Aloneā€. :shallow_pan_of_food::canned_food::canned_food::beer::beer::chocolate_bar:

Cheers, Clock. :cocktail:

6 Likes

Thatā€™s cool and I hope blender can support precision CAD modeling for a better 3d printing fit in the future.

Personally, for me to be able to precision model (as an already blender exclusive user) what Iā€™m lacking is very simple. Not being able to set an exact (x,y,z) for a specific selection (by pivot) or even a single vertex. Not being able to extrude by blender units, only relative proportion. Everything else, I feel is already there.

At the same time, I understand that the CAD industry has its own way of doing things, and Iā€™m all for supporting the facilitation of doing it the way youā€™ve been doing it, too. :slight_smile:

1 Like

The things you want to do can be done, but not in a friendly and easy manner, or one that is generally known. You can extrude along the cursor axis by rotating the cursor and keying E X 2.4, having set the right mode, for example and that will extrude 2.4 units in cursor X. But try setting units to metres, then keying G X 2.4mm and your object will move 2.4 metresā€¦

You can move something in all three axes by keying G 2 tab 3 tab 4 and it will move 2 in X, 3 in Y and 4 in Z. This is hardly intuitive when a command like G2,3,4 would make far more sense. Constantly switching cursor mode allows you to mimic a CAD pivot point, I would like to see a pivot point introduced, but I guess I have a long wait. You can also press the = key and then enter formulae into the move statement, so sqrt(2); square root of 2, could be used.

The cursor can be placed precisely, but if you want to place it 2 metres at 37 degrees away from the selected vertex you must key sine and cosine formulae into the transform boxes. That is why I wrote all this stuff here, to make it more logical and easy for the user to achieve these things.

Thank you for the kind words!

Cheers, Clock.

EDIT:

The main problem is that most users donā€™t want to model accurately, just trace over an image and ā€œnear enoughā€ is ā€œgood enoughā€ for them.

1 Like

You learn something new everyday. I donā€™t know how long youā€™ve been using blender but wow! How did you figure this out?

Also youā€™re right extrude does respect blender units, itā€™s scale that doesnā€™t. My bad
Edit: changed my mind about scale not having it, because you can alt-scale; and rotating verts has no frame of reference. I almost started writing a script myself and realized :blush:

As for extruding by exact degrees, custom orientations work fairly wellā€¦ but thatā€™s a bit cumbersome if you have more than a specifically documented set of them. For something like 45 degree angles, Iā€™d make a face in object mode, rotate it in global space, and use that as the reference rotation for all 45 degree extrusions (along whatever axis), but I wouldnā€™t want to define a 37 degree one, a 13.25 degree one, etcā€¦ btw I find it interesting you prefer degrees over radians, any reason for that?

2 Likes

Personally I would always work in Radians, because I understand them, but most people donā€™t and degrees are more commonly used. It is interesting that in this code snip from my addon, I must convert degrees to radians as that is what Blender uses in the sine function:

        vector_delta[a1] = vector_delta[a1] + (dis_v * cos(ang_v*pi/180))
        vector_delta[a2] = vector_delta[a2] + (dis_v * sin(ang_v*pi/180))

There are calls in python to convert, but I prefer the old *pi/180, or *180/pi to go the other way. The same applies if you use drivers in Blender; all angles must be in radians.

I have used Blender since the release of 2.5 BTW, and I spend many hours reading the manual, or just pressing random keys to see what happens, I was most frustrated in the my early days with Blender that accuracy was not easy and it still isnā€™t! In my ealry days in CAD most commands where keyboard driven, so I was used to Absolute, Delta and Directional inputs, I am surprised that Blender did not allow for this in an intuitive manner, but it was not written for precise modelling, you donā€™t need this to model aliensā€¦

I once helped someone rig an aeroplane undercarriage, the fact that he had not modelled it accurately from the drawing dimensions, rather just traced it, meant it would not work until I remade it to the dimensions on the drawing. Many old drawings were not drawn accurately by the draughtman, but the dimensions were always right.

One day, my friend, this will all be in Blenderā€¦

Cheers, Clock.

1 Like

Youā€™re right, but things are changing quickly, because many former alien modelers, when 3D printing took hold, they tried their hand at precise modeling , Iā€™m one of them. and I totally entered into love. and having used other tools suitable for precision modeling, now it is a few years ā€¦ I discovered its great potential, that I would like the others ā€œof my kindā€ to know and therefore pretend in blender ā€¦
Iā€™m not sure that blender will become a great precision modeling tool, but it would be enough for the bare minimum to be available.
So that we amateur DIY designers can have a bit of fun.

In this target of people, blender can have a lot of attraction.

1 Like