What's new

Script Release: Export Part Views as DXF

NateLiquidGravity

Alibre Super User
Export Part Views as DXF will show a dialog allowing you to pick the part and set the export path and name for the DXF. Then it will create a drawing, create a blank sheet, create all the standard views (left, front, right, back, top, bottom, top left, top right, bottom left, & bottom right) at 1:1 scale, export the dxf, and close the drawing.
 

Attachments

  • Export Part Views as DXF.py
    3 KB · Views: 35
Last edited:

Cator

Senior Member
Nate really did an excellent job. It far surpasses the autohotkey script that we did some time ago... I noticed that after the export the Progress bar remains open even if the console says that it has exited the script. It even remains open if all the windows except the main one remain open. You need to close the main window. It seems some process remains open....Regards,
Francesco
 

GeraldH

Member
Nate, thanks for sharing this!
Creating DXFs is a time consuming yet simple task. I don't understand why Alibre wouldn't be eager to put a DXF function directly into their program.
We have been using a AHK script that I cobbled together that mostly works. But I think this script could be an improvement over that.

However, this script is throwing an error for me on parameter: length; length can not be less than zero. Any help on what is the cause?

-Gerald
 

Attachments

  • Screenshot 2024-01-23 094927.jpg
    Screenshot 2024-01-23 094927.jpg
    10.8 KB · Views: 10

NateLiquidGravity

Alibre Super User
However, this script is throwing an error for me on parameter: length; length can not be less than zero. Any help on what is the cause?
I can't say for certain, but I put very little error checking in there. My first guess is that you are running it with a part that has not been saved yet so the file name of the part is blank when it tries to add the views.
 

cadtec

Senior Member
Hi Nate,

Great, you can make good use of it!
Works perfectly so far.

Best Regards
André
 

NateLiquidGravity

Alibre Super User
Yes, just change this line:
Python:
    test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES, 1.0, 1.0, ADViewOrientation.AD_FRONT | ADViewOrientation.AD_BACK | ADViewOrientation.AD_LEFT | ADViewOrientation.AD_RIGHT | ADViewOrientation.AD_TOP | ADViewOrientation.AD_BOTTOM | ADViewOrientation.AD_TOP_LEFT | ADViewOrientation.AD_TOP_RIGHT | ADViewOrientation.AD_BOTTOM_LEFT | ADViewOrientation.AD_BOTTOM_RIGHT , point_orgin)
To this:
Python:
    test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES, 1.0, 1.0, ADViewOrientation.AD_FRONT, point_orgin)
Keep in mind though that depending on how you made the part the Front may not necessarily be the front you need.
 

NateLiquidGravity

Alibre Super User
A sheet metal part can be projected to flat pattern with bend center lines by changing the ADDetailingOption in that line like so:
Python:
    test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_PROJECT_FLAT_PATTERN | ADDetailingOption.AD_BEND_CENTERLINES, 1.0, 1.0, ADViewOrientation.AD_FRONT, point_orgin)
 

HaroldL

Alibre Super User
Great automation of mundane tasks. I recall that when I was working, SolidWorks had a utility that I used to export the Flat pattern dxf for all the drawings in my working directory. I could select the directory with the files I wanted to export the dxf's from, the path for saving them, and even a time to start the process. I would set it up to export all the flat patterns for a project, that could be as few as 1 or as many as 15-20 or more drawings, then go to lunch and let it run on its own. That saved my sanity quite a few times since it can be monotonous exporting the dxf on all those drawings manually.
 

albie0803

Alibre Super User
Keep in mind though that depending on how you made the part the Front may not necessarily be the front you need.
The directions correspond with the viewcube so I have modified the code to

Python:
    test_sheet.ModifySheetBlank('Working Please Wait', 1.0, 1.0, ADUnits.AD_CENTIMETERS, 1.0, 1.0)
#    test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES, 1.0, 1.0, ADViewOrientation.AD_FRONT | ADViewOrientation.AD_BACK | ADViewOrientation.AD_LEFT | ADViewOrientation.AD_RIGHT | ADViewOrientation.AD_TOP | ADViewOrientation.AD_BOTTOM | ADViewOrientation.AD_TOP_LEFT | ADViewOrientation.AD_TOP_RIGHT | ADViewOrientation.AD_BOTTOM_LEFT | ADViewOrientation.AD_BOTTOM_RIGHT , point_orgin)
    if Values[3] == 'F' or Values[3] == 'f':
      test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES, 1.0, 1.0, ADViewOrientation.AD_FRONT, point_orgin)
    elif Values[3] == 'L' or Values[3] == 'l':
      test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES, 1.0, 1.0, ADViewOrientation.AD_LEFT, point_orgin)
    elif Values[3] == 'T' or Values[3] == 't':
      test_sheet.CreateStandardViews(str(part_path), ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES, 1.0, 1.0, ADViewOrientation.AD_TOP, point_orgin)
    my_drawing.ExportDXF(OutputFile)
    time.sleep(1)
    my_drawing.Close(0)
    print('Exported: ' + str(OutputFile))
    print('Done')
    return

Options = []
Options.append(['Select part', WindowsInputTypes.Face, None])
Options.append(['File', WindowsInputTypes.SaveFile, None, 'File', 'DXF|*.dxf', '.dxf'])
Options.append(['Label', WindowsInputTypes.Label , 'Export a drawing view of a part 1:1 as a DXF. Check the ViewCube for the appropriate face.'])
Options.append(['Enter the VC Face Letter: F L T', WindowsInputTypes.String, 'F'])
Win.UtilityDialog('Export Part Views as DXF', 'Export', ExportFaceDXF, InputChanged, Options, 300)

Is there a code method to toggle saving to M-Files? The code works but I get an M-Files popup and the progress bar never goes away.
 
Last edited:

NateLiquidGravity

Alibre Super User
I don't know how to avoid the dialog for saves to M-files. In AutoHotkey I would easily fill in M-files data as required and use WinWaitClose to wait for that dialog to close before closing the drawing session. I don't know how to achieve that without AutoHotkey. However if no automation is needed you could remove the line my_drawing.Close(0) and manually close the drawing window when done entering the M-files data.
 

albie0803

Alibre Super User
It didn't make any difference. This is the popup I get and I can live with it.
1706675008235.png
Never mind, I love what it does though! Thanks for the code.
 
Top