ide scripting creates double/triple:... property definitions in the same class

I use the following script to either create or update class properties.
When I run the script to add the properties, it works correctly and the properties are created
When I run the script again to update the properties, it works correctly and the properties are updated.
When I run the script once again to update the properties, it still works correctly and the properties are updated.

When I then close the project, and run the script again, the properties are not updated, but created again with the same name as the existing property.

When I then close the project again, and run the script once again, the properties are again not updated, but created once again with the same name as the existing property (we now have three properties with the same name in the same class.

For a video showing what happens idescriptingproblem video

I made a feedback ticket: <https://xojo.com/issue/51737>

Anyone know how to make sure the existing property is updated correctly? Is there a bug in my script, or if not, is there a workaround ?
Any ideas? @Greg O’Lone @Norman Palardy

OpenFile "/Users/dirkcleenwerck/Documents/scripttest/ScriptTest.xojo_binary_project"
Dim selected As Boolean = SelectProjectItem("APICallDocs")
If selected = False Then 
   Print "Something went wrong selecting APICallDocs"
Else
   if location = "APICallDocs.v1_Contacts_GET" Then
      Print "APICallDocs.v1_Contacts_GET Updated"
      ChangeDeclaration("v1_Contacts_GET", "Updated", "String", 0, "")
   Else
      Print "APICallDocs.v1_Contacts_GET Created"
      DoCommand("NewProperty")
      ChangeDeclaration("v1_Contacts_GET", "Created", "String", 0, "")
   End If
End If

selected = SelectProjectItem("APICalls")
If selected = False Then 
   Print "Something went wrong selecting APICalls"
Else
   If location ="APICalls.v1_Contacts_GET" Then 
      Print "APICalls.v1_Contacts_GET Updated"
      ChangeDeclaration("v1_Contacts_GET","Updated","String", 0,"")
   Else
      Print "APICalls.v1_Contacts_GET Created"
      DoCommand("NewProperty")
      ChangeDeclaration("v1_Contacts_GET","Created","String", 0,"")
   End If
End if

DoCommand("SaveFile")
location = "APICallDocs.v1_Contacts_GET"
// Save active project
Print "Project Saved"

It looks like Norman has replied to this in Feedback. A correction to the script should fix it.

In case someone else has this problem:

I assumed this

if location = "APICallDocs.v1_Contacts_GET" Then

would automatically try set the location and it would fail if it was not there.

Apparently this does not set the location, but only tests if this is the location.
So you need to try to set the location first, and then test for it
Like this:

location = "APICallDocs.v1_Contacts_GET"  
if location = "APICallDocs.v1_Contacts_GET" Then

And yes you can make double/triple properties with the same name through scripting. That’s a known bug, so pay attention that you do not do this.

Thanks to @Norman Palardy and @Jason Parsley for looking into this for me.
Much appreciated.