Hi,
I need to make my application compatible with 2008 and have one error saying that ObjectClass is not a member of SubEntId (As ObjectID) in my InsertBlock routine. Can anyone suggest a solution here?
Public Sub InsertBlock(ByVal blockname As String, ByVal trans As Transaction) Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database ' Test if block exists in the block table Dim bt As BlockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) Dim id As ObjectId = bt(blockname) Dim btr As BlockTableRecord = trans.GetObject(id, OpenMode.ForRead, False, True) Dim br As New BlockReference(New Point3d(0, 0, 0), id) Dim MS As BlockTableRecord = DirectCast(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) MS.AppendEntity(br) trans.AddNewlyCreatedDBObject(br, True) If btr.HasAttributeDefinitions Then Dim AtDef As AttributeDefinition, AttRef As AttributeReference For Each SubEntId As ObjectId In btr If SubEntId.ObjectClass.Name = "AcDbAttributeDefinition" Then AtDef = trans.GetObject(SubEntId, OpenMode.ForRead, False, True) AttRef = New AttributeReference AttRef.SetAttributeFromBlock(AtDef, br.BlockTransform) br.AttributeCollection.AppendAttribute(AttRef) trans.AddNewlyCreatedDBObject(AttRef, True) AtDef.Dispose() AttRef.Dispose() End If Next End If BlockRefID = br.ObjectId End Sub
That is turning my words around to make it bad.
>> CType() is faster than TryCast(), while completely ignoring the fact that
>> ignoring the fact that CType() cannot be used without also calling GetType()
>> and Equals() or (more correctly) IsAssignableFrom
And TryCast don't need that, wow, it does then magic things? Come on!
Additionally: I only run CType when I already know from GetType that is can be casted. Your code used TryCast for every ObjectID in the loop while I only use GetType.
But right, let us not waste time as you code is correct, as Gile's code is correct and as my revsed code is correct, but it is not like you want to write and so it has to be wrong.
You are right that my first attemt with twice calling trans.GetObject is not ok. And all after that hangs up on this first mistake.
I wish you never ever make a mistake and you're correction is then ignored as mine are.
At least for everyone: My apologizes, my first attempt needed two times GetObject (in case of it's the searched type) to get the accessable AttributeDefinition.
>> so I'm not going to waste time debating that with you.
Dicuss or debate, I tried to dicuss, yep, I never tried to push that up how it is now.
I always want to learn something, but with that hardness of reaction it is hard.
At least yes, time to stop.
To the story from Jeff,
...please don't forget the option, that one of your XTypes takes the parcel, brings it to the customer and has to bring it back as it's the wrong type 😉
To Jeff's code a short comment,
If "btr" is a BlockTableRecord, then I guess he wanted to check for AttributeDefinition and not AttributeReferences and he works with latebinding, so the assignment from type DbObject to a Type derived from DbObject (AttributeReference in his code) is possible without (any type of) casting.
Interestingly I also wrote AttribtueReferences instead of ...Defintions first 😉
I'm out then as this seems to not make sense any more and also does not include the fun like help anyone in forums should make. Very sorry, - alfred -
Thanks all for the extensive comments and advice.
I really appreciate the time you have taken to reply.