private boolean clearStructure(Program program, ProgramLocation start, ProgramLocation end) {
		// get data at start
		boolean commit = false;
		int id = program.startTransaction("Clear Structure");
		try {
			Address dataAddr = start.getByteAddress();
			Data data = program.getListing().getDefinedDataContaining(dataAddr);
			if (data == null) {
				return false;
			}

			// get the structure to clear, make sure it is a structure
			Data compData = data.getComponent(start.getComponentPath());
			if (compData == null) {
				return false;
			}

			DataType dataType = compData.getParent().getBaseDataType();
			if (!(dataType instanceof Composite)) {
				return false;
			}

			// get the start offset into the data structure
			int index = compData.getComponentIndex();
			int endIndex = index;
			if (end != null) {
				// assume start and end relate to ths same composite
				int[] cpath = end.getComponentPath();
				endIndex = cpath[cpath.length - 1];
			}

			if (dataType instanceof Union) {
				Union union = (Union) dataType;
				for (int ordinal = endIndex; ordinal >= 0 && ordinal >= index; ordinal--) {
					union.delete(ordinal);
				}
			}
			else {
				Structure structure = (Structure) dataType;
				for (int ordinal = endIndex; ordinal >= 0 && ordinal >= index; ordinal--) {
					structure.clearComponent(ordinal);
				}
			}
			commit = true;
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			program.endTransaction(id, commit);
		}
		return commit;
	}
Clear the internal parts of a structure
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clear/ClearPlugin.java