Author Topic: Import DXF, STL, STP plugin  (Read 20103 times)

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5262
  • Made in England
    • View Profile
Import DXF, STL, STP plugin
« on: January 27, 2019, 21:09:18 pm »
I know Jeff Birt wrote an excellent file merge/import plugin but I always wanted something simple in the "File" menu for importing geometry, so while browsing through, CamBam.CAD.dll, of CamBam v1.0 I found the following methods;

CamBam.CAD.GerberFile.AddToDocument(CamBam.CAD.CADFile)
CamBam.CAD.IO.STEPFile.AddToDocument(CamBam.CAD.CADFile)
CamBam.CAD.STLFile.AddToDocument(CamBam.CAD.CADFile)
CamBam.CAD.DXF.DXFFile2.ReadFile(string)
CamBam.CAD.DXF.DXFFile2.ExtractGeometry(CamBam.CAD.CADFile)

These sounded like they would import geometry directly without the need to create separate cb files for merging.

I therefore wrote this quite short plugin to try them out,  please give it a try and let me know if anything needs changing.

This works on CamBam v1.0 only.

In the File menu it appears as "Import" then three options under that of DXF,STL,STP

I have also attached the project source file so those interested can see how simple it is.
There are two versions, one with threading (that's the one the attached plugin dll uses) and one without threading (it's been commented out to prevent Visual Studio reporting duplicate errors)
  
Testing indicates that STL and STP files are imported to the currently selected 'active layer', so that's easy to arrange, DXF files seem to create or use existing layers of the same name they were created with.

Edit:
Version 3 attached

1. Translations added
2. for each type of file, DXF, STL, STP or STEP, the path last used is saved in Windows Registry. (so that's 3 different paths)

Edit:
Version 4 attached.

1. Added 3DS import option
« Last Edit: January 31, 2019, 09:07:37 am by EddyCurrent »
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Import DXF, STL, STP plugin
« Reply #1 on: January 28, 2019, 00:48:19 am »
Hello Eddy ;)

Nice idea ! the DXF import will be very useful !  ;D (strange that Andy don't add this features if they already exist in the code !! .. the import STL is used from a while, but not the 2 others)

after kick test I get some little problems.

- when using import, CamBam do not remember the last file path used to import (maybe it's a wish ?)

- the small labels at the left side of the layer name do not reflect the layer color. (saving and re-opening the file fix that)

- I'm not able to import my step files.
1) the files have a .step extension instead .stp and are not visible in the file selector.
2) after changing the file extension to .stp, the plugin said: Must be a stp file.

this file open well if open normally with the open menu or with drag/drop (both with .stp and .step extension)

Same problem with my stl files I always have the "Must be a stl file" message (the same STL file import fine with the STL import icon)

last minute: the pb with the stl is that the plugin imports only txt version, and mines are binaries version. If I import the stl with the "cube" icon (import mesh) then export it with CB, CB save it as txt version and the file can be imported with your plugin.

I attach the files for tests (done with SolidWorks)

++
David
« Last Edit: January 28, 2019, 00:51:35 am by dh42 »

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1826
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #2 on: January 28, 2019, 01:38:10 am »
Hi Eddy

Good Idea, I got all three types of file to open. with a couple of hiccups probably the ASCII/Binary thing as david says.

Dave

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1826
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #3 on: January 28, 2019, 02:40:10 am »
I just had a look at the CamBam code and it does have an Binary importer for .stl files.
so I'm not sure what's the problem with importing them.
Dave

Offline Dragonfly

  • CNC Jedi
  • *****
  • Posts: 2652
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #4 on: January 28, 2019, 08:20:59 am »
Import is a base laying function in almost all programs. Missed it badly in CB. Will give the plugin a try.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5262
  • Made in England
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #5 on: January 28, 2019, 09:27:46 am »
Thanks for some initial testing, keep in mind I just threw some existing code in CamBam together to see what the result would be.
Filmed in Supermarionation

Offline Garyhlucas

  • CNC Jedi
  • *****
  • Posts: 1463
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #6 on: January 28, 2019, 16:07:17 pm »
See that, the Eddy plugin does it again!
Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5262
  • Made in England
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #7 on: January 28, 2019, 19:57:08 pm »
New version 2 attached to first post.


Hello Eddy ;)

- when using import, CamBam do not remember the last file path used to import (maybe it's a wish ?)

It uses, CamBam.CamBamConfig.Defaults.DefaultDrawingDirectory
which appears to be the path used for the current or previous cb file, File->Save

Quote
- the small labels at the left side of the layer name do not reflect the layer color. (saving and re-opening the file fix that)

I tried different ways to "refresh" the tree without success, but this one worked.

foreach (Layer layer in CamBamUI.MainUI.ActiveView.CADFile.Layers)   layer.Update();

Quote
- I'm not able to import my step files.
1) the files have a .step extension instead .stp and are not visible in the file selector.
2) after changing the file extension to .stp, the plugin said: Must be a stp file.

This is now fixed to include .step

Quote
Same problem with my stl files I always have the "Must be a stl file" message (the same STL file import fine with the STL import icon)

