Parametric dimensions from vertices???

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
triplus
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Parametric dimensions from vertices???

Postby triplus » Wed Aug 24, 2016 3:46 pm

I see. First step is to model a part in GUI and not to create it from FreeCAD command line.

Well i am sure that if this is one of the last things you need to sort out you will think of something in the following days. Until then FreeCAD Gui can still be used "behind" the input dialog to make it all work?
Korslight
Posts: 33
Joined: Thu Aug 11, 2016 3:26 pm

Re: Parametric dimensions from vertices???

Postby Korslight » Wed Aug 24, 2016 4:19 pm

Triplus

Yes I have been able to accomplish everything in FreeCAD GUI, and able to get the program to output the DXF of the part. The only thing I cannot currently do is output the drawing.

Thank you for your help, and time. I guess I will have to wait until exportation from console is implemented to TechDraw to finish my program goal of drawing exportation.
wandererfan
Posts: 2968
Joined: Tue Nov 06, 2012 5:42 pm

Re: Parametric dimensions from vertices???

Postby wandererfan » Wed Aug 24, 2016 4:36 pm

triplus wrote:And i am guessing the whole drawing with template and views on it isn't stored anymore inside .fcstd file in SVG format as it used to be?
The template is stored in the document, since we don't know if it will be available the next time the project is opened (on another machine, say). The actual views are recreated from the DocumentObject properties when needed.

wf
triplus
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Parametric dimensions from vertices???

Postby triplus » Wed Aug 24, 2016 6:39 pm

wandererfan wrote:The template is stored in the document, since we don't know if it will be available the next time the project is opened (on another machine, say).
Thanks for the explanation and indeed based on the past discussions this is the way to do it.
The actual views are recreated from the DocumentObject properties when needed.
I guess it would be cool if in the future some function would return the template + all views on it as SVG and the result could be further proccesed by Inkscape. Like the macro i attached above. Use case is to use FreeCAD in combination with Inkscape to get Vector PDF file. That is an image isn't inserted in PDF and instead the text is selectable and searchable. AFAIK Qt doesn't have straightforward support for that ATM.
Korslight wrote:I guess I will have to wait until exportation from console is implemented to TechDraw to finish my program goal of drawing exportation.
Could you attach the image of an actual problem. That is i am guessing we are talking about Draft geometry.
triplus
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Parametric dimensions from vertices???

Postby triplus » Wed Aug 24, 2016 10:32 pm

You have another possibility and that is to first install Lattice workbench:

https://github.com/DeepSOIC/Lattice2

After you can do the following. Insert Cube and use Draft Shape2DView on it (set correct Draft working plane first).
Draft geometry.png
Draft geometry.png (15.77 KiB) Viewed 892 times
This is i guess where you are ATM. You can export Draft geometry to DXF. Now start up Lattice workbench and select first diagonal point and use SubLink tool on it. After use Shape info tool on SubLink feature. Repeat the procedure on the second diagonal point. Insert Draft Line and add (parametric) Draft Dimension to it. Select the Draft Line and in Property view add expressions for Start/End X, Y and Z property. That is use Shape info features read only Vertex Position property for X, Y and Z in expression.
Constrained.png
Constrained.png (19.76 KiB) Viewed 892 times
After select original Draft Shape2DView feature and Draft Dimension and use Draft Drawing tool. Changing Cube feature size should be reflected in drawing:
Drawing.png
Drawing.png (5.63 KiB) Viewed 892 times
To extract SVG/PDF you can use this macro:

viewtopic.php?t=12353#p99373

Reference:
viewtopic.php?f=22&t=12464&start=70#p135271
Korslight
Posts: 33
Joined: Thu Aug 11, 2016 3:26 pm

Re: Parametric dimensions from vertices???

Postby Korslight » Thu Aug 25, 2016 1:34 am

Argh so close.

I was able to do as you suggested with the Lattice2 WB.

If anyone was wondering the expression for Start/End x,y,z properties are:

Code: Select all

