Message 1 of 20
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I needed a tool that works as the Save and Replace command but I needed it to also make a copy of the original drawing and replace the reference of that drawing with the new component. I've written the rule below, which works great, but when the rule has finished Inventor seems to be stuck in an add to selection type of state (cursor shows a plus sign next to it). A simple hit of the Esc key clears it up but I was wondering if there is something I can code differently to exit cleanly. I'm relatively new to iLogic. Thanks.
Dim oDWGType As String = ".idw"
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oSelected As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'CHECK THAT ONLY ONE COMPONENT IS SELECTED
If oDoc.SelectSet.Count <> 1 Then
MessageBox.Show("ONE component must be selected.", "ERROR")
Exit Sub
End If
'ADD TO OBJECT COLLECTION
For i = 1 To oDoc.SelectSet.Count
If TypeOf oDoc.SelectSet.Item(i) Is ComponentOccurrence Then
oSelected.Add (oDoc.SelectSet.Item(i))
End If
Next
'CAPTURE OLD FILE INFORMATION
oOldDoc = oSelected.Item(1).Definition.Document
Dim oOldComp As String = System.IO.Path.GetFileName(oOldDoc.FullDocumentName)
Dim oOldIDW As String = System.IO.Path.ChangeExtension(oOldDoc.FullDocumentName, oDWGType)
'RUN Save&Replace COMMAND
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyBonusTools_SaveAndReplaceComponentCmd").Execute
'CAPTURE NEW FILE INFORMATION
oNewDoc = oSelected.Item(1).Definition.Document
Dim oNewComp As String = System.IO.Path.GetFileName(oNewDoc.FullDocumentName)
Dim oNewIDW As String = System.IO.Path.ChangeExtension(oNewDoc.FullDocumentName, oDWGType)
'EXIT IF Save&Replace WAS CANCELLED
If oOldComp = oNewComp Then
Return
End If
'OPEN OLD DRAWING
If System.IO.File.Exists(oOldIDW) Then
Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(oOldIDW)
'REPLACE REFERENCE
Dim oFD As FileDescriptor = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(oNewComp)
DrawingDoc.Update()
'SAVE NEW DRAWING
DrawingDoc.SaveAs(oNewIDW, False)
'REACTIVATE ASSEMBLY
oDoc.Activate()
Else
MessageBox.Show("A drawing file of the replaced component was not found.", "Missing " & oDWGType,MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
Solved! Go to Solution.