Dissociate/break link of multiple generated iPart files using iLogic

Dissociate/break link of multiple generated iPart files using iLogic

Anonymous
Not applicable
1,197 Views
6 Replies
Message 1 of 7

Dissociate/break link of multiple generated iPart files using iLogic

Anonymous
Not applicable

Hello,

 

I've perused these forums for almost a day's worth of time trying to find the solution to what I'm looking for.

 

We are trying to generated 1,000+ files using Inventor's iPart feature. The catch is that we would like all these newly derived parts to have their links broken from the original iPart file upon generation.

 

I was able to find a small line of code which partially worked:

 

Dim oParent As iPartFactory
oParent = ThisDoc.Document.ComponentDefinition.iPartFactory
Dim oRow As iPartTableRow
For Each oRow In oParent.TableRows
	oParent.CreateMember(oRow).BreakLinkToFactory
Next

This would generate the parts, though the link would only show itself as broken, if I immediately opened the new files all at once (no good with a batch of 1,000+ parts), with the original iPart file open as well.

 

Does anyone know of a code which could be written that will break these links for good upon generating the files?

 

Regards,

0 Likes
Accepted solutions (1)
1,198 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous 

 

Welcome to the Inventor Community, questions about programming related topics are best placed on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

If you search that forum for API keywords such as (BreakLinkToFactory) you will often find a working example. Here's a link to a recent topic:

https://forums.autodesk.com/t5/inventor-customization/delete-external-and-internal-ilogic-rules-in-ipt-and-break-link/td-p/9092980

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 7

Curtis_Waguespack
Consultant
Consultant

@Anonymous 

 

Actually it looks like you might have found that thread already. I don't fully follow your question about it not working to break the links and won't have time to look too deeply at it, so I would suggest you use the REPORT button in your post above and ask the admin staff to move this post to the Customization forum where it will get the right audience looking at it.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 4 of 7

Anonymous
Not applicable

@Curtis_Waguespack ,

 

Thanks for the reply.

 

To help clarify, my order of operations are as follows:

 

  1. Run iLogic rule using code mentioned above.
  2. Files are generated.
  3. Close "Parent" iPart/Inventor.
  4. Open generated files, all of which show they are still linked.

 

The only operational order that appears to actually work with breaking the links:

 

  1. Run iLogic rule using code mentioned above.
  2. Files are generated.
  3. Open all generated files.
  4. Save all generated files.
  5. Close out of "Parent" iPart /generated parts/Inventor.

This method shows all generated files with broken links upon opening.

 

We run Inventor 2020. Hopefully this makes my original post a bit clearer.

 

0 Likes
Message 5 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous 

 

Hmmm, that's strange. 

 

This code is from the link I posted above to the recent thread on this topic, if you scroll down there is a similar rule dealing with iAssemblies.... I took just a minutes and updated that rule to work with iparts, but I didn't really test it, but you can give this a go and see if it works.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oParent As iPartFactory
oParent = ThisDoc.Document.ComponentDefinition.iPartFactory

Dim oRow As iPartTableRow
Dim oDoc As PartDocument
Dim oDef As PartComponentDefinition

'Generate members
For Each oRow In oParent.TableRows
	Try
	oParent.CreateMember(oRow)
	Catch
	End Try
Next

'get member folder
oMemberFolder = oParent.MemberCacheDir

Dim fileEntries As String() = System.IO.Directory.GetFiles(oMemberFolder,"*.ipt")
Dim fileName As String

'open each member, break link, then save/close
For Each fileName In fileEntries
	oDoc = ThisApplication.Documents.Open(fileName, False)
	oDef = oDoc.ComponentDefinition
	If oDef.IsiPartMember Then
		oMember = oDef.iPartMember
		oMember.BreakLinkToFactory
		oDoc.save
	End If
	oDoc.close
Next

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 6 of 7

JelteDeJong
Mentor
Mentor

try this code:

 

Dim doc As PartDocument = ThisApplication.ActiveDocument

Dim factory As iPartFactory = doc.ComponentDefinition.iPartFactory
Dim folder As String = factory.MemberCacheDir

For Each row As iPartTableRow In factory.TableRows
    Dim member As iPartMember = factory.CreateMember(row)
    Dim memberName As String = row.MemberName & ".ipt"
    Dim fullFileName As String = IO.Path.Combine(folder, memberName)
    Dim memberDoc As PartDocument = ThisApplication.Documents.Open(fullFileName, True)
    Dim iPartMemberDoc As iPartMember = memberDoc.ComponentDefinition.iPartMember
    iPartMemberDoc.BreakLinkToFactory()
    memberDoc.Save()
    memberDoc.Close(True)
Next

EDIT: i see that @Curtis_Waguespack already send a solution. i guess he posted it while i was writing mine....

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 7 of 7

Anonymous
Not applicable

@Curtis_Waguespack ,

 

This revised coding worked out splendid. Only thing to note, is that once running, it would not let me abort the operation. I only attempted this while testing, but it doesn't have much of an effect on what I need it for.

 

I appreciate the help!

 

Regards,

0 Likes