article

Phil BoBo avatar image
8 Likes"
Phil BoBo posted Phil BoBo commented

Autodesk Interop Module Example Models

Example Usage of the New AutoCAD FlexScript API

The following example models were demonstrated at the Autodesk University presentation Elevating Factory Design: FlexSim and the Future of Autodesk Fusion Digital Factory. Refer to that presentation for a demo of these models and additional discussion regarding the topics demonstrated by these examples.

These examples require the Autodesk Interop FlexSim Module.

Healthcare Auto-Build Example

Demo_AutoCadAPI_ER_4.fsm

1730401410113.png

1730401557459.png

Using the new AutoCAD FlexScript API, the data within dwg files can be read using FlexScript to automatically build simulation objects within the model.

The script in this Healthcare example is contained in the AutoBuildFromDwg() user command in the Toolbox. This command reads the average location of blocks on the Bed Layer to create Bed Location objects. It also reads the lines on the Wall Layer to automatically create Wall objects and connect them to the A* Navigator for automatic pathfinding around the walls.

Reading dwg data

string filePath = param(1);
AutoCAD.Database db = AutoCAD.Database(filePath);
if (!db)
            return -1;
var iter = db.getBlockTable().getAt("*MODEL_SPACE").newIterator();
for (iter.start(); !iter.done(); iter.step()) {
            var ent = iter.getEntity();
            print("Entity:", ent.layer, ent.objectType);
            if (ent.layer == "Bed Layer") {
                        if (ent.is(AutoCAD.Polyline)) {
                                    AutoCAD.Polyline polyline = ent.as(AutoCAD.Polyline);
                        }
            }
}

Creating a bed location

treenode bedConfig = library().find("/people/Objects/Location>behaviour/eventfunctions/configs/Bed");
Object obj = Object.create("People::Location");
function_s(obj, "changeShape", bedConfig);

Creating walls

Object walls = Model.find("Walls");
if (walls) walls.destroy();
walls = Object.create("People::Walls");
treenode wallsSurrogate = walls.find(">visual/drawsurrogate");
Object libraryPillar = node("/?Pillar", library());
Object newPillar1 = createinstance(libraryPillar, wallsSurrogate);
newPillar1.setLocation(0.0, 0.0, 0.0);
Object newPillar2 = createinstance(libraryPillar, wallsSurrogate);
newPillar2.setLocation(10.0, 0.0, 0.0);
function_s(walls, "addWall", newPillar1, newPillar2);

Asserting the A* Navigator, a Grid, and connecting Walls

Object walls = Model.find("Walls");
Object aStarNavigator = model().find("AStarNavigator");
if (!aStarNavigator) {
            aStarNavigator = createinstance(library().find("?AStarNavigator"), model());
}
Object grid = aStarNavigator.find("Grid1");
if (!grid) {
            grid = function_s(aStarNavigator, "createGrid", 0, 0, 0, 1, 1, 0);
            grid.name = "Grid1";
}
contextdragconnection(grid, walls, "A"); 

AGV Read/Write Dynamic Blocks Example

POC_OHT_3_MoveOHB.fsm

POC_OHT_3_MoveOHB.dwg (If this file is named differently when you download it from Answers, make sure you name it back to this exact name. It is referenced by name in the model.)

1730401634702.png

1730401644179.png

1730401658664.png

The script in this AGV example is contained in the interopAutoCAD() user command in the Toolbox. This command reads the location and names of particular dynamic blocks in the dwg file in order to automatically create AGV path simulation objects based on the configuration of each type of dynamic block.

Additionally, the script has examples of both reading data and writing data back to the dwg based on modifications of the AGV paths within the simulation. The script is only partially complete as a demonstration of the API’s capabilities; the script is not a fully-working, robust solution for any arbitrary dwg.

Factory Design Utilities Proof of Concept Example

Demo_AutoCadAPI_FDU_1.fsm

1730401711027.png

1730401718991.png

1730401727177.png

This FDU example model contains many user commands in the Toolbox with various functionality. The primary example starts in the Load FDU Layout button’s OnPress code. By default, it calls the AutoBuildFromDwg() user command. Alternatively, it has unreachable example code for calling AutoBuildFromLayout(), which can read the layout data from an FDU LayoutData xml file rather than a dwg file.

The AutoBuildFromDwg() user command reads factory-specific meta-data about each FDU block in the dwg file and automatically creates simulation objects for each. The simulation objects then load the custom 3D shapes from FDU representing each of those objects. The import script also sets labels with the various Factory properties from each object. Within the CreateSimulationObjects() and CreateInternalObjects() user commands—called from the CreateFactoryAssetInstance() command—are hard-coded checks for particularly factory asset family ids to determine what type of simulation objects to create. This is merely a proof-of-concept example for handling FDU assets via FlexScript without any changes to FDU assets themselves. Future enhancements may include options for including such simulation meta-data within FDU assets directly for a more robust, easier-to-use solution.

This workflow brings all the new Autodesk interop features together for an exciting, new way to bring factory data into FlexSim. Once that data is in FlexSim, you can use its many existing features to analyze the system with live 3D animation and dashboard charts showing simulation results. You can validate the throughput of the layout, identify potential bottlenecks, and balance resource use.

flexscriptapiautocadautodeskinterop
· 6
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Martin K5 avatar image Martin K5 commented ·

Hi @Phil BoBo,

this is a great feature. However when I downloaded the Autodesk Interoperability FlexSim module to be able to read the .dwg file and autobuild the model, different models that include a big .dwg layout cannot simply load and open. As I tracked the overall performance, RAM is fully utilized (reaching 100%).


I have also tried openning these models in a different FlexSim version (without the AIF module) and everything works perfectly.


I am not sure if this can be a bug, but I wanted to let you know and ask for your opinion.


Thank you,


Martin

1 Like 1 ·
Phil BoBo avatar image Phil BoBo ♦♦ Martin K5 commented ·

Thanks for the feedback. We would need to test the dwg file to debug what is happening and what we can do about it. I'll send you an email.

0 Likes 0 ·
Sri_vikas K avatar image Sri_vikas K commented ·

Hi @Phil BoBo

I am trying to add the Autodesk InterOp into FlexSim. I downloaded the third-party file and placed the module in the FlexSim program files under the "module" folder. is this the correct way, Because I am unable to access the buttons when I click on them in dashboards in the model.
1730973823136.png

0 Likes 0 ·
1730973872008.png (52.0 KiB)
Phil BoBo avatar image Phil BoBo ♦♦ Sri_vikas K commented ·

You don't copy the installer into your modules directory. You run the Setup.exe within the folder:

1730995168558.png

1 Like 1 ·
1730995168558.png (92.8 KiB)
Alessio Merlo avatar image Alessio Merlo commented ·

Hi @Phil BoBo ,

can you share FDU and dwg file for the third example?

Otherwise I can't use and play with your POC.

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Alessio Merlo commented ·

FDU is part of Autodesk's Product Design & Manufacturing Collection.

https://www.autodesk.com/products/factory-design-utilities/overview

FDU is required to use the POC model I posted. The purpose of the model is to demonstrate data integration between applications. FlexSim, Factory Design Utilities, and the AdskInterop Module are all required for the POC model to work. The POC doesn't just read layout data generated from FDU; it reads ipt files from FDU's asset library, which requires FDU to be installed for this workflow.

0 Likes 0 ·

Article

Contributors

phil.bobo contributed to this article

Related Articles