You used upper case for STL, I was just checking for lower case stl, this is now now fixed.

Quote
last minute: the pb with the stl is that the plugin imports only txt version, and mines are binaries version. If I import the stl with the "cube" icon (import mesh) then export it with CB, CB save it as txt version and the file can be imported with your plugin.

I made some simple solids in Rhino and exported two versions, ascii and binary. Both Imported to CamBam okay, I made no changes.
Can you attach a file that will not import ?

I also read today that "Threads" use quite a bit of memory and a better way is to use "Tasks", I'll take a look when time permits to see what needs done to use Tasks instead.
« Last Edit: January 28, 2019, 20:07:40 pm by EddyCurrent »
Filmed in Supermarionation

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1826
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #8 on: January 28, 2019, 23:19:27 pm »
Hi Eddy
I took the plugin for a spin with two .step files, one from an earlier version of freecad (maybe 0.16) and a new
one made with 0.18 latest binaries. (same file)
Both didn't work, but with different errors, so I've zipped them up for testing for you.
Dave

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Import DXF, STL, STP plugin
« Reply #9 on: January 29, 2019, 00:04:39 am »
Hello

Quote
I made some simple solids in Rhino and exported two versions, ascii and binary. Both Imported to CamBam okay, I made no changes.
Can you attach a file that will not import ?

It is in the .zip in my first message ; tested on the "old" version of the plugin ; bin stl can be opened, the pb was only because upper case for .stl extension ;)

The new version of the plugin seems to solve all problems for me.

I tried also Dave's step files, and they can't be opened, but not only by the plugin, if I try to open then with the load file I get the same error as Dave so the pb is not with the plugin but with the step format saved by freecad or with the CB internal step import function.

If I open Dave's step files in Solidworks, then re save them (step AP203 format), the files can be opened in CB without problems

++
David
« Last Edit: January 29, 2019, 00:21:32 am by dh42 »

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Import DXF, STL, STP plugin
« Reply #10 on: January 29, 2019, 00:30:57 am »
re

I tried to open Dave's files on freecad 016, and no problem, I re save them with freedcad 016, and both can't be opened in CB ... (with file/open or of course, with the plugin)

not that the STEP import in CB is not totally finished ; BSpline and surfaces can cause problems ; maybe SW use another object description than FC. (solid objects instead surface objects ?)

++
David
« Last Edit: January 29, 2019, 00:46:51 am by dh42 »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5262
  • Made in England
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #11 on: January 29, 2019, 08:18:41 am »
Many thanks for further testing and the attached files.

There's not much we can do about the FreeCAD files, all those error reports are internal to CamBam, nothing to do with the plugin code.

Edit:
Version 3 attached to first post.

1. Translations added
2. for each type of file, DXF, STL, STP or STEP, the path last used is saved in Windows Registry. (so that's 3 different paths)
That should provide enough scope for anyone's use.
« Last Edit: January 29, 2019, 18:07:45 pm by EddyCurrent »
Filmed in Supermarionation

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1826
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #12 on: January 29, 2019, 14:31:19 pm »
Quote
not that the STEP import in CB is not totally finished ; BSpline and surfaces can cause problems ; maybe SW use another object description than FC. (solid objects instead surface objects ?)
Yes this is what I found and I don't think it will change anytime soon.

I had a look at the NIST website (the people who look after the cadfile formats) and downloaded their analyser for step/stp file formats.
Turns out it's a tin of worms really, I did get the files to successfully load, the settings are in the pic's. plus you need to save the file as a .stp not step and have the checkbox "write out curves in parametric space unchecked".
I was surprised that they also had a Freecad project with files you could download.
Here is a list for the Application protocols for those interested.

• AP203 – Configuration Controlled 3D Design of Mechanical Parts and Assemblies [8]
• AP209 – Multidisciplinary Analysis and Design [9, 10]
• AP210 – Electronic Assembly Interconnect and Packaging Design [11]
• AP214 – Automotive Design [12]
• AP238 – Integrated CNC Schema [13, 14]
• AP239 – Product Life Cycle Support (PLCS) [15, 16]
• AP242 – Managed Model Based 3D Engineering [17-19]

Good work Eddy, I've been using .stl's but now can import .stp files (with certain limitations).

Dave
« Last Edit: January 29, 2019, 14:35:16 pm by dave benson »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5262
  • Made in England
    • View Profile
Re: Import DXF, STL, STP plugin
« Reply #13 on: January 29, 2019, 21:13:58 pm »
Good information Dave, many thanks.
Filmed in Supermarionation

Offline Bob La Londe

  • CNC Jedi
  • *****
  • Posts: 4484
  • ^ 8.5 pounds on my own hand poured bait.
    • View Profile
    • CNC Molds N Stuff
Re: Import DXF, STL, STP plugin
« Reply #14 on: January 30, 2019, 19:14:09 pm »
I thought CamBam also supported 3DS format. 
Getting started on CNC?  In or passing through my area?
If I have the time I'll be glad to show you a little in my shop. 

Some Stuff I Make with CamBam
http://www.CNCMOLDS.com