Replace component if not exist

Replace component if not exist

atomic.lex
Enthusiast Enthusiast
639 Views
2 Replies
Message 1 of 3

Replace component if not exist

atomic.lex
Enthusiast
Enthusiast

 

 

Hi all,

 

 i make an assembly this some ilogic options and want to use it by some other computers. Some names of components going lost by making a copy, becouse some file have been renamed. Inventor asks to find find  them. Can I use some ilogic rules to replace them without a dialog this some other components, if i know new file names of component?

 

I use this code:

 

oDoc = ThisDoc.Document
Dim refDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim refDoc As Document
Dim oPath As String = ThisDoc.Path  
Dim FileName As String = PROTOTYPE
Dim ExPath As String = "I:\"
	ExFileNPath = ExPath & "\" & FileName
Dim NewPath As String = Left(oPath, InStrRev(oPath, "\"))  & "Artikel"

For Each refDoc in refDocs
	Component.Replace("Prototype", ExFileNPath, True)
	Try
		If refDoc.DisplayName = FileName Then
			If System.IO.File.Exists(NewFileNPath) Then
				My.Computer.FileSystem.DeleteFile(NewFileNPath, _
				Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, _
				Microsoft.VisualBasic.FileIO.RecycleOption.DeletePermanently)				
			End If 
			refDoc.SaveAs(NewPath & "\" & FileName, False)
		End If
	Catch
		MessageBox.Show("Try again")
	End Try
Next

 

But i want to use only if component not exists before Inventor opens a browser windows for searching

0 Likes
640 Views
2 Replies
Replies (2)
Message 2 of 3

HermJan.Otterman
Advisor
Advisor

I'm not sure what you main exactly but.....

 

before You use component names in iLogic code first CHANGE the name of the components in the Inventor browser!!

by doing that the names in the browser (occurrence names) don't change again when you replace a part, or do a copy design.

 

this is one of the first an important rules of iLogic...

what you change the name in is not important. what I do most of the time....

 

Part01:1   change in Part01_1

 

I change the : in a _  so I can see I have chaged the name for my iLogic code

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 3

atomic.lex
Enthusiast
Enthusiast

 

Thanks Herm,

 

 i do exact, what you mean. But a part as a file could be deleted and its reference would be brocken. I want to repair this reference before Inventor ask me to search for the deleted component. I have find a solution by putting this component in another network folder with no ability to delete it.

 

Have a nice day ☺

 

Atomic Z

 

0 Likes