self.Get_Unit(str_) never called, a bug?

51 views
Skip to first unread message

Fuyun Ling

unread,
Mar 25, 2019, 2:08:49 PM3/25/19
to dxf2gcode-dev
When I input a .dxf file with length unit of millimeter  in the x, y directions, dxf2gcode always interpret it as inch.  I then found the interpretation is determined by the variable "g.config.metric".  The value of g.config.metric is set by the function call self.Get_Unit(str_).  However, by searching the code, I couldn't find where this function is called.  Could you take a look if it is indeed the case?  Thanks.
Fuyun
P.S.  This is the case for both the 2017 and 2019 versions.

Christian Kohlöffel

unread,
Mar 26, 2019, 1:36:49 AM3/26/19
to 'Timo Birnschein' via dxf2gcode-dev
This function is not created by me, so I can't say how it should work, but I also have the same impression like you. 
Can you propose a patch to make it working correct? I won't find time to do it in the near future.
Regards Christian

--
--
You received this message because you subscribed to the Google
Groups-group "dxf2gcode-dev".
To post a message, send mail to dxf2gc...@googlegroups.com
To unsubscribe, send mail to dxf2gcode-de...@googlegroups.com
See http://groups.google.de/group/dxf2gcode-dev?hl=en for more options
and the dxf2gcode project page at http://code.google.com/p/dxf2gcode/
---
You received this message because you are subscribed to the Google Groups "dxf2gcode-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dxf2gcode-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fuyun Ling

unread,
Mar 26, 2019, 11:59:06 PM3/26/19
to dxf2gcode-dev
Sorry.  I should have said, The function call's value cannot be specified.

--

Fuyun Ling

unread,
Mar 27, 2019, 12:02:21 AM3/27/19
to dxf2gcode-dev
I can patch it to make it work for either inch or mm.  However, since I cannot find where the function is defined, I cannot use menu setting to select.  Do you know where is this function defined?

Christian Kohlöffel

unread,
Mar 27, 2019, 1:32:26 AM3/27/19
to 'Timo Birnschein' via dxf2gcode-dev
This should be called while dxf_import at the begin (Header) of the DXF.

I would search for the DXF code in the file to find it.
Regards Christian

Christian Kohlöffel

unread,
Mar 27, 2019, 1:34:24 AM3/27/19
to 'Timo Birnschein' via dxf2gcode-dev
If you search for the file menu I need to check also if it's in the dxf2gcode.py or the UI file created with the Qt designer 

Christian Kohlöffel

unread,
Mar 27, 2019, 1:44:46 AM3/27/19
to 'Timo Birnschein' via dxf2gcode-dev

Christian Kohlöffel

unread,
Mar 27, 2019, 1:46:14 AM3/27/19
to 'Timo Birnschein' via dxf2gcode-dev
Search for tool_

Christian Kohlöffel

unread,
Mar 27, 2019, 2:06:10 AM3/27/19
to 'Timo Birnschein' via dxf2gcode-dev

Fuyun Ling

unread,
Mar 27, 2019, 2:52:24 PM3/27/19
to dxf2gcode-dev
There's nothing called "INSUNITS " in dxf files, which are generated by either visio or inkscape.  I don't have Autocad so I don't know if it is a compatibility problem of these two programs. 

--

Fuyun Ling

unread,
Mar 27, 2019, 3:02:00 PM3/27/19
to dxf2gcode-dev
In the latest emails that you mentioned are for output gcode files.  There's no problem there.  The output measuring units are always mm.  It looks like the problem is that the program expect to read the units from the dxf file but the dxf files that I generated does not specify the unit.  I don't know for sure if it is the case, though.

--

Christian Kohlöffel

unread,
Mar 27, 2019, 6:15:21 PM3/27/19
to dxf2gc...@googlegroups.com

Hi,

 

i just checked in the Code again, this is how it understood it up to now :

 

In the configuration file 3 variables are set to define the Units.

https://sourceforge.net/p/dxf2gcode/sourcecode/ci/master/tree/source/dxf2gcode/globals/config.py#l331

 

self.metric (This should be defined during the Import? Yes it will be overwritten later, so no effect in the config at all.)

self.tool_units and

self.tool_units_metric

 

After that the Units are read in the DXF file:

https://sourceforge.net/p/dxf2gcode/sourcecode/ci/master/tree/source/dxf2gcode/dxfimport/importer.py#l135

It will be searched for : $MEASUREMENT or $INSUNITS if None of both is found  the Standard which is mm is used.

 

This will be saved in the global variable: g.config.metric where 0 is Inch and 1 is mm. Which means the value in the configuration file will be overwritten. And  will be  mm if Nothing is set without taking into care the variable in the config file.

 

