Drawing Template Sets And Their Implementation In FreeCAD

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Sun Jan 26, 2014 10:36 pm

mario52 wrote:hi quick61
You can replace the old by those above (small changes) and it is closed for blocks of titles, they are complete (for the correspondence of the wiki and git)
Templates_18_01_2014.zip


Thank's mario, i grabbed these the other day and am slowly going through them, adding Working space, title block and viewBox tages to them. As soon as i work through them all, I'll update everything. Thanks for all the work you have done.

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Sun Jan 26, 2014 10:42 pm

j-dowsett wrote:
ulrich1a wrote:[I made a primitive python script, that can create a valid template as an svg-file. It is just a proof of concept. Data for the template definition are given in python lists.
In order to test the script, line 241 has to be edited, and your save path has to be put in. It just has the minimum functionality to generate a template. There is no gui or XML-parser.
There are some templates, that do not work in Windows builds with the dated Qt-version. Generating templates, with such a script has the advantage, that no advanced svg-features are used, like nested items.

During tests with the generated templates, I found that no numbers with decimals can be used in the working space and title block comments. When the numbers have decimals, the automatic scaling for does not work. This may be no problem for A-formats, but limits the definition precision.

Ulrich


That's cool - do you have the code available for testing / playing with?

Yeh, I specified it to work with integers for working space & title block. Given these are mm dimensions, I figured there was little need for fractional values. It's no bother to change this to work with floats ... but you'll have to justify the need first!! :)



I'd just leave it as int. unless there is a good reason not to. For my part, rounding things off is allot easier/neater than using thousandths or hundred-thousandths when editing the .svg file. When you tell Python int, wont it round off any float it generates?

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
j-dowsett
Posts: 200
Joined: Wed Sep 07, 2011 9:37 am

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby j-dowsett » Sun Jan 26, 2014 10:50 pm

quick61 wrote:I'd just leave it as int. unless there is a good reason not to. For my part, rounding things off is allot easier/neater than using thousandths or hundred-thousandths when editing the .svg file. When you tell Python int, wont it round off any float it generates?

Mark


Yeh, I think it's fine as it is.
I don't know, I'm no python expert, but I didn't know you could explicitly declare a variable type with python? But, certainly if you give it a = 5/4 it'll give a as 1. As opposed to b = 5.0/4 which'll give b = 1.25.

Ah, so that could be the problem, if python code allocates it as a float, based on what it's calculated from, then you'd have to ensure you converted it to an int.
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby quick61 » Sun Jan 26, 2014 11:54 pm

j-dowsett wrote:
quick61 wrote:I'd just leave it as int. unless there is a good reason not to. For my part, rounding things off is allot easier/neater than using thousandths or hundred-thousandths when editing the .svg file. When you tell Python int, wont it round off any float it generates?

Mark


Yeh, I think it's fine as it is.
I don't know, I'm no python expert, but I didn't know you could explicitly declare a variable type with python? But, certainly if you give it a = 5/4 it'll give a as 1. As opposed to b = 5.0/4 which'll give b = 1.25.

Ah, so that could be the problem, if python code allocates it as a float, based on what it's calculated from, then you'd have to ensure you converted it to an int.


Between the two of us, I'd have to say you are far, Far, FAR more of an expert than I am with Python, but a simple demo... Python rounds down in it's simplest form.

Code: Select all

a=1.3
b=2.5
c=3.9

FreeCAD.Console.PrintError (int(a))
FreeCAD.Console.PrintError (int(b))
FreeCAD.Console.PrintError (int(c))


run that from your python console or macro and see the results.

I also came across this you might want to play around with -

Code: Select all

import math
math.trunc(1.5)
> 1
math.trunc(-1.5)
> -1
math.floor(1.5)
> 1
math.floor(-1.5)
> -2


There is also -

Code: Select all

>>> import math
>>> math.ceil(5.4)
6.0


Depending on which way you want to go...

Edit- Maybe use something like math.ceil for bottom and left and math.floor for top and right? :?

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
mrlukeparry
Posts: 652
Joined: Fri Jul 22, 2011 8:37 pm
Contact:

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby mrlukeparry » Mon Jan 27, 2014 5:15 pm

