Packaged Blocks

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Packaged Blocks

Postby Tesla011 » Wed Mar 01, 2023 4:01 am

Hi All,
How can I get all Blocks in the Package using OpenAPI and Beanshell?

Thanks,
Tesla011
Tesla011
Forum Newbie
Forum Newbie
 
Posts: 13
Posts Rating:0
Joined: Sun Aug 15, 2010 5:29 pm

Re: Packaged Blocks

Postby yu3333 » Fri Apr 07, 2023 8:57 am

Given the id of the package, you can try with this:

Code: Select all
Project project = Application.getInstance().getProject();

if (!SessionManager.getInstance().isSessionCreated(project)){
SessionManager.getInstance().createSession(project,"MySession");
}

String idPackage =  ... ;
Package thePackage = project.getElementByID(idPackage);             
Collection<PackageableElement> allElements = thePackage.getPackagedElement();

for (PackageableElement ele : allElements) {                       
    if(StereotypesHelper.hasStereotype(ele, "Block")){
        print("Found: " + ele.getName());
    }
}

SessionManager.getInstance().closeSession();
yu3333
Forum Newbie
Forum Newbie
 
Posts: 7
Posts Rating:0
Joined: Wed Mar 29, 2023 1:09 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests