Inventor Customization

Inventor Customization

Reply
Valued Contributor
Arnold82
Posts: 56
Registered: ‎12-20-2012
Message 1 of 5 (244 Views)
Accepted Solution

How to delete objects in an array

244 Views, 4 Replies
01-08-2013 02:14 PM

 

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

 

 

*Expert Elite*
Curtis_Waguespack
Posts: 2,903
Registered: ‎03-08-2006
Message 2 of 5 (240 Views)

Re: How to delete objects in an array

01-08-2013 02:38 PM in reply to: Arnold82

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



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Valued Contributor
Arnold82
Posts: 56
Registered: ‎12-20-2012
Message 3 of 5 (220 Views)

Re: How to delete objects in an array

01-12-2013 09:19 AM in reply to: Curtis_Waguespack

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
Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 4 of 5 (212 Views)

Re: How to delete objects in an array

01-13-2013 12:33 PM 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.

Valued Contributor
Arnold82
Posts: 56
Registered: ‎12-20-2012
Message 5 of 5 (198 Views)

Re: How to delete objects in an array

01-15-2013 03:06 AM 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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.