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: 48
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: 11

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.
 

Cator

Senior Member
@NateLiquidGravity
I noticed that the progress bar remains active based on the hardware and complexity of the sketch derived from the face projection. I added a delay after line 51 (after opening the AD_DRW) and noticed that it almost always works. In your opinion, is it possible to link the time.sleep(?) delay to the quantity of projected entities? That is, if it finds a complex sketch it just needs to be zero while if it finds a complex sketch it waits more seconds?
 

stepalibre

Alibre Super User
That is, if it finds a complex sketch it just needs to be zero while if it finds a complex sketch it waits more seconds?
Did you mean if it finds a simple sketch it just needs to be zero while if it finds a complex sketch it waits more seconds?

I'm eager to hear from Nate. My experience with AD/Alibre Script complexity and processing timing, has been mixed and often inconsistent. I wouldn't link the quantity of entities with time or thread sleeping. There are more factors involved. How will you determine if a sketch is complex? The script could count the entities beforehand to estimate, but that itself would take time. When I sleep/delay I use a fixed number, it is the most safe and reliable for me.
 
Last edited:

Cator

Senior Member
Did you mean if it finds a simple sketch it just needs to be zero while if it finds a complex sketch it waits more seconds?

I'm eager to hear from Nate. My experience with AD/Alibre Script complexity and processing timing, has been mixed and often inconsistent. I wouldn't link the quantity of entities with time or thread sleeping. There are more factors involved. How will you determine if a sketch is complex? The script could count the entities beforehand to estimate, but that itself would take time. When I sleep I use a fixed number, it is the most safe and reliable.
Exactly. The complexity in my ignorance is given by the amount of geometric entities involved in the export, but I'm curious to understand if this is data that can be accessed.
 

stepalibre

Alibre Super User
Exactly. The complexity in my ignorance is given by the amount of geometric entities involved in the export, but I'm curious to understand if this is data that can be accessed.
You mean IADSketchFigures.Count? That wouldn't tell you how long each entity will take to process. Line segments are simpler than a spline. I don't think it matter.

For example:
This project reads/writes figure data. In my tests using V27 headless/GUI-less programs are much faster overall but there's not much difference in processing GUI vs GUI-less.

1721277085505.png

I'm not exporting a DXF. I am creating folders and files, and writing the data to txt and json for each figure in a sketch.
 
Last edited:

NateLiquidGravity

Alibre Super User
In my experience with Alibre Design and AlibreScript - it's often a problem of threading and/or what I can best describe as Alibre Design is built like client/server. Sometimes the client asks for something and the server returns but hasn't finished yet so you don't get the correct answer. This can be seen in the API help somewhere - it is suggested to loop until a helpful answer is given. I don't remember what article. Putting in a sleep will let that thread rest and give the server side time to respond.
 
Top