Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ipart break link

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Anonymous
1245 Views, 15 Replies

ipart break link

I have made a code to break link of ipart in assembly with parent factory. It works in one assembly and it doesen't work in a another. Please Help i can't find the problem

SyntaxEditor Code Snippet

    Dim asmDoc As AssemblyDocument
    asmDoc = ThisApplication.ActiveDocument
    
    Dim oDoc As Document = ThisDoc.Document
    Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
       Dim occ As Inventor.ComponentOccurrence
    
      Dim partCompDef1 As PartComponentDefinition
    Dim partCompDef2 As PartComponentDefinition
    Dim factoryDoc As PartDocument
    'Dim oPart As PartDocument
    

    Dim i As Long=1
    
    For Each occ in oCompDef.Occurrences
    occ = asmDoc.ComponentDefinition.Occurrences(i)
    
    If occ.IsiPartMember Then
        partCompDef1 = occ.Definition
        factoryDoc=partCompDef1.iPartMember.ReferencedDocumentDescriptor.ReferencedDocument
    
    
        Dim oPart As PartDocument 
    
        For Each oPart In factoryDoc.ReferencedDocuments
            MessageBox.Show("Message", "Title")

            oPart.ComponentDefinition.iPartMember.BreakLinkToFactory
            
        Next
    
    End If
    i=i+1
      Next

 

15 REPLIES 15
Message 2 of 16
bradeneuropeArthur
in reply to: Anonymous

What do you mean with other assembly?

Do you mean a sub assembly from the top assembly?

Or  a complete other assembly?

 

if you mean subassembly then you need to create a recursive loop!

 

let me know what you mean....

 

Regards

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 16
Anonymous
in reply to: bradeneuropeArthur

I mean a sub assembly from the top assembly....:)

Message 4 of 16
bradeneuropeArthur
in reply to: Anonymous

then we need to modify the code a little....

 

keep reading, come back to it ASAP

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 5 of 16
Anonymous
in reply to: bradeneuropeArthur

My final goal is to make a code that will go throught all components of a assembly and will break the link with all the iparts factory and subassembly factories. Basicly i want to make a code that will convert all iparts and iassembly into parts.My workflow will go something like this:

Pack and go=>run code (convert(break links with factory) with all iparts and iassemblies into normal parts and assemblies)=> pack and go again

Message 6 of 16
bradeneuropeArthur
in reply to: Anonymous

Public Sub main()
Dim asmDoc As AssemblyDocument
    asmDoc = ThisApplication.ActiveDocument
End Sub

Public Sub c(asmDoc As AssemblyDocument)

    
    Dim oDoc As Document = ThisDoc.Document
    Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
       Dim occ As Inventor.ComponentOccurrence
    
      Dim partCompDef1 As PartComponentDefinition
    Dim partCompDef2 As PartComponentDefinition
    Dim factoryDoc As PartDocument
    'Dim oPart As PartDocument
    

    Dim i As Long=1
    
    For Each occ In oCompDef.Occurrences
    occ = asmDoc.ComponentDefinition.Occurrences(i)
    
    If occ.IsiPartMember Then
        partCompDef1 = occ.Definition
        factoryDoc = partCompDef1.iPartMember.ReferencedDocumentDescriptor.ReferencedDocument
    
    
        Dim oPart As PartDocument
    
        For Each oPart In factoryDoc.ReferencedDocuments
            MessageBox.Show("Message", "Title")

            oPart.ComponentDefinition.iPartMember.BreakLinkToFactory
            
        Next
    
    End If
    
    If occ.DefinitionDocumentType = kAssemblyDocumentObject Then
    Call c(occ.Definition.Document)
    End If
    i = i + 1
      Next
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 7 of 16
Anonymous
in reply to: bradeneuropeArthur

I am a little stupid her,when i run this code in a simple assembly with two ipart members and a subiassembly member  it does nothing? When i read the code i have to add something in the main sub? What am i missing?

 

I am really thankfull for helping me with this code

Message 8 of 16
bradeneuropeArthur
in reply to: Anonymous

No.

 

I made mistake!!

 

Public Sub main()
Dim asmDoc As AssemblyDocument
    asmDoc = ThisApplication.ActiveDocument
