Break Link changes lines

Break Link changes lines

JamieVJohnson2
Collaborator Collaborator
861 Views
8 Replies
Message 1 of 9

Break Link changes lines

JamieVJohnson2
Collaborator
Collaborator

I have the need to break a lot of links created by addsilhouette, and addentity and such to a sketch.  After the entities are added to the sketch the lines, arcs, circles, ellipses are all still linked back to the original 3D solid.  Running Break Link on over 700 objects cycles through and breaks the link.  However approx. 5% of the lines have been moved (where point values get set to 0 or something).  I think this may be a bug with Inventor (using version 2019.1.2 build 200).  If you break link on these exact lines one by one by hand, it succeeds, if you do so in batch by hand it messes up.  If you do so in batch by this code (vb.net), it messes just the same:

    Public Sub BreakAllLinks(sketch As Sketch)
        For Each en As SketchEntity In sketch.SketchEntities
            en.Reference = False
        Next
    End Sub

My intention is to report this bug, but also is there a way to add these entities without linking in the first place via code?

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Accepted solutions (1)
862 Views
8 Replies
Replies (8)
Message 2 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@JamieVJohnson2,

 

Below iLogic code seems to be working with attached part.  All entity links are set to false.

 

Sub Main()
	Dim oDoc As PartDocument 
	oDoc = ThisApplication.ActiveDocument 
	
	Dim oDef As PartComponentDefinition 
	oDef = oDoc.ComponentDefinition 
	
	Dim oSketch As Sketch 
	oSketch = oDef.Sketches.Item("Sketch5")
	BreakAllLinks(oSketch)
End Sub 
Public Sub BreakAllLinks(sketch As Sketch)
        For Each en As SketchEntity In sketch.SketchEntities
            en.Reference = False
        Next
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 9

JamieVJohnson2
Collaborator
Collaborator

Not for me.  Not as iLogic, not as VB.Net, not as user run command.  Not with Software Graphics, not with Hardware graphics, (NVIDIA Quadro P5000 16GB card, driver version :397.93) on a Precision 3630 running Windows 10 64Bit Pro for Workstations, and lots of highspeed hardware.  I get this instead.Capture.PNG

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

chandra.shekar.g
Autodesk Support
Autodesk Support

@JamieVJohnson2,

 

Can you please provide source code to test? Also please provide expected part after breaking link?

 

Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 9

JamieVJohnson2
Collaborator
Collaborator

I do believe your request to be ludicrous.  I have already provided the source code, and document, and you provided another copy of the same source code (that runs in full in iLogic), and I tested all of in on the provided document.  The result is that the lines move when they shouldn't.  They begin in one position before break link command, and end in a completely different position after break link command.  I posted an image of the bogus result (yellow lines do not outline the pipe, some have even moved down to the 0 elevation below the pipe.  I've been repeating it over and over, would you like a video as well?

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

JamieVJohnson2
Collaborator
Collaborator

I have uploaded a screen cast, showing this issue with and without code.

https://autode.sk/2Sws1je

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

JamieVJohnson2
Collaborator
Collaborator

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 goodall 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 offError 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!What a mess!Problem NOT solved.

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

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@JamieVJohnson2,

 

A workaround is found. After rebuilding document and breaking links, sketch entities links are broken properly. Can you please try below iLogic code?

Sub Main()
	Dim oDoc As PartDocument 
	oDoc = ThisApplication.ActiveDocument 
	
	Dim oDef As PartComponentDefinition 
	oDef = oDoc.ComponentDefinition 
	
	Call oDoc.Rebuild()
	
	Dim oSketch As Sketch 
	oSketch = oDef.Sketches.Item("Sketch5")
	BreakAllLinks(oSketch)
End Sub 
Public Sub BreakAllLinks(sketch As Sketch)
	
		sketch.Edit()
        For Each en As SketchEntity In sketch.SketchEntities
            en.Reference = False
        Next
		sketch.ExitEdit()
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 9

JamieVJohnson2
Collaborator
Collaborator

That works on my test widget.  Thanks.

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