Working with Advance Steel Commands

Use the Advance Steel API to call Advance Steel commands.

Any command that can be executed from the command line in Advance Steel can be executed through the API. This includes Advance Steel commands, but also AutoCAD commands or commands from a plugin. The following example demonstrates the basics of calling commands using the API. It will select all objects in the model and hide them.

Code Region: Executing commands from the API

[CommandMethodAttribute("TEST_GROUP", "BasicCommandSample", "BasicCommandSample", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void BasicCommandSample()
{
    Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_ai_selall ", false, false, true);
    Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_HIDEOBJECTS ", false, false, true);
}
Note: The above example uses the Autodesk.AdvanceSteel.Runtime and Autodesk.AutoCAD.ApplicationServices namespaces.

When calling SendStringToExecute, the first parameter is the command to execute. It must start with an underscore and have a space after the name to complete the command. The remaining parameters are boolean values. The second parameter indicates whether to activate the target document. The third parameter indicates whether to queue the current active document to complete in the next OnIdle() event when switching active documents. The last parameter indicates whether the echo the command from the first parameter on the command line.

Calling commands from the API can be useful for accessing functionality that is not available through the API directly, but can also be used to execute any commands whether available in the API or not. In the following example, some Advance Steel objects in the model are deleted and the remaining ones are put into a selection set that is later exploded so the model can be opened in plain AutoCAD.

Code Region: Explode objects for AutoCAD

[CommandMethodAttribute("TEST_GROUP", "DeleteAndExplodeForAutoCAD", "DeleteAndExplodeForAutoCAD", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void DeleteAndExplodeForAutoCAD()
{
    Autodesk.AdvanceSteel.CADAccess.TransactionManager.startTransaction();
    DocumentManager.lockCurrentDocument();

    Autodesk.AdvanceSteel.CADLink.Database.ObjectId[] ids;
    List<Autodesk.AdvanceSteel.CADLink.Database.ObjectId> idsToExplode = new List<Autodesk.AdvanceSteel.CADLink.Database.ObjectId>();
    DatabaseManager.GetModelObjectIds(out ids);
    foreach (Autodesk.AdvanceSteel.CADLink.Database.ObjectId id in ids)
    {
        FilerObject obj = DatabaseManager.Open(id);

        if (obj != null)
        {
            FilerObject.eObjectType objType = obj.Type();
            switch (objType)
            {
                case FilerObject.eObjectType.kActConstructionElem:
                case FilerObject.eObjectType.kAtomicElem:
                case FilerObject.eObjectType.kAutoConstructionObject:
                case FilerObject.eObjectType.kBuildingStructureItem:
                case FilerObject.eObjectType.kBuildingStructureManager:
                case FilerObject.eObjectType.kBuildingStructureManagerListObject:
                case FilerObject.eObjectType.kBuildingStructureObject:
                case FilerObject.eObjectType.kBuildingStructureTreeObject:
                case FilerObject.eObjectType.kCamera:
                case FilerObject.eObjectType.kConnector:
                case FilerObject.eObjectType.kConstructionElem:
                case FilerObject.eObjectType.kFilerObject:
                case FilerObject.eObjectType.kLevelObject:
                case FilerObject.eObjectType.kMainAlias:
                case FilerObject.eObjectType.kModelViewObject:
                case FilerObject.eObjectType.kObjectsGroup:
                case FilerObject.eObjectType.kObjectsQuery:
                case FilerObject.eObjectType.kPassiveConstructionObject:
                case FilerObject.eObjectType.kSpecialPart:
                case FilerObject.eObjectType.kUnknown:
                case FilerObject.eObjectType.kUserAutoConstructionObject:
                case FilerObject.eObjectType.kWeldLevel:
                case FilerObject.eObjectType.kWeldPattern:
                case FilerObject.eObjectType.kWeldStraight:
                case FilerObject.eObjectType.kWorkArea:
                case FilerObject.eObjectType.kWorkingPlane:
                    obj.DelFromDb();
                    break;
                case FilerObject.eObjectType.kAnchorPattern:
                case FilerObject.eObjectType.kBeam:
                case FilerObject.eObjectType.kBeamFeatEdge:
                case FilerObject.eObjectType.kBeamMultiContourNotch:
                case FilerObject.eObjectType.kBeamNotch:
                case FilerObject.eObjectType.kBeamNotch2Ortho:
                case FilerObject.eObjectType.kBeamNotchEx:
                case FilerObject.eObjectType.kBeamShortening:
                case FilerObject.eObjectType.kBeamTapered:
                case FilerObject.eObjectType.kBentBeam:
                case FilerObject.eObjectType.kBentBeamBase:
                case FilerObject.eObjectType.kBoltPattern:
                case FilerObject.eObjectType.kCircleScrewBoltPattern:
                case FilerObject.eObjectType.kCompoundBeam:
                case FilerObject.eObjectType.kCompoundStraightBeam:
                case FilerObject.eObjectType.kConcreteBeam:
                case FilerObject.eObjectType.kConcreteBentBeam:
                case FilerObject.eObjectType.kConnection:
                case FilerObject.eObjectType.kConnectionFeature:
                case FilerObject.eObjectType.kConnectionHoleBeam:
                case FilerObject.eObjectType.kConnectionHoleFeature:
                case FilerObject.eObjectType.kConnectionHolePlate:
                case FilerObject.eObjectType.kCountableScrewBoltPattern:
                case FilerObject.eObjectType.kFeatureObject:
                case FilerObject.eObjectType.kFinitRectScrewBoltPattern:
                case FilerObject.eObjectType.kFoldedPlate:
                case FilerObject.eObjectType.kGrating:
                case FilerObject.eObjectType.kInfinitMidScrewBoltPattern:
                case FilerObject.eObjectType.kInfinitRectScrewBoltPattern:
                case FilerObject.eObjectType.kPlate:
                case FilerObject.eObjectType.kPlateContourNotch:
                case FilerObject.eObjectType.kPlateFeat:
                case FilerObject.eObjectType.kPlateFeatContour:
                case FilerObject.eObjectType.kPlateFeatEdge:
                case FilerObject.eObjectType.kPlateFeatShortening:
                case FilerObject.eObjectType.kPlateFeatVertFillet:
                case FilerObject.eObjectType.kPlateFeatVertex:
                case FilerObject.eObjectType.kPlateFeatWeldFillet:
                case FilerObject.eObjectType.kPlateFeatWeldPreparation:
                case FilerObject.eObjectType.kPlateFold:
                case FilerObject.eObjectType.kPlateFoldRelation:
                case FilerObject.eObjectType.kPolyBeam:
                case FilerObject.eObjectType.kScrewBoltPattern:
                case FilerObject.eObjectType.kSlab:
                case FilerObject.eObjectType.kStraightBeam:
                case FilerObject.eObjectType.kTimberBeam:
                case FilerObject.eObjectType.kUnfoldedStraightBeam:
                case FilerObject.eObjectType.kWall:
                    idsToExplode.Add(id);
                    break;
                default:
                    break;
            }

        }
    }

    UserInteraction.PutIntoSelectionSet(idsToExplode);
    Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_AstM4CommExplodeToAcis ", true, false, true); // call Advance Steel command to explode to ACIS

    Autodesk.AdvanceSteel.CADAccess.TransactionManager.endTransaction();
    DocumentManager.unlockCurrentDocument();
}

Command flow

After a command is sent with the SendStringToExecute() method, control must be returned to AutoCAD to allow the command to execute. When it is necessary to perform multiple commands, your plugin can register for an event to know when the command is done. As we saw in the Command Reactors section of the Walkthrough: Working with AutoCAD and AS API, you can register for the CommandEnded event to be notified when the command is complete. Once you get notification that the command is complete, the next command can be sent to execute.

Another event that is useful in this case is the EnteringQuiescentState event available from the active document's Editor. This event is triggered when AutoCAD is in an idle state, meaning no commands are executing.

Silent mode

Although any command that can be executed in Advance Steel can be executed with the SendStringToExecute() method, some commands open dialogs requiring input from the user to complete. In some cases, the dialogs can be disabled and the command will complete with default values. However, this does not work for all commands that invoke a dialog. To disable dialogs, prior to calling the command, call the command shown below.

Code Region: Disable dialogs

Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_AstM4SetDefault C0_SilentMode int 1 ", false, false, true);

This same command would need to be called later with the last parameter set to 0 to re-enable dialogs.