Inventor Customization

Inventor Customization

Reply
Valued Contributor
63 Posts
21 Kudos
Registered: ‎12-20-2012
Post 1 of 5
Accepted Solution

How to delete objects in an array

271 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

 

 

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

*Expert Elite*
3,002 Posts
1,702 Kudos
Registered: ‎03-08-2006
Post 2 of 5

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
63 Posts
21 Kudos
Registered: ‎12-20-2012
Post 3 of 5

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
176 Posts
4 Kudos
Registered: ‎11-22-2009
Post 4 of 5

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
63 Posts
21 Kudos
Registered: ‎12-20-2012
Post 5 of 5

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post