End Sub
c(asmDoc)
Public Sub c(asmDoc As AssemblyDocument)

    
    Dim oDoc As Document = ThisDoc.Document
    Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
       Dim occ As Inventor.ComponentOccurrence
    
      Dim partCompDef1 As PartComponentDefinition
    Dim partCompDef2 As PartComponentDefinition
    Dim factoryDoc As PartDocument
    'Dim oPart As PartDocument
    

    Dim i As Long=1
    
    For Each occ In oCompDef.Occurrences
    occ = asmDoc.ComponentDefinition.Occurrences(i)
    
    If occ.IsiPartMember Then
        partCompDef1 = occ.Definition
        factoryDoc = partCompDef1.iPartMember.ReferencedDocumentDescriptor.ReferencedDocument
    
    
        Dim oPart As PartDocument
    
        For Each oPart In factoryDoc.ReferencedDocuments
            MessageBox.Show("Message", "Title")

            oPart.ComponentDefinition.iPartMember.BreakLinkToFactory
            
        Next
    
    End If
    
    If occ.DefinitionDocumentType = kAssemblyDocumentObject Then
    Call c(occ.Definition.Document)
    End If
    i = i + 1
      Next
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 9 of 16
Anonymous
in reply to: bradeneuropeArthur

Ok so here is the problem i get when i run the code. The problem lies in the line

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 672 StartFragment: 314 EndFragment: 640 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

oPart.ComponentDefinition.iPartMember.BreakLinkToFactory

The error i get is "Object reference not set to an instance of an object."

 

I have a simple assembly with two iparts and a subiassembly. Do i need to do something in the ipart auther table or something to make it work?? 

Message 10 of 16
Anonymous
in reply to: Anonymous

I have atached the rule with a simple assembly. Can somone please help me find the error???

Message 11 of 16
Anonymous
in reply to: Anonymous

Anyone?

Message 12 of 16
Anonymous
in reply to: Anonymous

Ok I am stupid. Found the problem.....

Thank you for the help brandeneurope

 

 

Message 13 of 16
bradeneuropeArthur
in reply to: Anonymous

Your thanks are appreciated!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 14 of 16
aurel_e
in reply to: Anonymous

@Anonymous 

Can you please post the right rule? 

I am having the same problem "Object reference not set..."

Message 15 of 16
Anonymous
in reply to: aurel_e

This code was a year ago when i started learning about ipart and ilogic codeine. I think it is this one try it:

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 19535 StartFragment: 314 EndFragment: 19503 StartSelection: 314 EndSelection: 314

Sub Main()
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition

Dim occ As ComponentOccurrence

For Each occ In oCompDef.Occurrences
isum=isum+1
Next

For i=1 To isum
occ = oDoc.ComponentDefinition.Occurrences(i)

If occ.IsiPartMember Then
    Dim oPCD As PartComponentDefinition
    oPCD = occ.Definition
    Dim iPM As iPartMember
    iPM = oPCD.iPartMember
    iPM.BreakLinkToFactory    
End If

If occ.IsiAssemblyMember Then
    
    Call processAllSubOcc(occ)
    Dim oPCD As AssemblyComponentDefinition
    oPCD = occ.Definition
    Dim iPM As iAssemblyMember
    iPM = oPCD.iAssemblyMember
    iPM.BreakLinkToFactory
End If


Next
iLogicVb.UpdateWhenDone = True

End Sub

' This function is called for processing sub assembly. It is called recursively' to iterate through the entire assembly tree.

Sub processAllSubOcc(ByRef occ As ComponentOccurrence)

Dim oAssemblyDoc As AssemblyDocument 
oDoc = occ.Definition.Document
Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
Dim Subocc As ComponentOccurrence


For Each Subocc In oCompDef.Occurrences
isum=isum+1
Next

For i=1 To isum
subocc = oDoc.ComponentDefinition.Occurrences(i)

If subocc.IsiPartMember Then
    Dim oPCD As PartComponentDefinition
    oPCD = subocc.Definition
    Dim iPM As iPartMember
    iPM = oPCD.iPartMember
    iPM.BreakLinkToFactory    
End If
If subocc.IsiAssemblyMember Then
    Call processAllSubOcc(subocc)
    Dim oPCD As AssemblyComponentDefinition
    oPCD = subocc .Definition
    Dim iPM As iAssemblyMember
    iPM = oPCD.iAssemblyMember
    iPM.BreakLinkToFactory
End If
Next
End Sub
Message 16 of 16
aurel_e
in reply to: Anonymous

It works!

Thank you @Anonymous 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report