Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by Roy_043 »

Is there a way to control the position of the baseline for coordinate dimensions?

In the example on the TechDraw_ExtensionCreateObliqueCoordDimension page the baseline is at vertex 4, is there a way to put it at vertex 1?
domad
Veteran
Posts: 2051
Joined: Mon Jun 22, 2020 12:16 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by domad »

Hi Roy_043, greetings to the Community!
Currently, when for me it is necessary, I intervene from the properties of the dimension by assigning to the dimension new references to the vertices, in the * .gif (for newbies) the steps to do so are shown.
I believe that @edi should have no particular problems in solving (?) This (important) "detail" in integrating the code of the macro functions in TechDraw
Attachments
Change of reference vertices of parallel coordinate dimension.gif
Change of reference vertices of parallel coordinate dimension.gif (712.12 KiB) Viewed 2952 times
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by Roy_043 »

Thanks for showing this workaround. I was actually not aware that you can update links in the Link dialog by clicking in the 3D view. So thanks for that as well.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by edi »

The workaround in the existing Create Horizontal Coordinate Dimensions tool:
- Sort all selected vertexes by its x-coordinates
- Create dimensions from the first (leftmost) vertex to the second, the third etc. vertex.

IMO the most important matter is the user interface, which must be as comfortabe as possible.

I do not prefer a dialog in the Combo-View where the user has to click a left/right button.

My suggestion: To show the baseline the first selected vertex must be the leftmost or the rightmost one. If the first selected vertex is neither the leftmost nor the rightmost an error message occures.

Find attached a test macro using this workaround.

Code: Select all

''' Testmacro creating a horizontal coordinate dimension using a left or right baseline'''
import TechDraw
import FreeCAD as app
import FreeCADGui as gui

class commonTools:
    ''' common tools used by command buttons'''

    def selectionOK():
        ''' check selection of View and ObjectList '''
        OK, ObjectList, View = False, [], []
        if gui.Selection.getCompleteSelection():
            View = gui.Selection.getCompleteSelection()[0]
            ObjectList = gui.Selection.getSelectionEx()[0].SubElementNames
            if len(ObjectList) > 0:
                OK = True
        return (OK,ObjectList,View)

class createHorizChamferDim:
    '''Create horizontal chamfer dimension'''

    def activated(self): # createHorizCoordDim
        def sortVertex(Vertex):
            return Vertex.Point.x

        (OK,ElementNames,View) = commonTools.selectionOK()
        if OK:
            VertexNames = [VertexName for VertexName in ElementNames if VertexName[:6]=='Vertex']
            Vertexes = [View.getVertexBySelection(VertexName) for VertexName in VertexNames]
            firstSelect = Vertexes[0]
            Vertexes.sort(key=sortVertex)
            if firstSelect == Vertexes[0] or firstSelect == Vertexes[-1]:
                if firstSelect != Vertexes[0]:
                    Vertexes.reverse()
                if len(Vertexes) > 1:
                    XPos = float(Vertexes[0].X)
                    YPos = float(Vertexes[0].Y)
                    Sign = YPos/abs(YPos)
                    for i  in range(len(Vertexes)-1):
                        DistanceDim=TechDraw.makeDistanceDim(View,'DistanceX',Vertexes[0].Point,Vertexes[i+1].Point)
                        DistanceDim.X = (XPos+Vertexes[i+1].Point.x)/2
                        YPos = YPos + 7*Sign
                        DistanceDim.Y = YPos
                gui.Selection.clearSelection()
            else:
                print('First vertex must be the  leftmost or rightmost one')

execute = createHorizChamferDim()
execute.activated()
- Select several vertexes
- Start the macro
Horizontal coordinate dimensions are created:
- If the first selected vertex is the leftmost, the baseline is at the left
- If the first selected vertex is the rightmost, the baseline is at the right
- If neither nor, an error message occures.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by Roy_043 »

You can also check the order of the first two vertices. That would perhaps make more sense as these also determine the direction (angle) of the TechDraw_ExtensionCreateObliqueCoordDimension tool AFAICT.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by edi »

OK, good idea. Find attached a test-macro using the suggested workaround:

Code: Select all

''' Testmacro creating a horizontal coordinate dimension using a left or right baseline'''
import TechDraw
import FreeCAD as app
import FreeCADGui as gui

