void createInternalStructure() throws UsrException {

		if (selection.getNumRanges() != 1) {
			throw new UsrException("Can only create structure on a contiguous selection.");
		}

		FieldRange fieldRange = selection.getFieldRange(0);
		int minRow = fieldRange.getStart().getIndex().intValue();
		int maxRow = fieldRange.getEnd().getIndex().intValue();
		int selectedRowCount = maxRow - minRow;
		if (selectedRowCount == 1) {
			// Popup are you sure dialog.
			int choice = OptionDialog.showYesNoDialog(provider.getComponent(),
				"Create Structure From Selected Components",
				"You only have a single component selected.\nAre you sure you want to create a structure from the selection?");
			if (choice == OptionDialog.NO_OPTION) {
				// If user chooses no, then bail out.
				return;
			}
		}

		if (isEditingField()) {
			endFieldEditing();
		}

		DataTypeManager originalDtm = getOriginalDataTypeManager();
		CategoryPath originalCategoryPath = getOriginalCategoryPath();
		String uniqueName = getUniqueDataTypeName(originalCategoryPath, "struct");

		String specifiedName =
			showNameDialog(uniqueName, originalCategoryPath, viewComposite.getName(), originalDtm);
		if (specifiedName == null) {
			return;
		}

		TaskLauncher.launchModal("Create Structure", monitor -> {
			try {
				doCreateInternalStructure(originalDtm, originalCategoryPath, specifiedName,
					monitor);
			}
			catch (UsrException e) {
				setStatus(e.getMessage(), true);
			}
		});
	}
Returns the number of bytes that are included in the current selection
range.

@param range the range of indices for the component's whose sizes should
be added together.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java