I guess one idea is to use a conditional statement to issue the right ctype code, but that would not teach me
anything... 🙂
James Maeding
|>I am trying to make a function to take a name and table type, and return the record if found.
|>So this is what I have so far for the "generic" table function:
|>
|>Public Function getAnyObjNet(ByVal name As String, ByVal tableType As String) As SymbolTableRecord
|> Dim db As Database = HostApplicationServices.WorkingDatabase()
|> Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
|> Dim symTblRec As SymbolTableRecord = Nothing
|> Using myT As Transaction = tm.StartTransaction()
|> Try
|> Dim symTbl As SymbolTable = CType(myT.GetObject(db.LayerTableId, OpenMode.ForRead, False), tableType)
|> 'the above line does not work
|> 'cannot use tableType as variable for object type, must use explicit name
|> 'like LayerTable
|> 'need ideas here
|> If symTbl.Has(name) Then
|> symTblRec = CType(myT.GetObject(symTbl.Item(name), OpenMode.ForRead), SymbolTableRecord)
|> 'the above works but I would prefer to send back correct cast of object even though function says
|> '"As SymbolTableRecord.."
|> End If
|> myT.Commit()
|> Catch
|> symTblRec = Nothing
|> Finally
|> myT.Dispose()
|> End Try
|> End Using
|> Return symTblRec
|> End Function
|>
|>So while I can stay generic in most places, I must specify what kind of table I want to look up at some point.
|>I am also wondering if I can return a specific object type like LayerTableRecord, even though my function says "as
|>SymbolTableRecord".
|>
|>Any takers? Any comments welcome on the code, I am not experienced with .net error checking.
|>
|>thanks
|>James Maeding
|>Civil Engineer and Programmer
|>jmaeding - athunsaker - com
James Maeding
Civil Engineer and Programmer
jmaeding - athunsaker - com