Post #20 - Simple Export Utility

Simplify the export of ABAQUS part files to one of several CAD formats, with the option to scale the output to units of your choice and store to a user selected folder.
I have been distracted from blog posts by other things, I would love to say life, but other coding things which I hope to announce very soon. So today a simple one – a very brief dash through using the incredibly easy Really Simple GUI addon for ABAQUS to create a handy little plugin that makes exporting your ABAQUS models into CAD that bit easier.
I don’t normally advocate for GUIs, they add a load of code and complexity, but for many tasks they are helpful, making the inputs easier to manage and the user experience much better. For many GUIs in ABAQUS the Really Simple GUI, RSG, addon is all you need to produce an effective user interface. It does not include all the controls you might ever need, or all the functionality, but it will cover a lot of cases and it is quick and easy to use.
Scaling An Exported Part
ABAQUS is unit agnostic. I typically work assuming dimensions in meters as this keeps all input units in easy to understand SI units. Your mileage may vary. However, if you export a model in meters directly to a CAD system expecting parts in mm, my preferred units for drafting, then you end up with a blank model or a very, very, tiny one. This is not good.
Using the File->Export command directly does not apply a scale. So, the approach we shall take is:
Create a temporary copy of the part, which does allow a scale to be applied
Save the copy to a new CAD file format, either IGES, STEP, or SAT, in a user selected location
Delete the copy.
The GUI will have to allow the user to pick a part from a given model, define a scaling ratio and select an output location. The file dialog to choose the output should also be limited such that only approved CAD file types can be applied to the output.
The scaling factor is easy to do as a single number but rather than think about it we shall have selectors to choose from lists what the assumed ABAQUS units are and the desired CAD units will be. The program can then apply the scaling.
So, we need a model/part picker, two pre-filled lists and a file picker with file type options set. Sound a little daunting? Easy with RSG! Follow the five steps to GUI success below.
Step 1 - Open RSG
Open the RSG addon, Plugins->Abaqus->RSG Dialog Builder, and fill in the dialog title and press the Show Dialog button to see what you have made. An empty, titled, dialog will show:

Step 2 - Part Picker
Add the model and part picker. To do this select the combo box button from the palette on the left. Change the Type from Standard to MDB Repository, then select Parts from the model elements pull down. Make sure to give your keywords meaningful names, it will make the kernel script easier to understand. You should end up with something like the this:

Step 3 - Units Of Measure
Now add two more, Standard combo boxes. Populate these with the names of units of measure, in this case m, mm, in. These strings will be used as keys for a dictionary used in the scaling factor so ensure that the spelling is consistent and the order identical. Setting the default values is helpful.
The keywords will default to keyword01 etc, change this to meaningful names to make your kernel code easier to understand later. If the new elements do not appear in the right place in the hierarchy steer them into place using the arrows at the top of the dialog tree. You should now have something like this:

Part 4 - File Picker
Now add a file picking dialog, by selecting the launching button from the palette on the left and placing it at the bottom of the tree. Depending on you taste you can fix the width of the file path dialog by choosing how many columns it has. The part picker will scale with the name of the part and model at present, so you may not feel the need. Both can be fixed later if the completed dialog is saved as a standard dialog file.
The file type defaults to All Files (*). This is not helpful when we need to save the resulting file to one of three standard CAD export formats. This needs to be replaced with a text string that defines the CAD format in the style <label>(<format>)\n where <label> is say STEP and <format> is *.stp.
Unfortunately, RSG will only allow you to set up one file format at a time. In theory the string to setup multiple formats should be like this:
STEP(*.stp)\nIGES(*.igs)\nSAT(*.sat).
This does not work, showing only the last file type in the string. To enable multiple file formats we must edit the plugin code when it is saved as a standard dialog, more later. Your dialog should now look like this:

Part 5 - Tidy Up
The dialog is functionally ready, but it lacks a little finish. It is untidy, so we shall apply some element formatting to it. The Vertical Aligner can be a source of real trouble when you come to more complex GUIs but in this case it will do fine. Select it from the palette, place it at the bottom and then select the existing element directly above it and steer it into the aligner by hitting the right arrow. Repeat for all the elements and you should end up with a tidier dialog and a tree looking like this:

At this stage we have completed the dialog creation but there is no functionality, because there is no kernel script. If you click the OK button in the dialog it will produce a copy of the command string that will be sent to the kernel function for processing.

So, let’s follow the suggestion in the dialog and give this a kernel script to test.
The Kernel Script
First thing to do is save the dialog as an RSG plugin. Click the Save button at the top of the palette and choose a directory name and menu button. Save it in your home directory. This creates a directory and the files required to build and register the plugin.
Now create a kernel script in the same directory. I maintain a template kernel script file with the boiler plate already in place and save a copy into the current location, renaming the module and empty function as needed.
At the top of the RSG plugin Kernel tab are two boxes, one shows the module name, which is filled by selecting the kernel script module you have just placed in the plugin folder. The other is a pull down to choose the function that will be launched by the dialog, in this case I have called it Export. Its arguments must match those of the dialog command string, as here:

The Kernel tab allows you to search for the kernel script but not to create a new one. You can edit the script here once you have selected it. Personally, I never use this editor, VS Code being so much better, making edits in the RSG editor can become confusing. I would strongly recommend completing and testing your kernel script before connecting it to the dialog, make connecting the script to the dialog the last thing that you do.
The code for the kernel script is very straightforward as shown below. The scaling factor is determined by using the strings for the units as keys to a dictionary of multiplying factors. A dummy part is created and scaled as required. It is then exported.
Note that the export functions have been disabled in the Student versions for reasons best known to Dassault.

Multiple File Formats
The project as given so far, saving it as an RSG project type is fine, it works and it makes adding dialog elements or doing edits as simple as opening the file again via the RSG Builder. There is one annoying glitch though, and that is the ability to save to multiple file formats. The dialog will not let you choose multiple formats. The fix is very simple however.
First save the project as a Standard plugin. This will mean that it cannot be edited in RSG ever again so be sure you are done, or alternatively that you are comfortable with editing the standard file code.
Now open the dialog definition file, its name will end in DB rather than _plugin. Work down the class definition of xxxDB until you get to the place where the file handler is defined, search for fileHandler. In that line you will find something that looks like:

Simply extend the string for the file types as discussed above:

Conclusion
RSG provides a very simple way to generate useful, and sometimes quite complex, GUIs without needing to know how to write the interface code from scratch. It also provides an excellent starting point for more complex projects, allowing the UI to be sketched quickly and then extended as required.
I hope you find this little exporter useful. The full listing of the standard plugin is available on the downloads page.



Comments