## idf importing error

Post here for help on using FreeCAD's graphical user interface (GUI).
fiffo
Posts: 35
Joined: Wed Oct 18, 2017 8:57 am

### Re: idf importing error

yes,
the problem in this file is on "board outline".
How I can fix this problem on idf.py script?

I try to use the busbox on windows commandprompt but don't work:
this is the error:
C:\Users\xx>C:\Users\xx\Desktop\freecad\busybox64.exe cut -d " " -f 2-3 Copy of NBP3 Altera MAX7000 MAX3000 PLCC Rev1 SOLO CONTORNO.emn | uniq -d
'uniq' is not recognized as an internal or external command,operable program or batch file.
openBrain
Posts: 486
Joined: Fri Nov 09, 2018 5:38 pm

### Re: idf importing error

fiffo wrote:
Fri Dec 07, 2018 2:51 pm
yes,
the problem in this file is on "board outline".
How I can fix this problem on idf.py script?
IDF.py is (I guess) the Python script importing the IDF into FreeCAD. Basically you just have to open it into a text editor and use your Python knowledge (as well as your FreeCAD API knowledge) to improve the script and overpass the current limitation.
GoW is available here : https://github.com/bmatzelle/gow/releases
It's quite a big piece of software, and some commands don't have the standard Unix name to prevent collision with Windows' commands.

For simple needs (as here), I would recommend the (very) small and efficient busybox here : http://frippery.org/busybox/index.html
I advise to run it with

Code: Select all

C:\path\to\busybox.exe sh -l
in the console to find yourself in a "bas- like" environment. If you don't do so, you'll have to prefix each command with "busybox " and use Windows-like path format.
openBrain
Posts: 486
Joined: Fri Nov 09, 2018 5:38 pm

### Re: idf importing error

fiffo wrote:
Fri Dec 07, 2018 2:51 pm
this is the error:
C:\Users\xx>C:\Users\xx\Desktop\freecad\busybox64.exe cut -d " " -f 2-3 Copy of NBP3 Altera MAX7000 MAX3000 PLCC Rev1 SOLO CONTORNO.emn | uniq -d
'uniq' is not recognized as an internal or external command,operable program or batch file.
OK, was edited during my first answer. As you're in the Windows env, you have to prefix "uniq" with "busybox64.exe ".
Actually use "busybox64.exe uniq" instead of just "uniq".

EDIT : also better to enclose your filename with double quotes

BR
fiffo
Posts: 35
Joined: Wed Oct 18, 2017 8:57 am

### Re: idf importing error

Hi,
thanks a lot for your support.
If I understand:
1 - I use this command on windows "command prompt"
C:\Users\xxx\Desktop\freecad>busybox64.exe cut -d " " -f 2-3 "Copy of NBP3 Altera MAX7000 MAX3000 PLCC Rev1 SOLO CONTORNO.emn" | busybox64.exe uniq -d

2-after running this appear:
0.0007 76.9997

This are the coordinate double.. ok .

3-I open the file "Copy of NBP3 Altera MAX7000 MAX3000 PLCC Rev1 SOLO CONTORNO.emn"

BOARD_FILE 3.0 "Altium DXP" 2018-12-07.15:49:16 1
"Copy of NBP3 Altera MAX7000 MAX3000 PLCC Rev1.00" MM
.BOARD_OUTLINE UNOWNED
0.4115
0 0.0004 0.0004 0.0000
0 0.0004 76.9998 0.0000
0 0.0007 76.9997 54.0180
0 0.0007 76.9997 0.0000
0 0.0007 76.9997 26.4500
0 68.9996 76.9996 0.0000
0 68.9996 0.0004 0.0000
0 0.0004 0.0004 0.0000
.END_BOARD_OUTLINE

4- and inside the file there are the coordinates 0.0007 76.9997 ... but is not exact the same because is:
0 0.0007 76.9997 54.0180
0 0.0007 76.9997 0.0000
0 0.0007 76.9997 26.4500

What line do I need to remove from file?
openBrain
Posts: 486
Joined: Fri Nov 09, 2018 5:38 pm

### Re: idf importing error

fiffo wrote:
Fri Dec 07, 2018 3:54 pm
What line do I need to remove from file?
Actually that's not so simple as removing lines. But not too hard too.
Your board is just a rectangle on which the top side is an arc.
A very simple IDF sequence that do not uses duplicate points is just the 4 board edges, providing for the top side the included angle.
According your board dimensions (69x77), and if I guess the center of the arc is on the middle of the bottom side, the included angle is "2*atan(69/2/77) = 48,2697 deg". As the arc is CCW, IDF specified it shall be passed as a negative value.

