Remove Constraints and ground components within subassembly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to remove all constraints, and ground all components within a subassembly.
I am replacing components within a subassembly. But to make this easy, and without iMates, I have to remove all constraints, and ground all components within that subassembly.
I tried these two codes:
SyntaxEditor Code Snippet
'start of ilogic code' get the active assembly Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'set the Master LOD active Dim oLODRep As LevelofDetailRepresentation oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master") oLODRep.Activate 'Iterate through all of the occurrences and ground them. Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences 'check for and skip virtual components If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then oOccurrence.Grounded = True Else End If
SyntaxEditor Code Snippet
Dim oAssDoc As AssemblyDocument oAssDoc = ThisApplication.ActiveDocument Dim oConstraint As AssemblyConstraint i = 0 For Each oConstraint In oAssDoc.ComponentDefinition.Constraints oConstraint.Delete i = i + 1 Next MessageBox.Show(" A total of "& i & " constraints were deleted.", "iLogic")
These work perfect in an assembly, but they do nothing to subassemblies.
I even tried to put them inside the subassembly and running it within the subassembly by using an external rule. But this also doesn't work.
If I try this I will get these errors:
Constraints;
It doesn't give an error, but it just doesn't remove any constraints.
I will get the message: A total of 0 constraints were deleted.
Grounden;
Error in rule: Grounden, in document: subassembly.iam
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
If I open the subassembly, and run the rules there everything works fine again.
I hope someone can help me out!
Melle Oosterman
Inventor Autodesk Inventor 2014