Shape2DView_Vertex*?*_Info.ShapePoint.x
Shape2DView_Vertex*?*_Info.ShapePoint.y
Shape2DView_Vertex*?*_Info.ShapePoint.z
respectively, where *?* corresponds to the vertex that you are pointing to.


Also I ran your script and it worked great through the GUI. However I am still looking for the automation of exporting through the console alone without opening the GUI.

I have tried multiple things such as:
1) trying to run your script through the console with execfile("path to file"), and get the error "FreeCADGu is not defined" even after importing FreeCADGui, which makes me think the script requires the GUI to be open.

2) I have also tried exporting the dims as a flattened SVG using inportSVG.export("path.svg") but it gives me a strange error "The export list contains no shape" which it also gives me on the GUI when trying to export either the page or the parts. :?:

3) I have tried exporting everything as a DXF and it page part and dimensions, but only outputs the part... I believe this one may stem from the fact that I cannot import Lattice2 into the console. When I tried it gives a missing "QtCore" so I try to "from PySide import QtCore" and it still gives the error. Thus, when I open the file I receive errors, but it still is able to open (but I assume it "deletes" the Dimension and page to open through the errors)
triplus
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Parametric dimensions from vertices???

Postby triplus » Thu Aug 25, 2016 9:10 am

Yes i forgot Lattice might not work in FreeCAD command line. I am not sure to be honest (as i never use FreeCAD command line) on what should and shouldn't work and what happens if you add features in FreeCAD GUI and after try to modify them in FreeCAD command line. As for:
Korslight wrote: trying to run your script through the console with execfile("path to file"), and get the error "FreeCADGu is not defined" even after importing FreeCADGui, which makes me think the script requires the GUI to be open.
I mentioned this here:

viewtopic.php?f=3&t=17044&start=10#p135214

Code: Select all

obj = FreeCADGui.Selection.getSelection()[0]
This can't work in FreeCAD command line therefore you would need to replace it with something like:

Code: Select all

obj = FreeCAD.ActiveDocument.Page
I haven't test the macro i attached below but something in the lines of this is what you are after:

Code: Select all

import os
import subprocess

# Path to Inkscape executable
inkscape_path = "/usr/bin/inkscape"

obj = FreeCAD.ActiveDocument.Page
file_location = os.path.expanduser("~" + os.sep + obj.Label + ".pdf")
call_inkscape = [inkscape_path, "-f", obj.PageResult, "-A", file_location]
subprocess.call(call_inkscape)
User avatar
DeepSOIC
Posts: 6953
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Parametric dimensions from vertices???

Postby DeepSOIC » Thu Aug 25, 2016 10:34 am

Korslight wrote:... I believe this one may stem from the fact that I cannot import Lattice2 into the console.
triplus wrote:Yes i forgot Lattice might not work in FreeCAD command line. I am not sure to be honest
Yes, Lattice cannot be used from command-line FreeCAD.

I promised to myself I'm going to do it if someone complains about it. Please don't expect it to happen quickly, though :roll:

--
created an issue.
https://github.com/DeepSOIC/Lattice2/issues/12
triplus
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Parametric dimensions from vertices???

Postby triplus » Thu Aug 25, 2016 10:47 am

Thanks for confirming and @Korslight therefore i guess until all this TechDraw/Lattice stuff we talked about will work without GUI you probably should involve FreeCAD GUI in the process somehow. As it seems that it does everything you want and in the end you plan to use GUI dialog for your users anyway.

P.S. And who knows maybe it will end up a good thing. That is not hiding FreeCAD from the users but exposing them to it.
wandererfan
Posts: 2968
Joined: Tue Nov 06, 2012 5:42 pm

Re: Parametric dimensions from vertices???

Postby wandererfan » Thu Aug 25, 2016 11:40 am

triplus wrote:I guess it would be cool if in the future some function would return the template + all views on it as SVG and the result could be further proccesed by Inkscape.
Image
That functionality is available in the Gui now, but depends on QtGui. Drawings/exports without the Gui will require custom code to replace what QtGui provides.