Thus finally you can remove the all 3 lines with duplicates coordinates as it uses an extra point that we don't need.
After that the 3rd point shall provide the inc angle between 2nd and 3rd point, thus -48.2697.

At the end, the BOARD_OUTLINE section of your file shall be as is :

Code: Select all

.BOARD_OUTLINE
5.0000
0 0.0004 0.0004 0.0000
0 0.0004 76.9998 0.0000
0 68.9996 76.9996 -48.2697
0 68.9996 0.0004 0.0000
0 0.0004 0.0004 0.0000
.END_BOARD_OUTLINE
But let me say it looses most interest of IDF (automatically exchanging ECAD and MCAD data) to do such tampering.

BR
fiffo
Posts: 35
Joined: Wed Oct 18, 2017 8:57 am

### Re: idf importing error

Ok, thanks.
And with this files in attachment I have this error (always from Altium IDF export),
The error is this
"Emp version: 2.0
Traceback (most recent call last):
File "<string>", line 1, in <module>
process_emn(doc,filename)
process_emp(doc,filename,placement,board_thickness)
comps.append((comp_PartNumber,[Process_comp_outline(doc,comp_outline,comp_height),comp_GeometryName]))
out_shape.append(Part.LineSegment(prev_vertex,vertex))
<class 'Part.OCCError'>: Both points are equal"

I used always the same program with this commad line:
C:\Users\floriano\Desktop\freecad>busybox64.exe cut -d " " -f 2-3 "aaaa.emn" | busybox64.exe uniq -d

nothing coordinate duplicates appair.
Attachments
aaaa.zip
openBrain
Posts: 486
Joined: Fri Nov 09, 2018 5:38 pm

### Re: idf importing error

fiffo wrote:
Fri Dec 07, 2018 5:52 pm
I used always the same program with this commad line:
C:\Users\floriano\Desktop\freecad>busybox64.exe cut -d " " -f 2-3 "aaaa.emn" | busybox64.exe uniq -d

nothing coordinate duplicates appair.
Guess the problem is in the EMP file. Did you try to process it also ?
Seeing your files one after each other, it appears there is a high chance that your ECAD software is totally not compliant with IDF.
Oppositely to what I previously said, troubling point sequences are non-sense and should never lead to something correct (even in other software).

EDIT : Won !
To find the duplicates more easily, you can use this enhanced command line (will indicate the line number) :

Code: Select all

cut -d " " -f 2-3 aaaa.emp | nl | uniq -f 1 -d
(Always add "busybox64.exe" in front of each command (cut/nl/uniq) in Windows environment)
openBrain
Posts: 486
Joined: Fri Nov 09, 2018 5:38 pm

### Re: idf importing error

Now that you are getting familiar with busybox, you can also automatically remove duplicates with the following command (in example, create a new "bbbb.emp" file that is "aaaa.emp" w/o duplicates) :

Code: Select all

sed -E '\$!N;/[01]\ (-?[0-9\.]+\ -?[0-9\.]+)\ -?[0-9\.]+\r?\n[01]\ \1/D;P;D' aaaa.emp > bbbb.emp
fiffo
Posts: 35
Joined: Wed Oct 18, 2017 8:57 am

### Re: idf importing error

Fantastic and thanks a lot for you support.
The problem is on idf.py that it does not manage this kind of problem/mistake..

I hope someone can update the idf.py file to manage this error and permit to continue to load the rest of the components without crashing
openBrain
Posts: 486
Joined: Fri Nov 09, 2018 5:38 pm

### Re: idf importing error

fiffo wrote:
Fri Dec 07, 2018 7:23 pm
Fantastic and thanks a lot for you support.
The problem is on idf.py that it does not manage this kind of problem/mistake..

I hope someone can update the idf.py file to manage this error and permit to continue to load the rest of the components without crashing
I don't really think the problem is on idf.py...
First the error is actually raised by FreeCAD itself when the IDF script try to create a null-length line.
Then the problem cause actually comes from your file (hence from your ECAD software). I processed a lot of EMN/EMP files with FreeCAD and never had any problem.
IMHO, this last point is the best reason to keep the idf.py as it is. I prefer it to fail with an error rather than succeed doing something that is not what I'm expecting.
But if you really want it, I attach a modified script that will ignore the duplicate errors. Beware that it just brutally ignores the duplicates when they come, and thus it may lead to unexpected shapes when importing.

BR
Attachments
Idf.py