class commonTools:
    ''' common tools used by command buttons'''

    def selectionOK():
        ''' check selection of View and ObjectList '''
        OK, ObjectList, View = False, [], []
        if gui.Selection.getCompleteSelection():
            View = gui.Selection.getCompleteSelection()[0]
            ObjectList = gui.Selection.getSelectionEx()[0].SubElementNames
            if len(ObjectList) > 0:
                OK = True
        return (OK,ObjectList,View)

class createHorizChamferDim:
    '''Create horizontal chamfer dimension'''

    def activated(self): # createHorizCoordDim
        def sortVertex(Vertex):
            return Vertex.Point.x

        (OK,ElementNames,View) = commonTools.selectionOK()
        if OK:
            VertexNames = [VertexName for VertexName in ElementNames if VertexName[:6]=='Vertex']
            Vertexes = [View.getVertexBySelection(VertexName) for VertexName in VertexNames]
            if len(Vertexes) > 1:
                firstSelect = Vertexes[0]
                secondSelect = Vertexes[1]
                Vertexes.sort(key=sortVertex)
                if firstSelect.X > secondSelect.X:
                    Vertexes.reverse()
                XPos = float(Vertexes[0].X)
                YPos = float(Vertexes[0].Y)
                Sign = YPos/abs(YPos)
                for i  in range(len(Vertexes)-1):
                    DistanceDim=TechDraw.makeDistanceDim(View,'DistanceX',Vertexes[0].Point,Vertexes[i+1].Point)
                    DistanceDim.X = (XPos+Vertexes[i+1].Point.x)/2
                    YPos = YPos + 7*Sign
                    DistanceDim.Y = YPos
                gui.Selection.clearSelection()

execute = createHorizChamferDim()
execute.activated()
- Select several (at least two) vertexes.
- Start the macro.
Horizontal coordinate dimensions are created:
- If the first selected vertex is left of the second one, the baseline is at the left
- If the first selected vertex is right of the second one, the baseline is at the right
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by Roy_043 »

Yes it works quite well. Thanks.
ToniTen
Posts: 240
Joined: Fri Sep 04, 2020 10:11 am

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by ToniTen »

This macro is really good! Many (probably all, but I've not used all the tools in the toolbox yet) of the features here should be part of baseline FreeCAD.

There's one thing that I'm sure is in front of me, but I can't see: how do I center a dimension label over the dimension line? I'm sure there will be a way, I just can't find it.
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by edi »

ToniTen wrote: Wed Dec 15, 2021 10:07 am ... should be part of baseline FreeCAD.
All the tools are created in C++, a PR https://forum.freecadweb.org/viewtopic.php?f=17&t=63548 is waiting to become merged.
ToniTen wrote: Wed Dec 15, 2021 10:07 am ... how do I center a dimension label over the dimension line?
Sorry, no option in the macro tools, but that will be possible in the C++ version.
ToniTen
Posts: 240
Joined: Fri Sep 04, 2020 10:11 am

Re: Macro version 4.2 multilanguage: helper tools to improve TechDraw documents.

Post by ToniTen »

edi wrote: Wed Dec 15, 2021 4:48 pm
ToniTen wrote: Wed Dec 15, 2021 10:07 am ... how do I center a dimension label over the dimension line?
Sorry, no option in the macro tools, but that will be possible in the C++ version.
I just saw that (all? most?) of the tools are finally merged into master, and they're already present in the latest dev appimage. Great work!

I didn't see it yet, but is there now a way to center a dimension over the the dimension line? or is this waiting for the merge to stabilise?

EDIT: DOH, using the "Extensions: Attributes/Modifications"/ "Position Horizontal Chain Dimensions"|"Cascade Horizontal Dimensions" will center the dimension over the dimension line, even if only one dimension is selected. Vertical centering seems to not work properly, since the dimension seems to end up slightly offset towards the bottom. Will detail it in a later post.

Oh, and I see that you've added "add diameter symbol" and "add square tube symbol". I've been using this macro https://github.com/reox/FreeCAD_macros/ ... at.FCMacro to add other symbols to my dimensions. Maybe it would be a good thing to incorporate (some? all?) of these into this drop down?
Last edited by ToniTen on Mon Jan 17, 2022 12:39 pm, edited 1 time in total.
Post Reply