Unsuppress Drawingviews using LINQ

Unsuppress Drawingviews using LINQ

frederic.vandenplas
Collaborator Collaborator
239 Views
2 Replies
Message 1 of 3

Unsuppress Drawingviews using LINQ

frederic.vandenplas
Collaborator
Collaborator

Hi, 

I want to (un)suppres drawingviews using LINQ.

When i debug the code in VS the functions seems to work fine but the drawingviews remain (un)suppressed.

Can someone help me out?

First i filter for drawingviews which contains TREK , then i want to (un)suppress them.

 

Sub main
	
Dim invapp As Inventor.Application = ThisApplication
Dim oDrawDoc As DrawingDocument = invapp.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

oSheet.DrawingViews.Cast(Of DrawingView).ToList().Where(Function(oDrawView As DrawingView) oDrawView.Name.Contains("TREK")).tolist.ForEach(Function(oDrawView As DrawingView) oDrawView.Suppressed = True) 

End Sub

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
240 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

I could be wrong, because I have not tested it, but you may be attempting just a little too much with one line there.  I think you may need a Delegate Sub routine that you can point to for each item in the list at the end, instead of another 'Function(Of T)'.  Just looking at the simple example on Microsoft's website for that List<T>.ForEach() method.  It's using an Action<T> delegate there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

frederic.vandenplas
Collaborator
Collaborator

Hi,

Indeed, maybe i wanted to much 🙂

I've solved it this way

 

Dim invapp As Inventor.Application = ThisApplication
Dim oDrawDoc As DrawingDocument = invapp.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

For Each oDrawView As DrawingView In oSheet.DrawingViews.Cast(Of DrawingView).Where(Function(d As DrawingView) d.Name.Contains("TREK"))
	oDrawView.Suppressed = True
Next oDrawView 
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes