ILOGIC Save Assembly, Copy & Replace Specified Parts

ILOGIC Save Assembly, Copy & Replace Specified Parts

waldie.jonathan
Enthusiast Enthusiast
4,277 Views
21 Replies
Message 1 of 22

ILOGIC Save Assembly, Copy & Replace Specified Parts

waldie.jonathan
Enthusiast
Enthusiast

Hi Everyone,

I've been splicing some code together in order to create a rule that will 'Save As' an assembly file as well as copy and replace specific components. The problem I am having is figuring out how to specify the parts I want it to copy. There are parts as well as hardware in the assembly and I only want it to copy and replace the part files. Right now I am using "refDoc.DisplayName.EndsWith" to reference a part, but I need to reference multiple parts with different names. I assume I would use some sort of loop. I am new to and self taught in working with code so any help would be appreciated!

 

SyntaxEditor Code Snippet

InvDoc = ThisDoc.Document
 Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments
 Dim refDoc As Document
 Dim mypath As String
 mypath = InputBox("Specify Path", "Enter Desired Path", "") + "\"
 
 
 
 For Each refDoc in refDocs
 MessageBox.Show(refDoc.DisplayName)

If refDoc.DisplayName.EndsWith ("-A")= True Then

component. Dim newpartname As String newpartname = refDoc.DisplayName + InputBox("Specify Quote Extension", "Enter Desired Part Extension", "") Dim NewFileName As String 'input box to enter new file name NewFileName = newpartname 'NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name",refDoc.DisplayName) 'if the new file name is blank then use the same name If NewFileName = "" Then NewFileName = refDoc.DisplayName End If 'if the user also types in the extesion then remove the extension. If NewFileName.EndsWith(".ipt") = True Then NewFileName = NewFileName.substring(0,NewFileName.length-4) 'MessageBox.show(NewFileName) End If 'if there is a change in the name then do the following. If refDoc.DisplayName <> NewFileName & ".ipt" Then 'check to see the file already exist. if it does then replace. If System.IO.File.Exists(mypath & NewFileName & ".ipt") Then Component.Replace(refDoc.DisplayName, mypath & NewFileName & ".ipt", True) Else Dim oldName As String = refDoc.DisplayName 'if it does not exist then recreate the file refDoc.saveas(mypath & NewFileName & ".ipt",False) ' Call UpdateDrawing(Path, oldName, NewFileName) End If FileChange = True End If End If Next If FileChange = True Then NewAssemblyName = InputBox("What is the new file name for the assembly?", "New Assembly File Name",iProperties.Value("Project", "Part Number")) If NewAssemblyName <> "" Then Dim oldName As String = ThisDoc.FileName(True) 'include extension ThisDoc.Document.SaveAs(mypath & NewAssemblyName & ".iam" , False) ' Call UpdateDrawing(Path, oldName, NewAssemblyName) End If End If iLogicVb.UpdateWhenDone = True
4,278 Views
21 Replies
Replies (21)
Message 21 of 22

cencinaNB2ET
Advocate
Advocate

HI,

Did the code work?

It seems i cant find any other reference to a similar subject in the forum.

 

 

0 Likes
Message 22 of 22

P_Korgaonkar
Advocate
Advocate

Hello,

 

It seems to work till some point.

 

Creates new parts and sub assembly with additional character at the end "_ "

 

I don't have any experience with coding of such type or detail, so could not work on it.

 

If you improve it further please let me know.

 

Regards

Parag

0 Likes