How to replace a component occurrence which has the same name.

How to replace a component occurrence which has the same name.

davidt162003
Advocate Advocate
464 Views
3 Replies
Message 1 of 4

How to replace a component occurrence which has the same name.

davidt162003
Advocate
Advocate

So I have an assembly which is made up of parametric template parts. Before I attempt to update the parameters I want to make sure that its using the latest version of the template, Which i can tell by using an Iproperty on the part. 

 

Im able to delete the occurrence and  the file in the file system but I keep having issues occur when try to create the new version. 

originally I was trying to do this by opening the template part document and using .SaveAs but that threw an error, so instead I used vb.nets filesystem.filecopy.  this allowed me to create a new file under the same name, but I began having errors when I tried to actually use it, such as:

  • Part is referenced in another context
  • Part has been updated elsewhere  

What I think is happening is that somewhere the old version is being remembered/Referenced, but I don't know where.  I make sure to both update and save the assembly and the subassembly if the part was in one, but I still get the errors. So maybe its being remembered somewhere else and I need to do an extra step?? 

 

Dose anyone else have another good method or some fix for this?

HII
0 Likes
Accepted solutions (1)
465 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @davidt162003.  You may need to consult the folks at Autodesk directly about this type of issue.  I have seen very similar posts on the forum many times before over the years which mention the actions of deleting a file, then recreating another file with the same name, then encountering these types of issues.  I could be wrong, but I do not think there is a solution or way to 'fix' this issue/behavior.  I think it is simply a limitation.  You may need to find a different way to accomplish your end goal, besides deleting, then recreating a new file with the same exact name, in the same exact place as before, all by code.  I know of a couple commands for clearing iLogic's memory, iLogic's clipboard, or maybe iLogic's Log, but I do not know of a method or command for clearing Inventor's general session memory at the application level.   This may even be an operating system level issue.

 

You can try using the Document.ReleaseReference method on that document object, if it was not loaded into Inventor's session memory by opening an assembly or drawing that references it, followed by using the Documents.CloseAll method, and specifying True, which implies you only want to close all 'unreferenced' documents.  You can only release the reference to a document when it is is not currently being referenced by any other currently open documents though.  You can also try using the FileManager.RefreshAllDocuments method, but that does not really sound that promising.  There is also the Application.MRUEnabled & Application.MRUDisplay properties, where MRU essentially means 'Most Recently Used', where it would normally list the recently accessed files.  These are just a few ways that 'may' help 'clean-up' after working with files that are no longer being referenced by any other currently open documents, when you are done with them.  But I am not sure that taking any of these steps will solve this type of problem though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

davidt162003
Advocate
Advocate

Hmm that's disappointing 

Currently I'm trying to close done inventor after deleting the part. I'm able to keep running commands because i drive inventor through an external EXE rather than a add-on/Ilogic. 

Do you think this route might work? 

Im still getting a few errors  but at the moment most of them look to be because I haven't started up the same way I usually do, IE telling the app to be visible. 

HII
0 Likes
Message 4 of 4

davidt162003
Advocate
Advocate
Accepted solution

After alot of work along with going back and forth with AutoDesk support we were eventually able to find a working method. I'm hoping to write it out properly later but here is a summary just in case anyone needs it.

1. delete the existing occurrence from the assembly using delete2(true)

2. Close the connected document using .close(true)

3. delete it from the disk using system.io.file.delete then use  system.io.file.copy to create a new file under the same name 

4. then place your newly created occurrence into the assembly.

The main thing which is done differently here than any other method I've attempted is to use the system.io.file to copy the file template rather than using the inventor saveas function. 

HII