How to set References2D of Dimensions

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

How to set References2D of Dimensions

Post by Aleks »

I want to create Dimensions using CosmeticVertexes.

The only way I found on how to use Dimensions in scripts is like this:

Code: Select all

dim1.References2D=[(view1, 'Vertex1'), (view1, 'Vertex2')]
The problem I have that I dont know the names of already placed CosmeticVertexes.

My question is: How do i set References2D using a direct reference to the CosmeticVertex object?
Alternatively: How do i get the name of an existing CosmeticVertex (like 'Vertex1')?
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: How to set References2D of Dimensions

Post by edi »

Select several vertexes in a view, start the script:

Code: Select all

Selection = Gui.Selection.getSelectionEx()[0]
ObjectList = Selection.SubElementNames
print(ObjectList)
A list of strings containing the vertex names will be returned.

To create a dimension use:

Code: Select all

import TechDraw
View = Gui.Selection.getCompleteSelection()[0]
Selection = Gui.Selection.getSelectionEx()[0]
VertexNames = Selection.SubElementNames
Vertex1 = View.getVertexBySelection(VertexNames[0])
Vertex2 = View.getVertexBySelection(VertexNames[1])
DistanceDim=TechDraw.makeDistanceDim(View,'Distance',Vertex1.Point,Vertex2.Point)
but ensure two vertexes had been selected.
Post Reply