- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
First time posting, been rummaging through the Forums for a while and have come across a lot of really good info.
I am trying to make a chunk that will take my selections inside a drawing and move them to my "Red" layer; pretty simple. But what I have found, is that when I grab these objects from the SelectSet, or even better [Grab Select iLogic Example] which returns an ObjectsEnumerator, the code won't dynamically access the object!
Below is working code, however I don't want to have a "Select Case" and have to DirectCast() based on the TypeName?! It is so beyond redundant...
I feel like the For Each loop should only be that single line that is commented out, but for some reason it produces some junk error:
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
Working Code:
Dim oDraw As Inventor.DrawingDocument = ThisDoc.Document
Dim oMgr = oDraw.StylesManager
Dim sSet As SelectSet = oDraw.SelectSet
Dim desLayer As Inventor.Layer = oMgr.Layers("Red")
'Filtering out objects that have already been assigned. Future code to possibly revert objects away from "Red" back to "Default"
For Each _ent In sSet.OfType(Of Object).Where(Function(x) x.Layer.Name <> desLayer.Name)
' _ent.Layer = desLayer '<--- This line should be Gold
Select Case TypeName(_ent)
Case "Balloon" : CType(_ent, Balloon).Layer = desLayer
Case "SketchEntity" : DirectCast(_ent, Inventor.SketchEntity).Layer = desLayer
Case "GeneralNote" : DirectCast(_ent, Inventor.GeneralNote).Layer = desLayer
Case "LinearGeneralDimension" : DirectCast(_ent, LinearGeneralDimension).Layer = desLayer
End Select
Next
As you could imagine, this code snippet has only 4 drawing objects, but obviously I want it to include Notes, SketchedSymbols, Ordinate Dims, Thread Notes.... Whatever I have selected. Especially with that code example above, I could be selecting lots!
Any ideas?
Solved! Go to Solution.