Import DXF and Manipulate in Grasshopper

I would like to import several DXF files and then manipulate them (Group each file together).

This is part of a larger involved project, spanning hundreds of DXF files. I’ve searched and cant find a solution. I’ve spent over a month working on this project and this would really help.

BTW I’ve only used GH for a month now (coming from engineering SolidWorks world) I really learned to enjoy and appreciate what GH and its community have built. Thank you for everyone who helps.

For latest rhino and grasshopper

Ive tried elefront but it only imports 3dm files ( same as the native GH import component ). I’ve also tried using custom scripts/definitions others have made but they don’t seem to work.

It could be interesting to know your limitations
Could you import all dxf in a single file and then use worksession ?
How script doesn’t work ? Which ones ?

I know it’s not a help for you, but I right now file import other than 3DM is not available in the Rhino API, not in Rhinocommon, Rhinoscriptsyntax or Grasshopper.

I have a project that really NEEDS .STP import in grasshopper or Python.

McNeel, any chance of helping us out and giving API access to file import?

Cheers

DK

Unfortunately I’m exporting them from solidworks and it seems that they must be separate files, I also need their location in space to be kept. Im basically nesting hundreds of unfolds back into Rhino so they can be ran through a GH script I made. Unfortunately they aren’t grouped/separated on import, this is where GH would come into play.

tried these two GH things, and another convert script. Thought that maybe if I convert to 3dm I could just use the native import.

batchconvertto3ds.gh (13.3 KB) importToGrasshopper.gh (15.7 KB)

It’s possible to attach DXF files as worksessions. Usually worksessions are 3dm files, however if you set your default import options, rhino will attach without asking for options.

I use python code similar to below for attaching worksessions in grasshopper.

https://discourse.mcneel.com/t/batch-rhino-grasshopper-automation-with-worksessions/77985

#P is a list of filepaths to attach to worksession 
for p in P: 
#command must be surrounded with '' so that file path can e surrounded with "" 
#this ensures that paths with spaces still work 
    rs.Command('-Worksession Attach "{}" _Enter'.format(p))

After the worksessions are attached, you can use elefront to reference by layer name.
Use the full layer name including file name.
This will ensure that if you have many files with identical layer names, you will still be able to identify and reference them uniquely.
Eg from file1.dxf you want a layer named “fold”
Reference by layer name should take file1.dxf::fold

If this doesn’t help I can put together an example when I’m at a computer.

1 Like

Im still pretty new so an example would help.

Thank you all for the fast response (one of the most active program forums), I actually recognize your profile pic from reading a bunch of these threads.

I do need to batch “import” several dxf files for cnc processing through GH. The only way I Found is To drag and drop files in the top viewport, and use “insert” command instead of import. Then I manually set the options “as group” and uncheck invite for origin, scale, etc. I imagine it’s possible To automate this by script, but I don’t have the necessary skills. Tomorrow I will post my GH referencing définition. Maybe together we will find a solution…

Think this is a good solution, can you send me a grasshopper example with the python/elefront script inside. If its not too much to ask, would help a great amount.

Here is a sample.

Please let me know if it doesn’t work for you

Note that you will need the elefront add-in
https://www.food4rhino.com/app/elefront

as far as i understand you will only need step 3 and 4 for your workflow. I needed to make steps 1 and 2 to create test geometry

dxf export.gh (46.1 KB)

Here is the way I process (simplified version), the goal is to have a alphacam-like GH definition processing 2D dxf files using iformations from the geometries and their layer names (Elefront needed):

  1. I insert (no import) the dxf files in a new rhino document (drag and drop from explorer is my fastest way…) I’d prefer make this by script or with grasshopper, but I don’t know how to do that for now… The insert is made “by group”, not “blocks” (if someone has an idea you’re welcome) I keep the file name for creating the group name

  2. My definition keeps the dxf filename to give it to the export file (with a helpful python script I found in this awesome forum), and sorts the files by type (it’s for stair parts cnc processing)

  3. In my definition, the goal is to export a text file (I use a cnc extension .cix for Biesse machines), but once the geometries sorted you can proceed what you want on it and export in the file format you need

I only import 22 files maximum at once (it can be extended), for speed process reasons.
You can try whith my dxf files, because of the layer names, you will have an idea of the way it works. Hope this will help.

DXF IMPORT AS GROUPS.gh (39.0 KB) 1_Limon1Gche.DXF (23.9 KB) 1_Mar2.DXF (3.5 KB) 1_Mar6.DXF (3.5 KB) 1_Mar14.DXF (3.8 KB)

So neat, changed by own font and panel color right when I saw how good this looks haha. It works perfectly, really appreciate your solution, hopefully other people can get some use out of this. I’ll likely be using this to process my current project which involves importing 800ish custom sheet metal dxf files I created with the help of Gh.

Questions:
How can I get those colored rectangular blocks on the left? Cant find what those are. And how did you load that bunny thing into grasshopper ? Confused how that was self contained in the mesh component without a rhino file.

Ill try Philippe’s next, always fun seeing/learning from other definitions.

@edgar.jikst glad this helped you.

The coloured blocks are just normal groups (select any grasshopper components and press CTRL+G)
However what’s in the group is a bit of a trick.
It’s a transparent Sketch object drawn to exactly the same size as the canvas grid minus the extra width that the group adds. It’s part of our company template we use to help make all our definitions consistent.

The bunny is internalised from a file I had lying around (made from the Stanford bunny using mesh machine if you are interested)
If you right click on any parameter which is referencing something from :rhinoceros: and select “internalise”. This will store the geometry in the grasshopper file. It’s a friendly way of sharing GH files so you don’t need the 3dm file too.