Hello,
Im making an array of all the sketchedsymboldefinitions in a drawing that are not used in the drawing as a sketchedsymbol
My problem is that i do not understand how to delete all the objects i have in my array at the end of the code
Dim oDoc As Drawingdocument = ThisDoc.Document Dim oSkSymDefs As SketchedSymbolDefinitions = oDoc.SketchedsymbolDefinitions Dim oSkSymDef As SketchedSymbolDefinition Dim oSheets As Sheets = oDoc.Sheets Dim oSheet As Sheet Dim oSkSymb As SketchedSymbol Dim MyArrayList As New ArrayList
'checking each definition for occurence in the drawing For Each oSkSymDef In oSkSymDefs
'checking each sheet For Each oSheet In oSheets Dim oSkSymbs As SketchedSymbols = oSheet.SketchedSymbols
'checking each sketched symbol per sheet For Each oSkSymb In oSkSymbs
'If the sketchname is found and not previously found then add to array If oSkSymDef.Name = oSkSymb.Name And Not MyArrayList.Contains(oSkSymDef) Then MyArrayList.Add(oSkSymDef) End If Next Next Next
So I got my array with all the objects to be deleted. But how to delete???
I also believe this code could be a bit more effecient.
So if anyone can help im very grateful
Thx in advance,
Arnold
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi Arnold82,
I think this will have some answers:
http://www.dotnetperls.com/arraylist-vbnet
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks for the reply,
And here is the code that purges all unneccesary sketch symbols:
Dim oDoc As Drawingdocument = ThisDoc.Document Dim oSkSymDefs As SketchedSymbolDefinitions = oDoc.SketchedsymbolDefinitions Dim oSkSymDef As SketchedSymbolDefinition Dim oSheets As Sheets = oDoc.Sheets Dim oSheet As Sheet Dim oSkSymb As SketchedSymbol Dim MyArrayList As New ArrayList For Each oSkSymDef In oSkSymDefs For Each oSheet In oSheets Dim oSkSymbs As SketchedSymbols = oSheet.SketchedSymbols For Each oSkSymb In oSkSymbs If oSkSymDef.Name = oSkSymb.Name And Not MyArrayList.Contains(oSkSymDef.Name) Then MyArrayList.Add(oSkSymDef.Name) End If Next Next If MyArrayList.contains(oSkSymDef.Name) = False Then oSkSymDef.Delete End If Next
Hi
Don't know why you collect all Symbols in an array, but each SketchedSymbolDefinition has a property "IsReferenced".
From Help
So you only have to step through the SketchedSymbolDefinitions, check the IsReferenced-Property and delete all unreferenced SketchedSymbolDifinitions.
I did that because I had no idea (but it was good exercise)
Thx for the tip. This truly is much better
Dim oDoc As Drawingdocument = ThisDoc.Document
Dim oSkSymDefs As SketchedSymbolDefinitions = oDoc.SketchedsymbolDefinitions
Dim oSkSymDef As SketchedSymbolDefinition
For Each oSkSymDef In oSkSymDefs
If oSkSymDef.IsReferenced = False Then
oSkSymDef.Delete
End If
Next
Can't find what you're looking for? Ask the community or share your knowledge.