Keep dimension positioning after editing 3D model

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
m.cavallerin
Posts: 115
Joined: Wed May 30, 2018 6:59 pm

Keep dimension positioning after editing 3D model

Post by m.cavallerin »

Hi all,
enclosed you can find a video where on a test model it is possibile to see that after changing 3D dimension, the dimension position won't change according to to the other and the dim ends in the middle of the view.
I haven't found a way to keep it relative to original position (before editing the 3D model).

Thanks for any hint

Michele
dimPosition.gif
dimPosition.gif (393.49 KiB) Viewed 3088 times
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: Keep dimension positioning after editing 3D model

Post by chrisb »

What algorithm would you propose - keeping of course other common use cases in mind?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
m.cavallerin
Posts: 115
Joined: Wed May 30, 2018 6:59 pm

Re: Keep dimension positioning after editing 3D model

Post by m.cavallerin »

Well, taking inspiration from writing programs like libreoffice, each text is defined in a paragraph that has several properties, including line spacing.
So instead of linking the position of the dimension to the size of the (absolute) view, it would be appropriate to link it to the position of the (relative) edge and its positioning should be a predetermined distance and (perhaps) settable by the user.
When the user moves the dimension, the algorithm should dynamically evaluate whether the new distance falls within a multiple of the line spacing in the settings.
As long as the instantaneous value is greater than a delta, the user can position the dimension at "where he wants"; when the user "enters" the dimension in a range covered by the delta, the program should move the dimension to the new line spacing * n where n are the distance steps.
If dynamically is not possible then the algorithm should calculate the delta when the user releases the mouse button, that's the event for evaluation of the positioning of the dimension.

I don't know the structure of the program and therefore I don't know how feasible it is, but for better or worse the "smart dimensioning" of Solidworks (e.g.) works more or less like this
m.cavallerin
Posts: 115
Joined: Wed May 30, 2018 6:59 pm

Re: Keep dimension positioning after editing 3D model

Post by m.cavallerin »

This is my code to automate svg generation. At the bottom you can find what I'm trying to do with the dimension positioning, but it's not a good solution, it changes with every shape.

Code: Select all

import sys
import os
FREECAD_PATH = '//usr/lib/freecad-python3/lib' #'//usr/lib//freecad//bin'
sys.path.append(FREECAD_PATH)
import FreeCAD
import FreeCADGui
import Part
import TechDraw

FreeCADGui.showMainWindow()
mw=FreeCADGui.getMainWindow()
mw.hide()


pathToTemplate = u'/path/to/a/fcstd/file/' #thisi is a freecad file that has a 3d model (Part) and a Page (Tech draw)
templateName = 'template' #the name of the freecad file
outputFolder = u'/home/user/Desktop/'
svgFileName = 'tes.svg'

template = FreeCAD.openDocument(pathToTemplate+templateName+'.FCStd') #è il file che contiene i modelli

X1 = '300 mm'
Y1 = '400 mm'
Z1 = '30 mm'
box1 = FreeCAD.getDocument('template').getObject('Box1')
box1.Length = X1
box1.Width = Y1
box1.Height = Z1

X2 = '150 mm'
Y2 = '40 mm'
Z2 = '30 mm'
box2 = FreeCAD.getDocument('template').getObject('Box2')
box2.Length = X2
box2.Width = Y2
box2.Height = Z2

#box2
moveX1 = 150.
moveY1 = 150.

box2.Placement = FreeCAD.Placement(FreeCAD.Vector(moveX1,moveY1,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))


pagina = FreeCAD.getDocument(templateName).getObject('Page')
template.recompute()

offset = 60
dx1 = float(X1.strip(" mm"))/2
dy1 = float(Y1.strip(" mm"))/2
dmvX1 = moveX1/2
dmvY1 = moveY1/2
dx2 = float(X2.strip(" mm"))/2
dy2 = float(Y2.strip(" mm"))/2
# ingombri
FreeCAD.ActiveDocument.Dimension.X = -dx1-offset*1.2
FreeCAD.ActiveDocument.Dimension.Y = 0
FreeCAD.ActiveDocument.Dimension001.X = 0
FreeCAD.ActiveDocument.Dimension001.Y = -dy1-offset
#posizioni foro1
FreeCAD.ActiveDocument.Dimension004.X = -dx1+dmvX1
FreeCAD.ActiveDocument.Dimension004.Y = -dy1+dmvY1-offset*1.7
FreeCAD.ActiveDocument.Dimension005.X = -dx1+dmvX1-offset*1.7
FreeCAD.ActiveDocument.Dimension005.Y = -dy1+dmvY1
#dimejsioni foro1
FreeCAD.ActiveDocument.Dimension002.X = 0
FreeCAD.ActiveDocument.Dimension002.Y = -dy1+dmvY1*2+dy2
FreeCAD.ActiveDocument.Dimension003.X = -dx1+dmvX1*2+dx2
FreeCAD.ActiveDocument.Dimension003.Y = 0


