Issue with iPart/iAssembly Member File Generation

Issue with iPart/iAssembly Member File Generation

arkelec
Collaborator Collaborator
376 Views
2 Replies
Message 1 of 3

Issue with iPart/iAssembly Member File Generation

arkelec
Collaborator
Collaborator

I seem to have entered the 7th Circle of Hell.

I have been using some iLogic code to generate all member files of an iPart or iAssembly.

I run the code, the parts are generated & I'm not prompted to save the ipart or iAssembly file when done.

However on a seemingly random basis, if I add the iPart of iAssembly to another assembly, I'm prompted to save the instance.  If I do, I'm then prompted to update the original iPart or iAssembly when I open that file, which of course then requires a save.

Then if I open any file which references said iPart or iAssembly, I'm required to update & save.

And around we go again.

If however I generate the member files by selecting them from the tree & manually selecting "generate files", the issue does not present.  But that requires user intervention for every member file & is more time consuming.

 

The code I'm using is from THIS THREAD), shown below:

ThisDoc.Document.Rebuild()
InventorVb.DocumentUpdate()
'If it Is an iPart
If ThisDoc.Document.DocumentType = kPartDocumentObject Then
    Dim oDoc As PartDocument = ThisDoc.Document
    Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
    Dim oFactory As iPartFactory = oDef.iPartFactory
    Dim oRow As iPartTableRow  
    For Each oRow In oFactory.TableRows
        oFactory.CreateMember(oRow)
    Next
End If
'If it is an iAssembly
If ThisDoc.Document.DocumentType = kAssemblyDocumentObject Then
    Dim oDoc As AssemblyDocument = ThisDoc.Document
    Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
    Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
    Dim oRow As iAssemblyTableRow   
    For Each oRow In oFactory.TableRows
        oFactory.CreateMember(oRow)
    Next
End If
iLogicVb.UpdateWhenDone = True

If there something wrong with it, it's not obvious to me.  

Can anyone shed any light on it?

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

JamieVJohnson2
Collaborator
Collaborator

explain the .UpdateWhenDone, and why you call it.  It is the only listed command that could cause the unexpected behavior, because you update after all changes have been made, the update itself could cause a 'is dirty' flag to be thrown on the file (and or its children) say due to an formula calculation being rerun for example.  If update is even necessary, call it and save BEFORE you generate your table row files.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 3

maxim.teleguz
Advocate
Advocate

 

 

 

Sub Main()
If ThisDoc.Document.DocumentType = kDrawingDocumentObject Then
	Msgbox("cannot run in drawing environment")
	Exit Sub
End If
'Dim oDoc As Document = ThisApplication.ActiveDocument

MsgBox("Screen might freeze dont panic, will start after you press ok")
ThisApplication.ScreenUpdating = False

	'If it Is an iPart
If ThisDoc.Document.DocumentType = kPartDocumentObject Then
    Dim oDoc As PartDocument = ThisDoc.Document
    Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
    Dim oFactory As iPartFactory = oDef.iPartFactory
    Dim oRow As iPartTableRow  
    For Each oRow In oFactory.TableRows
        oDoc.SelectSet.Select(oRow)
    Next
Else
End If
'If it is an iAssembly
If ThisDoc.Document.DocumentType = kAssemblyDocumentObject Then
    Dim oDoc As AssemblyDocument = ThisDoc.Document
    Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
    Dim oFactory As iAssemblyFactory = oDef.iAssemblyFactory
    Dim oRow As iAssemblyTableRow   
    For Each oRow In oFactory.TableRows
        oDoc.SelectSet.Select(oRow)
    Next
End If
	
'ThisDoc.Document.Rebuild() 'this will force a regenerate careful with this one.

Call ThisApplication.CommandManager.ControlDefinitions.Item("DeselSpawnCtxCmd").Execute



iLogicVb.UpdateWhenDone = True

''Cleanup
ThisApplication.ScreenUpdating = True
ThisApplication.ActiveView.Update()
MsgBox("Done")

End Sub

 

 

 

0 Likes