I have an update worth posting. I ran this code addition to defer sketch updates, and all the break lines looked great during breaking. I stopped the code on the line sketch.DeferUpdates=false. At the stop, the sketch looked perfect.
all line break link looking good
However, when the code ran the line deferupdates= false (turning off defer), the problematic sketch lines ALL jumped to their inappropriate places. Also, hosting a transaction for each reference break has no positive effect at all.
Public Sub BreakAllLinks(sketch As Sketch)
sketch.DeferUpdates = True
For Each en As SketchEntity In sketch.SketchEntities
'Dim trans As Transaction = invApp.TransactionManager.StartTransaction(CType(sketch.Parent, ComponentDefinition).Document, "Break Link")
en.Reference = False
'trans.End()
Next
sketch.DeferUpdates = False
End Sub
I'm guessing there is a calculation error taking place during the sketch update command. My first thought was a point moving from one referenced location to another (by index) or received a 0 in its coordinate due to lack of access from another changing entity, so I thought 'break link while sketch updates are deferred'. It was looking like the solution, until I reset the defer. Then everything went splat, to the floor (or ceiling), miscalculations galore!
Error after defer update is turned off
The user accessible undo command has "Disable Sketch Defer Updates". If I undo that, it returns to the better picture. If I edit sketch, defer updates, break all links, and end sketch edit (with defer updates left on) the entities remain in their proper place.
Public Sub BreakAllLinks(sketch As Sketch)
sketch.Edit()
sketch.DeferUpdates = True
For Each en As SketchEntity In sketch.SketchEntities
'Dim trans As Transaction = invApp.TransactionManager.StartTransaction(CType(sketch.Parent, ComponentDefinition).Document, "Break Link")
en.Reference = False
'trans.End()
Next
sketch.ExitEdit()
'sketch.DeferUpdates = False
End Sub
But then Inventor becomes unstable, and the downstream code fails to get sketch.sketchlines items properly (system exception - can't find inventor, and fatal error (double boom!). So leaving DeferUpdates set to False is a bad idea.
So can you simply add deferupdates = false AFTER you exit the sketch??? No.
What a mess!Problem NOT solved.
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/