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
Solved! Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
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 !
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 !
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
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 !
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
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 !
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??
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 !
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
Can't find what you're looking for? Ask the community or share your knowledge.