[Feature Request] Add a way to align section views to regular views

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
ToniTen
Posts: 242
Joined: Fri Sep 04, 2020 10:11 am

[Feature Request] Add a way to align section views to regular views

Post by ToniTen »

I often need to align section views with regular views (assume a standard first angle view group, and then align sections with one or more of the secondary views). If the section views have the same width/height as the non section view, aligning them is easy, just set the same X and change the Y or vice versa. However, given that the X/Y position of a view (section or otherwise) is based on the centre of the bounding box of the projected geometry, if the section view ends up with a different sized bounding box, it's basically impossible to align it properly. So far, I've resorted to editing the drawing in Inkscape (and sometimes it's not easy and so takes a while, if the parts are complicated), but I need to be very careful to move the geometry and all the dimensions together.

I've attached an example file of what I usually need to do. "Section - Left" was easy to align, but "Section - Bottom" has a different bounding box and so ends up misaligned.
Attachments
align section views.FCStd
(12.84 KiB) Downloaded 58 times
User avatar
wandererfan
Veteran
Posts: 6317
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Add a way to align section views to regular views

Post by wandererfan »

ToniTen wrote: Tue Mar 08, 2022 12:28 pm I often need to align section views with regular views (assume a standard first angle view group, and then align sections with one or more of the secondary views).
The grid should help with manual alignment.
align section views_grid.png
align section views_grid.png (43.24 KiB) Viewed 5506 times
Are you looking for functions like Inkscape's "Align and Distribute"?
User avatar
Roy_043
Veteran
Posts: 8551
Joined: Thu Dec 27, 2018 12:28 pm

Re: [Feature Request] Add a way to align section views to regular views

Post by Roy_043 »

I am trying to write some Python code to (potentially) address this. And while testing my code I notice something I do not understand. In the file attached to the OP, the Y coord of the Bottom view in the ProjGroup is 95mm. The Y coord of the ProjGroup is 100mm. You would therefore expect the center of the Bottom view to have an effective Y coord of 100+95 = 195mm. But if you switch on the grid you can clearly see that the center of the Bottom view is higher. See the image in the previous post (in the image the grid is 10x10).

What is even more confusing is that if you first drag the Bottom view up, and then back down to its original position, the Y coord of the Bottom view changes to 100mm. Is there a bug here, or am I missing something?

I have attached the (POC) code.
The intended workflow:
  • Roughly position the view you want to move. The code checks for the delta X and delta Y distance between two vertices, the smallest distance determines how the view will be moved.
  • Select a vertex in the view that should remain in its current position.
  • Select a vertex in the view you want to move.
  • Run the attached macro.
  • Vertically aligning with the Bottom view does not work properly because of the mentioned issue.
Attachments
AllignTechDrawViews.FCMacro
(1.82 KiB) Downloaded 50 times
ToniTen
Posts: 242
Joined: Fri Sep 04, 2020 10:11 am

Re: [Feature Request] Add a way to align section views to regular views

Post by ToniTen »

wandererfan wrote: Tue Mar 08, 2022 2:53 pm The grid should help with manual alignment.
The grid would help, but it would not be exact, since AFAIK, there's no "Snap vertex to grid" functionality when moving views right? If there is such a functionality, then sorry for not noticing it yet, since the grid is a new, welcome addition to FreeCAD that I'm not 100% familiar with yet.
wandererfan wrote: Tue Mar 08, 2022 2:53 pm Are you looking for functions like Inkscape's "Align and Distribute"?
Inkscape's "Align and Distribute" functions could help, but the problem is, that really only works in very simple situations (and real life is anything but). Don't me wrong, it would be a really really useful addition, but I also feel we shouldn't need to replicate Inkscape inside of FreeCAD. It would not really work if the section view has a different width than the secondary views in the projection group AND it's also not aligned to one of the sides.

Let me make a slightly more complicated part and show you (FreeCAD file attached to this post):
This is what you get if you set the X coordinate of the Section - Bottom view to the same value as the projection group
Screenshot_2022-03-09_11-25-43.png
Screenshot_2022-03-09_11-25-43.png (25.41 KiB) Viewed 5303 times
This is what I want (without the red dashed lines, those are for illustration). I used inkscape to move the section view with the help of some guides
aligned section views.png
aligned section views.png (57.07 KiB) Viewed 5303 times
(inkscape source file attached too).
As you can see, that is aligned to where the section is (follow the red lines) and yet that is not feasible with just "Align and Distribute"
Attachments
align section views.FCStd
(13.58 KiB) Downloaded 35 times
aligned section views.svg
(39.42 KiB) Downloaded 48 times
ToniTen
Posts: 242
Joined: Fri Sep 04, 2020 10:11 am

Re: [Feature Request] Add a way to align section views to regular views

Post by ToniTen »

Roy_043 wrote: Tue Mar 08, 2022 8:58 pm I am trying to write some Python code to (potentially) address this.
Thanks a lot, I will check the macro later. I have no idea on the internal of FreeCAD to help you with getting it to work proper though :(
User avatar
wandererfan
Veteran
Posts: 6317
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Feature Request] Add a way to align section views to regular views

Post by wandererfan »

Roy_043 wrote: Tue Mar 08, 2022 8:58 pm What is even more confusing is that if you first drag the Bottom view up, and then back down to its original position, the Y coord of the Bottom view changes to 100mm. Is there a bug here, or am I missing something?
First, turn off AutoDistribute if you are going to drag views.

There is an allowance of "label size in mm" (5mm in my environment) for the vertical positioning of some views i(top, bottom and the iso views) in a projection group. Without this allowance, the labels overlap the lower view. So the real vertical position of Bottom is 205 in the example.
User avatar
Roy_043
Veteran
Posts: 8551
Joined: Thu Dec 27, 2018 12:28 pm

Re: [Feature Request] Add a way to align section views to regular views

Post by Roy_043 »

But how do you deal with this programmatically?
User avatar
Roy_043
Veteran
Posts: 8551
Joined: Thu Dec 27, 2018 12:28 pm

Re: [Feature Request] Add a way to align section views to regular views

Post by Roy_043 »

New version of the macro attached.
Attachments
AllignTechDrawViews.FCMacro
(2.3 KiB) Downloaded 53 times
User avatar
Roy_043
Veteran
Posts: 8551
Joined: Thu Dec 27, 2018 12:28 pm

Re: [Feature Request] Add a way to align section views to regular views

Post by Roy_043 »

There is definitely something strange going on:
  1. Open the file from the OP.
  2. Change "Auto Distribute" of ProjGroup to false.
  3. Recompute.
  4. Select the Bottom view in the tree.
  5. Notice that its Y is 95mm.
  6. Drag that view down by a tiny amount.
  7. Notice that its Y has a higher value now.
  8. Select the Front view in the tree.
  9. The Bottom view has moved up now.

Code: Select all

OS: Windows 8.1 (6.3)
Word size of FreeCAD: 64-bit
Version: 0.20.27809 (Git)
Build type: Release
Python 3.8.12, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: Dutch/Netherlands (nl_NL)
Installed mods:
edi
Posts: 482
Joined: Fri Jan 17, 2020 1:32 pm

Re: [Feature Request] Add a way to align section views to regular views

Post by edi »

Find attached my version of the macro (hopefully) doing the task:

Code: Select all

#
# scan selected objects:
#
Sel0 = Gui.Selection.getSelectionEx()[0]
Sel1 = Gui.Selection.getSelectionEx()[1]
View0 = Gui.Selection.getCompleteSelection()[0] # the base view
Pnt0 = View0.getVertexBySelection(Sel0.SubElementNames[0]).Point # base point
if View0.TypeId == "TechDraw::DrawProjGroupItem":
    View0 = View0.InList[0] # replace base view with its ProjGroup
View1 = Gui.Selection.getCompleteSelection()[1] # the section view
Pnt1 = View1.getVertexBySelection(Sel1.SubElementNames[0]).Point # section point
#
# do the calculations:
#
Scale = View0.Scale
C0 = FreeCAD.Vector(View0.X,View0.Y,0) # base center on page
P0 = C0+Pnt0*Scale # base point on page
C1 = FreeCAD.Vector(View1.X,View1.Y,0) # section center on page
P1 = C1+Pnt1*Scale # section point on page
Delta = P1.sub(P0) # the moving vector
#
# move the section view
#
if abs(View1.Direction.y) == 1:
    View1.X = View1.X.Value-Delta.x
if abs(View1.Direction.x) == 1:
    View1.Y = View1.Y.Value-Delta.y
Workflow:
- select one point in the base view
- select the corresponding point in a section view
- start the macro

The section view is positioned at the correct perpendicular position.

Attention: There is no test, whether the correct objects are selected.

Please test the macro. Is it worth to create an extension tool in TechDraw ? Pease tell me your opinion.
Post Reply