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: 

How to delete objects in an array

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Arnold82
1051 Views, 4 Replies

How to delete objects in an array

 

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

 

 

4 REPLIES 4
Message 2 of 5

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

Message 3 of 5

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
Message 4 of 5
Ralf_Krieg
in reply to: Arnold82

Hi

 

Don't know why you collect all Symbols in an array, but each SketchedSymbolDefinition has a property "IsReferenced".

 

From Help

Property that specifies if the sketched symbol definition is being referenced or not. A sketched symbol definition is referenced when an instance of the definition has been placed. A referenced sketched symbol definition cannot be deleted.

 


So you only have to step through the SketchedSymbolDefinitions, check the IsReferenced-Property and delete all unreferenced SketchedSymbolDifinitions.


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 5 of 5
Arnold82
in reply to: Arnold82

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.

Post to forums  

Autodesk Design & Make Report