file Does it possible to reorder elements in package

1 year 6 months ago #4644 by slavb18
Hi!

Does it possible to reorder elements in package?
E.g. mode "use case" element up and down. It is required becouse this affects order, how documentation is generated.

Only possibility I found is to move element to bottom, by drag and dropping it on "package" element itself.
But much convenient would be manual move to any position.

Or may be element reordering possible in script ?
E.g. could i, based on positions of use cases in use case diagram, reorder their appearance in package?

Please Log in or Create an account to join the conversation.

1 year 6 months ago #4645 by pan
Hi!

You can reorder elements in Package by using the reorder button (AZ with an arrow)in the toolbar or by right-clicking on the Package and selecting the Macros/Sort command.

This command is a macro.

You can create your own script to order the elements following your own rules.

The main principle to reorder elements is as follows:
#Create a comparator function
def eltCompare(a, b):
	return cmp(a.getName(), b.getName())

def sortPackage(package):
	#Declare an array which will contain the elements that will be reordered
	ownedElements = []
	for elt in package.getOwnedElement():
		ownedElements.append(elt)
	#Remove elements from the package
	package.getOwnedElement().clear()
	#Sort the elements of the array
	ownedElements.sort(eltCompare)

	#Add the elements to the package
	for elt in ownedElements:
		package.getOwnedElement().add(elt)

#Please note that in this example selectedElements must be Packages   
for element in selectedElements:
	sortPackage(element)

Hope this helps

Please Log in or Create an account to join the conversation.

1 year 6 months ago #4646 by slavb18
Thanks!

Please Log in or Create an account to join the conversation.

Moderators: tmaebr
Time to create page: 0.033 seconds
^ Back to Top