After that the values read are used here to set it during Export:

https://sourceforge.net/p/dxf2gcode/sourcecode/ci/master/tree/source/dxf2gcode/postpro/postprocessor.py#l426

 

 

For the configuration window GUI the value of self.tool_unit is used again.

https://sourceforge.net/p/dxf2gcode/sourcecode/ci/master/tree/source/dxf2gcode/globals/config.py#l521

 

 

I’m not really sure how this should work at all. Too many different variables used and then overwritten. This makes me confused …
Maybe you understand it better.

 

 

Regards

Christian

Fuyun Ling

unread,
Mar 27, 2019, 11:22:00 PM3/27/19
to dxf2gcode-dev
Hi,  Christian:
With your explanation, I think I know what is the problem is now.  The issue was the dxf file generated by Visio did not specify the values of the strings "$INSUNITS" AND/OR "$MEASUREMENT" correctly.  For example the value of $MEASUREMENT was 70.  It is an invalid number.  The section of the code in the function Get_Unit(self, str) dealing with $MEASUREMENT directly taking this value as the value of metric. Thus, the value of metric became invalid.  The section dealing with $INSUNITS is fine.  It only check the value is 1 or 4.  Since we are only interested in these two values, I simply change the section of $MEASUREMENT in the function  to be the same as the section of $INSUNIT.  It works fine now.  I listed the old section and the new section in the function Get_Unit(self, str) below.  Maybe you can test and generate a patch.  I did some patch before but not very proficient.
Thank you very much for your efforts and help.
Sincerely,
Fuyun
Old Section of code in Get_Unit(self, str) 
for line in range(len(str) - 2):
if str[line].startswith("$MEASUREMENT"):
metric = int(str[line + 2].strip())
break
# Default drawing units for AutoCAD DesignCenter blocks:
# 0 = Unitless; 1 = Inches; 2 = Feet; 3 = Miles; 4 = Millimeters;
# 5 = Centimeters; 6 = Meters; 7 = Kilometers; 8 = Microinches;
# 9 = Mils (thous); 10 = Yards; 11 = Angstroms; 12 = Nanometers;
# 13 = Microns; 14 = Decimeters; 15 = Decameters;
# 16 = Hectometers; 17 = Gigameters; 18 = Astronomical units;
# 19 = Light years; 20 = Parsecs
New Section of code:
              for line in range(len(str) - 2):
if str[line].startswith("$MEASUREMENT"):
if int(str[line + 2].strip()) == 1:
metric = 0
elif int(str[line + 2].strip()) == 4:
metric = 1
break

Christian Kohlöffel

unread,
Mar 28, 2019, 5:25:35 PM3/28/19
to dxf2gc...@googlegroups.com

Hi Fuyun,

 

just reviewed your changes and added them with one additional „improvement“ to the develop branch.

 

Refer to: https://sourceforge.net/p/dxf2gcode/sourcecode/ci/develop/tree/

 

Thanks for you support

Fuyun Ling

unread,
Mar 28, 2019, 9:02:27 PM3/28/19
to dxf2gcode-dev
Hi, Christian:
Thanks for letting me know.  Glad I helped, if any.
What is the additional improvement?
Fuyun

Christian Kohlöffel

unread,
Mar 29, 2019, 2:07:41 AM3/29/19
to 'Timo Birnschein' via dxf2gcode-dev
The default unit is defined by tool_unit also

zap parello

unread,
Apr 20, 2019, 3:19:29 AM4/20/19
to dxf2gcode-dev


On Thursday, March 28, 2019 at 6:22:00 AM UTC+3, Fuyun Ling wrote:
Old Section of code in Get_Unit(self, str) 
for line in range(len(str) - 2):
if str[line].startswith("$MEASUREMENT"):
metric = int(str[line + 2].strip())
break
# Default drawing units for AutoCAD DesignCenter blocks:
# 0 = Unitless; 1 = Inches; 2 = Feet; 3 = Miles; 4 = Millimeters;
# 5 = Centimeters; 6 = Meters; 7 = Kilometers; 8 = Microinches;
# 9 = Mils (thous); 10 = Yards; 11 = Angstroms; 12 = Nanometers;
# 13 = Microns; 14 = Decimeters; 15 = Decameters;
# 16 = Hectometers; 17 = Gigameters; 18 = Astronomical units;
# 19 = Light years; 20 = Parsecs
New Section of code:
              for line in range(len(str) - 2):
if str[line].startswith("$MEASUREMENT"):
if int(str[line + 2].strip()) == 1:
metric = 0
elif int(str[line + 2].strip()) == 4:
metric = 1
break

