Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

help automating task

Anonymous

help automating task

Anonymous
Not applicable

Hello,

 

Can someone help me with and script to do the following steps:

I have a folder with dxf files

within that folder for every dxf file

 

-Start a new file

-import dxf to xy plane

-extrude simple profile (maybe click to select) to a standard lenght (100mm)

-save the file to the same name as the DXF file  "dxfname_3D"

-create a drawing using an existing template template

-save drawing file as "dxfname_drw"

-repeat until all files have been done.

 

Many thanks

Huba

 

0 Likes
Reply
Accepted solutions (1)
2,084 Views
15 Replies
Replies (15)

kandennti
Mentor
Mentor

Hi @Anonymous .

 

Fusion360API does not support the drawing.
Therefore, the following two are impossible.


-create a drawing using an existing template template
-save drawing file as "dxfname_drw"

0 Likes

Anonymous
Not applicable

OK. THanks for the reply.

 

Then just the firts part create 3d models from a batch of dxf with the same name???

0 Likes

kandennti
Mentor
Mentor

Because I do not understand English, I may not understand.

I think it is possible to import a DXF file, extrude it and save it with the same name.

0 Likes

Anonymous
Not applicable

Thanks for that.

 

Any chance you can share a solution??

0 Likes

Anonymous
Not applicable

Thanks for that.

 

Any chance you can share a solution??

0 Likes

kandennti
Mentor
Mentor

Business is busy and can not be started.
I will make it if you give me time.

0 Likes

Anonymous
Not applicable

Sure. Whenever you have time it will be good. Thanks

0 Likes

kandennti
Mentor
Mentor
Accepted solution

I'm sorry that I was late.

 

It may lack functionality, but it imports multiple DXF files, performs an extrusion,

and saves them under the same name as the DXF file.

 

The save destination is in the "importDXF" project.
(The account to which the "importDXF" project is logged in
If it does not exist, create it. )

 

#Fusion360API Python script
#Description-importDXF & Extend test

import adsk.core, adsk.fusion, traceback
from pathlib import Path

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
_prj = adsk.core.DataProject.cast(None)

# saving project name
_PROJECT_NAME = 'importDxf'

# Extend Distance(unit Cm)
_EXTENDDISTANCE = 10.0

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # select dxf files
        paths = getFilePaths()
        if len(paths) < 1: return

        # create document
        global _EXTENDDISTANCE
        results = [initFusionDoc(path, _EXTENDDISTANCE) for path in paths]

        # finish
        _ui.messageBox('\n'.join(results))

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def setDataProject():

    global _app, _PROJECT_NAME, _prj
    prj = adsk.core.DataProject.cast(None)

    for prj in _app.data.dataProjects:
        if prj.name == _PROJECT_NAME:
            _prj = prj
            return
    
    _prj = _app.data.dataProjects.add(_PROJECT_NAME)


def initFusionDoc(
    path :str,
    length :float
    ) -> str:

    pathObj = Path(path)
    adsk.doEvents()

    try:
        global _app
        typeFuDoc = adsk.core.DocumentTypes.FusionDesignDocumentType
        doc = _app.documents.add(typeFuDoc)
        des = adsk.fusion.Design.cast(_app.activeProduct)
        root = des.rootComponent

        # dxf import
        iptMng = _app.importManager

        dxfOpt = iptMng.createDXF2DImportOptions(path, root.xZConstructionPlane)
        dxfOpt.isViewFit = False
        skts = iptMng.importToTarget2(dxfOpt, root)

        # profile
        profs = adsk.core.ObjectCollection.create()
        for skt in skts:
            for prof in skt.profiles:
                profs.add(prof)

        # pad
        exts = root.features.extrudeFeatures
        newBodyOpe = adsk.fusion.FeatureOperations.NewBodyFeatureOperation
        dist = adsk.core.ValueInput.createByReal(length)
        exts.addSimple(profs, dist, newBodyOpe)

        # save
        global _prj
        if not _prj:
            setDataProject()

        doc.saveAs(pathObj.stem, _prj.rootFolder, '', '')

        return pathObj.stem + ' : OK'

    except:
        return pathObj.stem + ' : NG'


def getFilePaths() -> list:

    global _ui
    dlog :adsk.core.FileDialog = _ui.createFileDialog()
    dlog.isMultiSelectEnabled = True
    dlog.title = "Select Open DXF Files"
    dlog.filter = 'DXF files (*.dxf)'
    dlog.filterIndex = 0

    res = dlog.showOpen()
    if res == adsk.core.DialogResults.DialogOK:
        return dlog.filenames
    else:
        return []

 

 

 

 

0 Likes

Anonymous
Not applicable

Thank you very much for this much appreciated.

0 Likes

damien.huvelle
Enthusiast
Enthusiast

Hi, just found your reply in this post when searching about batch DXF importer.

 

Is there a way to modify your script to make him open those DXF in the same file and make them not stacked on each other but spaced from each other ?

With my job (wooden furnitures) I often need to import as many DXF that there is parts, so it would be very helpful.

 

thanks

0 Likes

kandennti
Mentor
Mentor

Hi @damien.huvelle .

 

After running the script, why not try using the pattern in the GUI?

0 Likes

damien.huvelle
Enthusiast
Enthusiast

@kandennti 

 

You script open different DXF in seperate files, I would like to open those in the same file (batch importing). I suggested to add that the DXF don't stacks on each other but side by side.

 

do you think it's possible ? you seems pretty good with scripting (not like me ...)

0 Likes

kandennti
Mentor
Mentor

I don't know a good algorithm for doing the placement.


However, by using the bounding box of component and occurrence
I think it is possible to arrange them so that they do not overlap.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-A2DF83DA-A919-446F-A8A9-3684635058E5 

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6E1510A3-3014-4958-8D03-878025C9F093 

 

Of course, I think it is possible to deploy with API.
(I don't have time to work on it now)

0 Likes

kandennti
Mentor
Mentor

I was able to secure time, so I repaired it.

An algorithm for optimal placement to avoid duplication I do not know.
Therefore, I simply arrange them side by side.

The process takes a little longer because you have to wait for the data panel to update.

 

↓The modified script is attached.

0 Likes

damien.huvelle
Enthusiast
Enthusiast

@kandennti 

hello, thanks for you work ! I finally found this on github which is made by tapnair. This is exactly what I was waiting for and I finally found it.

 

thanks

0 Likes