Very simply - the scripting commands AssignItem an unAssignItem do not work for weapon attachments.
The commands work for NVGs for example but do not move weapon items to/from the inventory. In some cases they will delete the weapon from inventory but not attach to gun. The same applies whether the slot is empty or full.