This is wrong code.
I have Autocad 2012 DXF reference open.
Here's what it says about $MEASUREMENT:

$MEASUREMENT 70 Sets drawing units: 0 = English; 1 = Metric 

No feets, no gigameters. Just English and Metric. Your list should be valid somewhere else, but not in $MEASUREMENT.

P.S. I started digging here to find out why my perfectly Metric DXF files (exported from Inkscape) instantly started to display in inches.

Fuyun Ling

unread,
Apr 20, 2019, 10:19:03 PM4/20/19
to dxf2gcode-dev
What does  Autocad 2012 DXF reference says about $INSUNIT?

zap parello

unread,
Apr 21, 2019, 5:29:54 AM4/21/19
to dxf2gcode-dev
I just found the doc/ folder inside the dxf2gcode repository :)
And it contains the file acad_dxf2010.pdf which same reference, just a little older.

$INSUNITS 70 Default drawing units for AutoCAD DesignCenter blocks:
0 = Unitless; 1 = Inches; 2 = Feet; 3 = Miles; 4 = Millimeters; [...]

So, the code to handle $MEASUREMENTS should be reverted to:
for line in range(len(str) - 2):
if str[line].startswith("$MEASUREMENT"):
metric = int(str[line + 2].strip())
break
and the code for $INSUNITS is fine, but it's not clear what to do if it specifies e.g. feets or angstroms.
To unsubscribe, send mail to dxf2gc...@googlegroups.com

See http://groups.google.de/group/dxf2gcode-dev?hl=en for more options
and the dxf2gcode project page at http://code.google.com/p/dxf2gcode/
---
You received this message because you are subscribed to the Google Groups "dxf2gcode-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dxf2gc...@googlegroups.com.

Fuyun Ling

unread,
Apr 21, 2019, 12:59:35 PM4/21/19
to dxf2gcode-dev
But the original code would not work for Visio generated .dxl codes.  Visio assigns a value of 70 to  $MEASUREMENT.  It is probably a bug in Visio but we cannot change that.
If what you said is true, why not just let: if $MEASUREMENT=0 => metric =0; elif $MEASUREMENT=1 => metric =1; bleak; 
This will be robust to autocad non-compliant dxl codes.
I can give it a try to see how it works for me.


To unsubscribe, send mail to dxf2gcode-de...@googlegroups.com

See http://groups.google.de/group/dxf2gcode-dev?hl=en for more options
and the dxf2gcode project page at http://code.google.com/p/dxf2gcode/
---
You received this message because you are subscribed to the Google Groups "dxf2gcode-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dxf2gcode-de...@googlegroups.com.

zap parello

unread,
Apr 21, 2019, 1:44:05 PM4/21/19
to dxf2gcode-dev
Hm, I see. So the solution would be something like this:

for line in range(len(str) - 2):
if str[line].startswith("$MEASUREMENT"):
tmp_metric = int(str[line + 2].strip())
if 0 <= tmp_metric <= 1:
metric = tmp_metric
break

Fuyun Ling

unread,
Apr 21, 2019, 5:09:12 PM4/21/19
to dxf2gcode-dev
Did not work for me.  I looked the dxf file generated by Visio, the lines in the $MEASUREMENT section are:
$MEASUREMENT
 70
     0
  0
So the value is always zero and it is interpolated as Inch.
It's Visio problem then.

To unsubscribe, send mail to dxf2gcode-de...@googlegroups.com

See http://groups.google.de/group/dxf2gcode-dev?hl=en for more options
and the dxf2gcode project page at http://code.google.com/p/dxf2gcode/
---
You received this message because you are subscribed to the Google Groups "dxf2gcode-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dxf2gcode-de...@googlegroups.com.

zap parello

unread,
Apr 21, 2019, 7:51:05 PM4/21/19
to dxf2gcode-dev
70 is block code and 0 is the value, and means inches.
Looks like it's a bug in Visio. I'm not sure this can be somehow fixed or detected.
Can you try to export a file in mm and then convert same file to inches and save again, then compare them? Will be any difference?

zap parello

unread,
Apr 22, 2019, 2:18:21 AM4/22/19
to dxf2gcode-dev
Perhaps this problem could be solved by implementing a switch for measure units somewhere in the main menu. So that even if dxf2gcode detected the units incorrectly one could fix it.
Something like "Measuring units -> [x]Inches | [ ]Millimeters".

zappa...@gmail.com

unread,
Apr 25, 2019, 3:56:36 AM4/25/19
to dxf2gcode-dev
Fixed DXF units detection, and added a menu option to switch between mm and inch if autodetection got it wrong.
Reply all
Reply to author
Forward
0 new messages