issue with SaveAs and kinking of files

issue with SaveAs and kinking of files

tmathieson
Advocate Advocate
655 Views
6 Replies
Message 1 of 7

issue with SaveAs and kinking of files

tmathieson
Advocate
Advocate

Hello All,

 

hope everyone had a ggod summer!.  i am having an issue with one of my rules that uses the "saveAs" command....

 

i have a 'seed' part, (say a block that's 4x4x4) that

  • 1.i inserted into an assembly
  • 2. rename the 'seed' to unique name using
doc.SaveAs(file_save, False)
  • 3. modify the parameters of new part,  (say 6x8x4 for block one, 8x3x1 for block 2, 5x10x4 for block 3, etc)
  • repeat 1-3 as needed
  • save assembly and parts

everything looks fine when the program finishes, blocks update accordingly. But... if i file the assembly, and parts, close it and open it again, all the blocks revert to the parameters of the last part entered ( in the example above all blocks would be 5x10x4 instead of 3 unique sizes).

 

not sure what is going on... tried changing the SaveAs option to true, but no dice....

 

maybe i have to close the 'new part' window before repeating steps 1-3 above?

 

thanks in advance for any help, insight, etc!

0 Likes
Accepted solutions (1)
656 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @tmathieson.  You may have to include your full code and maybe slightly more detailed order of operations, or bullet list you are doing for us to be able to more accurately diagnose the problem.  Is there a reason you are creating the parts individually within the assembly, using the new part command, instead of creating them normally outside the assembly, then inserting them?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

Curtis_Waguespack
Consultant
Consultant

Hi @WCrihfield 

 

Attached is a simple Inventor 2020 data set that might help you see the issue.

 

If you download these 2 files and place them in any folder you can then open the assembly and there is a rule in it that will place a block each time the rule is run (it'll create a Blocks folder next to the assembly and place the new files in it).

 

When the 2nd block is placed, the file is saved to disk as expected, but the BOM shows it to be using the same file as block 1

 

Curtis_Waguespack_1-1662754421201.png

 

But if I right click on Block2 in the browser, and look at the iProperties, it shows that it is actually the 2nd saved file.

 

Curtis_Waguespack_1-1662754998369.png

 

 

If I save and close the assembly at this point, then reopen it. I see that Block 1 and Block 2 are using the Block 1 file, just as @tmathieson describes.

 

Interestingly, if I place 5 more blocks, those all work as expected.

 

Curtis_Waguespack_0-1662754953840.png

 

 

I might just have a bug in my code, but I can't seem to see it. Or I might have recreated the issue described in the OP.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

 

EESignature

Message 4 of 7

tmathieson
Advocate
Advocate

Hi @WCrihfield  and @Curtis_Waguespack ,

 

thanks so much for having a look at this. as Curtis detailed,  in that the 'renamed part' reverts back to the seed part. interestingly , if i create a new assembly and insert the 'renamed parts', they act as expected, i.e. they are not related back to the seed part

 

i think my issue is that i'm thinking in 'the other software', when i insert a component into an assembly, rename and save it, that new renamed part replaces the original part in the assembly.  that doesn't seem to happen in Inventor?

 

here is a snippet of my code. since Friday, i have tried adding the "component.replace" command to force the update but it does not do it.

Dim componentA = Components.Add(PLATE_PRE & i, PLATE_DIRECTORY & BASE_TEMP2, position := Nothing, grounded := False, visible := True, appearance := Nothing)
		'Dim doc As Document
			doc= Component.InventorComponent(PLATE_PRE & i).Definition.Document
					file_delete = (ApATH & File_new_name)
					'check to see if file exists.  delte if it does
		If Dir(file_delete) <> "" Then
			'MessageBox.Show("it exists", "Title")
			Kill(file_delete)
		Else 
			'MessageBox.Show("no file in directory", "Title")
		End If
			'save new part 
	        doc.SaveAs(ApATH & File_new_name, False)
			Logger.Debug(ApATH & File_new_name)
			Component.Replace(PLATE_PRE & i, File_new_name, False)

i've also included a couple of screen shots of  the component list, a) -after my rule runs and files are named "****-Pn", and b) - after i set the names back to the file name, things look good.

c) - but after saving,closing and re opening,  you can see that i go from having a P2,P3,P4, to having 3 instances of P2... if i then manually replace each component, the proper files are added/replaced in the assembly as they should and assembly works properly.

 

i wish i could you my code to review, but that would also mean sending some propriety components, which my bosses are not keen on....

 

thanks again for your help with this!

 

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor
Accepted solution

I know that using SaveAs retains ancestry of the document, which is often very helpful when you need to replace a component, but this is ridiculous. 😏  Since I don't generally use this route for generating assembly components, the first thing that comes to mind is the ReplaceReference method.  That may work where a simple replace component may not work.  I wrote a short contribution post about using is method once.  You could give something like that a try and see if it works better for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7

tmathieson
Advocate
Advocate

Hey @WCrihfield ,

 

thanks for the link.  i will look into it, see what i can decipher. in your other reply, you asked " Is there a reason you are creating the parts individually within the assembly, using the new part command, instead of creating them normally outside the assembly, then inserting them?" short answer is I thought the SaveAs routine/rule  would work :^).... i am open to other options, i'm just not familiar enough with API and Ilogic to hammer that one out (yet). i'm sure the link provided will be helpful !

 

thanks so much, and will let you all know how it goes!

0 Likes
Message 7 of 7

tmathieson
Advocate
Advocate

Hey Welsey, thank you, thank you, thank you!!

 

the link to your contribution post did the trick!!!  i  just had to change my "SaveAs" command option from "false" to "true", modify the code to point to my file name variables, and voila, back in business!!!!

 

thanks again so much!! without help from you, @Curtis_Waguespack , and others, the hole would be deep.

 

thanks again, and have a great day (mine is a whole lot better!!)