iLogic Form/Rule to copy/replace/reuse components

iLogic Form/Rule to copy/replace/reuse components

J.Oye
Advocate Advocate
298 Views
1 Reply
Message 1 of 2

iLogic Form/Rule to copy/replace/reuse components

J.Oye
Advocate
Advocate

I have been searching high and low for If there's away to have a form be utilized that would do the same thing as the design assistant when closed out of files where you can select whether you want to reuse, copy or replace components.  I don't want to have to enter prefix or suffix per copied component just be able to rename them entirely.  design assistant is a great tool I just want the user the ability to do it in the assembly they have actively open.  Specifying folder location for copied components would be great as well.

 

Thanks in advance!!!!

0 Likes
299 Views
1 Reply
Reply (1)
Message 2 of 2

j.brodersen
Enthusiast
Enthusiast

Hi J.Oye

 

I'm new to vba/Ilogic programming but I think that a slightly modded version of save-copy-and-replace-with-i-logic 

is what you are looking for!?

 

I would guess that following code in an assembly would do the job

Sub Main()


Dim dialog As New System.Windows.Forms.FolderBrowserDialog()

If dialog.ShowDialog()= System.Windows.Forms.DialogResult.OK Then 
	NewPath = dialog.SelectedPath 
	MsgBox(NewPath)
End If  



 Dim Path As String = NewPath

 Dim FileChange As Boolean = False

 

 InvDoc = ThisDoc.Document

 Dim refDocs As DocumentsEnumerator = InvDoc.AllReferencedDocuments

 Dim refDoc As Document

 

 For Each refDoc in refDocs

 'MessageBox.show(refDoc.DisplayName)

 

 'input box to enter new file name

 NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", refDoc.DisplayName)

 'NewFileName = InputBox("What is the new file name for " & refDoc.DisplayName & "?", "New File Name", iProperties.Value(refDoc.DisplayName, "Project", "Part Number"))

   

     '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 an 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(Path & NewFileName & ".ipt") Then

             Component.Replace(refDoc.DisplayName, Path & NewFileName & ".ipt", True)

         Else

             Dim oldName As String = refDoc.DisplayName

             'if it does not exist then recreate the file

             refDoc.saveas(Path & NewFileName & ".ipt",False)

             Call UpdateDrawing(Path, oldName, NewFileName)

         End If

       

         FileChange = True

     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(Path & NewAssemblyName & ".iam" , False)

         Call UpdateDrawing(Path, oldName, NewAssemblyName)

     End If

 End If

 

 iLogicVb.UpdateWhenDone = True

 

 End Sub

 

 Private Sub UpdateDrawing (ByVal Path As String, ByVal oldName As String, ByVal newName As String)

     Dim oDestinationDoc As DrawingDocument

     Dim strFileExtension As String = oldName.substring(oldName.Length-4,4)

     oldName = oldName.substring(0,oldName.Length-4)

     Dim sFileName As String = Path & oldName & ".idw"

   

     Try

         If System.IO.File.Exists(sFileName) Then

             oDestinationDoc = ThisApplication.Documents.Open(sFileName)

             oDestinationDoc.saveas(Path & newName & ".idw",False)

             Dim oDocDescriptor As DocumentDescriptor

             oDocDescriptor = oDestinationDoc.ReferencedDocumentDescriptors.Item(1)

   

             Dim oFileDescriptor As FileDescriptor

             oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor

           

             oFileDescriptor.ReplaceReference(Path & newName & strFileExtension)

             oDestinationDoc.Update()

             oDestinationDoc.Close

         End If

     Catch

         oDestinationDoc.Close

         MessageBox.Show("error")

     End Try

 

 End Sub
0 Likes