Importing .dxf / .obj / .fbx with grasshopper

Hi all,

Like the title mentions, I’m looking for a way to import .dxf / .obj / .fbx with grasshopper.
I’ve seen some mentioned and tried a few solutions but unfortunately without any succes, hoping for some help with this post.

I’ve tried out this solution.

Script down below:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino


        
def importToGrasshopper(fileType, fileName, filePath):

    # check the input data
    if fileType:
        if fileType.startswith("."):
            pass
        else:
            fileType = "." + fileType
            
        supportedFileTypes = [".3dm", ".3ds", ".sat", ".ai", ".dwg", ".dxf", ".dae", ".cd", ".x", ".emf", ".gf", ".pm", ".kmz", ".gts", ".igs", ".iges", ".udo", ".fbx", ".obj", ".csv", ".x_t", ".pdf", ".ply", ".txt", ".pov", ".raw", ".rib", ".skp", ".step", ".stl", ".tsm", ".tss", ".vda", ".wrl", ".vmrl", ".gdf", ".wmf", ".x3dv", ".xaml", ".xgl", ".zpr"]
        if fileType in supportedFileTypes:
            pass
        else:
            print "File type %s is not supported" % fileType
            return
    else:
        print "Please input fileType"
        return
    
    if fileName:
        pass
    else:
        print "Please input fileName"
        return
    
    if filePath:
        if filePath.endswith("\\"):
            pass
        else:
            filePath = filePath + "\\"
    else:
        return
        print "Please input filePath"


    # geometryTypes functions


    fileNameAndType = fileName + fileType
    finalPath = filePath + fileNameAndType
    
    commandString = "_-Import " + finalPath + " _Enter _Enter _Enter" 
        
    done = rs.Command(commandString)
    if done:
        print "%s file successfully imported from: %s" % (fileNameAndType, filePath)



if Import:
    importToGrasshopper(fileType, fileName, filePath)

The script has some problems with the white spaces in the file path and can not import anything because of it.

Thank you :slight_smile:

1 Like

You can use the “Import 3dm” component in Rhino 7 to read all of the file formats that Rhino supports.

1 Like

oh wow, I did not realize that. Thanks for the tip!

Any idea why it’s still called “import 3dm” as it supports multiple formats?

1 Like

The component already existed as “Import 3dm” in Rhino 6. I added the ability to support non-3dm paths without creating a new component type in Rhino 7.

2 Likes

I see. Thanks.

Attached my GH file. Perhaps I’m doing something wrong. I have a system which checks for new .dxf files and checks if an export is already made to .fbx of the same .dxf. Can I use the import 3dm component in this way? I think I need a boolean toggle to determine which ones can be exported and which ones don’t have to. Struggling with the import geo method a bit.

ImportGeo.gh (19.4 KB)

1 Like

Strange enough .dxf are not supported?

1 Like

It should be. I drew a few curves in Rhino and exported them as a dxf. They came in fine with the import 3dm component

1 Like

I’ve changed the input from .dxf to .fbx and it all works now. Perhaps that is a better flow for me anyway :slight_smile:
Thanks for the help!

1 Like

Hi Remy -

I see that here and put it on the list as RH-65519.
Thanks,
-wim

1 Like

The DXF that you posted earlier was entirely composed of blocks. Grasshopper doesn’t support blocks. What do you think the component should do in cases like this?

2 Likes

Hi, @stevebaer any thoughts about this problem? @wim

1 Like

Replied in original thread

2 Likes

Hey,

I searched a way to import a lot of DXF files with Grasshopper in Rhino and i found in this Thread the Component Import 3DM. Thanks for that !

If i use Import 3DM its not working like i expected. U can see it in the following Screenshot. On the left we have the Grasshopper Version, on the right the Drag % Drop Version.

Also the way to create a block out of it with the file name is not working, i cant bake it.

Can anyone help me out to fix this ?

Thanks for your time !

Screenshot.1:

My data:

Screenshot.2:

DXF file:
Test.DXF (345.0 KB)

Is this Rhino 8?

And you want to write out each DXF as a Rhino 3dm?

So a list of 5 DXFs would result in 5 3DMs?

all DXF files in 1 3dm
It will be later over 1000 DXFs i will need in 1 3dm

Rhino 7:

Rhino 8: This time i had a error message, but it created the object again in all black with wrong text sizes.


There are two parts to this.

Here is how I would read in the DXF files and create blocks of each:

Of course the file names could be harvested for block names. This uses the Rhino 8 DataTypes and Import Content component.

The second is why the DXF is coming in black with font issues. I will take a look at that.

1 Like

This worked with the Test.DXF.

The definition above does not insert the Block instance. So to get these definitions actually set in Rhino, the Right-Click Bake on the Block definition to Bake it.

Or, use a component Cache to set the block definitions in Rhino.

1 Like

Thanks for the fast help !

Same Script, but at me all the Curves are missing. Rhino 8.

Version 8 SR6
(8.6.24101.5001, 2024-04-10)

Baked from Grasshopper

Script:

I am running 8.8, but that should not really matter.

Can I get the Grasshopepr definition? I will take a look why it is different.

I will PM you a link to today’s build?

1 Like

Here is my file i used the same DXF i uploaded before.

DXF_import_01.gh (10.1 KB)

U wrote: “I will PM you a link to today’s build?”
What do u mean with that, sending me your build, maybe your .gh file ?