import TechDrawGui
TechDrawGui.exportPageAsSvg(pagina,outputFolder+svgFileName)
Attachments
template.FCStd
the testing file
(11.61 KiB) Downloaded 38 times
m.cavallerin
Posts: 115
Joined: Wed May 30, 2018 6:59 pm

Re: Keep dimension positioning after editing 3D model

Post by m.cavallerin »

chrisb wrote: Wed Dec 01, 2021 9:27 pm What algorithm would you propose - keeping of course other common use cases in mind?
Well, do you think my proposal is a good idea for further development?
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: Keep dimension positioning after editing 3D model

Post by chrisb »

As an option it could be sensible to make the position depend on the dimensioned item. I have seen many technical drawings though, where all dimensions are lined up at the border, which seems very sensible too.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
domad
Veteran
Posts: 2029
Joined: Mon Jun 22, 2020 12:16 pm

Re: Keep dimension positioning after editing 3D model

Post by domad »

m.cavallerin wrote: Sat Dec 04, 2021 5:00 am .........
Well, do you think my proposal is a good idea for further development?
Greetings to the Community!
Since the positioning of the dimensions (X, Y coordinates) that are created in a view refer to the center of the view (0,0), they can refer to the dimensions (Length - Height) of the "Piano" body, setting appropriate functions in the X, Y coordinate parameters.
By changing the length and / or height of the "Piano" body, the positioning of the dimensions does not change. If we move the dimensions in a broken way in any position, just activate the “Redraw Page” command and the dimensions will be repositioned correctly automatically.
To make the functionality "universal" you should enter the "block-position dimension" parameter through the "True / False" condition, once the position of the dimension has been chosen by setting the parameter to "True" the coordinates of the dimension positioning in the view are frozen , it will be up to us, in the event of a dimensional change of the object or new relocation, to reposition them ("False" condition) and then refreeze them ("True" condition).
Attachments
template2.FCStd
(12.17 KiB) Downloaded 31 times
template2.gif
template2.gif (210.22 KiB) Viewed 2741 times
user1234
Veteran
Posts: 3261
Joined: Mon Jul 11, 2016 5:08 pm

Re: Keep dimension positioning after editing 3D model

Post by user1234 »

domad wrote: Sat Dec 04, 2021 3:50 pm Since the positioning of the dimensions (X, Y coordinates) that are created in a view refer to the center of the view (0,0)
I think the issue starts here. This makes no sense. If i change an object in its length and have a section is not in the correct position anymore. The x and y coordinates should depend on its x, y z placement.

Also all here is pretty fragile because of the TNP.


Greetings
user1234
m.cavallerin
Posts: 115
Joined: Wed May 30, 2018 6:59 pm

Re: Keep dimension positioning after editing 3D model

Post by m.cavallerin »

domad wrote: Sat Dec 04, 2021 3:50 pm Greetings to the Community!
Since the positioning of the dimensions (X, Y coordinates) that are created in a view refer to the center of the view (0,0), they can refer to the dimensions (Length - Height) of the "Piano" body, setting appropriate functions in the X, Y coordinate parameters.
By changing the length and / or height of the "Piano" body, the positioning of the dimensions does not change. If we move the dimensions in a broken way in any position, just activate the “Redraw Page” command and the dimensions will be repositioned correctly automatically.
To make the functionality "universal" you should enter the "block-position dimension" parameter through the "True / False" condition, once the position of the dimension has been chosen by setting the parameter to "True" the coordinates of the dimension positioning in the view are frozen , it will be up to us, in the event of a dimensional change of the object or new relocation, to reposition them ("False" condition) and then refreeze them ("True" condition).
Hi thanks for the suggestion, but I can't understand all steps. Can you guide me through?
You created a spreadsheet and...?
You made universal entering "block-position dimension" parameter through the "True / False" condition, where?
domad
Veteran
Posts: 2029
Joined: Mon Jun 22, 2020 12:16 pm

Re: Keep dimension positioning after editing 3D model

Post by domad »

m.cavallerin wrote: Sun Dec 05, 2021 5:18 pm Hi thanks for the suggestion, but I can't understand all steps. Can you guide me through?
You created a spreadsheet and...?
You made universal entering "block-position dimension" parameter through the "True / False" condition, where?
Hi m.cavallerin, greetings to the Community!
I apologize for the misunderstanding, unfortunately in the file I had attached I forgot to delete the spreadsheet I had used (to avoid triggering the "circular reference" error) to refer to the placement of dimensions at the same dimensions.
Subsequently trying, with success, to set the functions directly in the parameters of the coordinates (X, Y) for positioning the dimensions and not having found any errors, I canceled the references to the spreadsheet but, unfortunately, I forgot to delete the sheet. :oops:
Regarding the problem, I simply suggested creating a parameter (True/False) that freezes/blocks or unfreezes/unlocks, the positioning of the dimension or more generally of the dimensions in the view.
Post Reply