ulrich1a wrote:
mrlukeparry wrote:A python class will be given a template file of some format - maybe xml / python for which contains basic template parameters such border position, thickness etc.
I made a primitive python script, that can create a valid template as an svg-file. It is just a proof of concept. Data for the template definition are given in python lists.
In order to test the script, line 241 has to be edited, and your save path has to be put in. It just has the minimum functionality to generate a template. There is no gui or XML-parser.
There are some templates, that do not work in Windows builds with the dated Qt-version. Generating templates, with such a script has the advantage, that no advanced svg-features are used, like nested items.

During tests with the generated templates, I found that no numbers with decimals can be used in the working space and title block comments. When the numbers have decimals, the automatic scaling for does not work. This may be no problem for A-formats, but limits the definition precision.

Ulrich


If we're all happy to go with this approach, it'd be good to organise what this script needs so I know what your requirements are and I can go about implementing it and just be a bit more systematic about this.

I think we need to devise a list of public properties e.g page width, page height, type that are accessible to the script so that it can be used inside calculations or as part of logic.

Similarly we need to know what the inputs of these parametric templates are given to the script. Then if needed I can build up a parser but it may even be the case that its not needed - e.g. reading directly from the script.

Once we've all agreed to something then we can start pushing together to produce something :)
ulrich1a
Posts: 1374
Joined: Sun Jul 07, 2013 12:08 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby ulrich1a » Mon Jan 27, 2014 8:49 pm

At making late changes to the template generator, I forgot to upload it. :oops:
So I attach it now. It is not realy useful jet. It does just show the concept. It generates an svg-template from python lists. It does contain only one very limited list for one template style. The idea is to have lot of lists with different titleblock definitions. Dont forget to change your path at line 241.
mrlukeparry wrote:If we're all happy to go with this approach, it'd be good to organise what this script needs so I know what your requirements are and I can go about implementing it and just be a bit more systematic about this.
I start have the feeling, that there seems to be a misunderstanding. This script has just the potential to generate different templates for the current drawing workbench. The current drawing workbench has a parser to use svg-files, which is organized as an xml-format. So your new workbench may just use the allready existing code for parsing these files.
What can be new, is the possibilty to generate different template one the fly, with the users choice of paper-format, language, orientation and title-block style. I did only paper-format and orientation. Language, svg-symbols and more options are still todo.

Ulrich
Attachments
gen_template2.py.zip
template generate only proof of concept
(3.3 KiB) Downloaded 39 times
ulrich1a
Posts: 1374
Joined: Sun Jul 07, 2013 12:08 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby ulrich1a » Mon Jan 27, 2014 8:59 pm

Forgot to say, it does also generate a FreeCAD-Document with a visible presentation of the template. This can be changed. With the latest fixes, the FreeCAD-Draft-Workbench has also the potential as a template editor. You have to save as a flattedSVG. The draft workbench makes an extra marging of 1% to the outermost content. In order to have a good template just drawn in the draft-workbench, this has to be considered.

Ulrich
User avatar
shoogen
Posts: 2822
Joined: Thu Dec 01, 2011 5:24 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby shoogen » Mon Jan 27, 2014 9:18 pm

ulrich1a wrote:With the latest fixes, the FreeCAD-Draft-Workbench has also the potential as a template editor. You have to save as a flattedSVG. The draft workbench makes an extra marging of 1% to the outermost content. In order to have a good template just drawn in the draft-workbench, this has to be considered.
Usually you would not like to have a visible line at the border of the sheet.
ulrich1a
Posts: 1374
Joined: Sun Jul 07, 2013 12:08 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby ulrich1a » Mon Jan 27, 2014 9:26 pm

shoogen wrote:Usually you would not like to have a visible line at the border of the sheet.
I agree. When talking about templates, I understand you want to have an SVG-viewport with the exact dimensions of for example A3-paper. This cant be set anywhere in the Draft-workbench. At least I am not aware of it. So to make a workaround, the margin from the frame to the paper dimensions has to be this 1%, or something invisible is needed in the template.

Ulrich
User avatar
shoogen
Posts: 2822
Joined: Thu Dec 01, 2011 5:24 pm

Re: Drawing Template Sets And Their Implementation In FreeCA

Postby shoogen » Mon Jan 27, 2014 9:33 pm

the marco editor is probably a better template editor than the draft workbench. A text editor offer WYSIWYM, a vector editor (Inkscape) offers WYSIWYG and the draft workbench offers nothing.
In translated mode it shifts everything around by the margin. And in raw mode you have negative y coordinates, unsuiatbale for a lot of incompatible renderers.