' Recursively grabs ObjectIDs of xrefs ' used by HandleToOID Private Shared Function ChildrenGet(i_root As GraphNode, i_Tx As Transaction, myHNDL As Handle, myOwnerHNDL As Handle) As ObjectId For o As Integer = 0 To i_root.NumOut - 1 Dim child As XrefGraphNode = TryCast(i_root.Out(o), XrefGraphNode) If child.XrefStatus = XrefStatus.Resolved Then Dim bl As BlockTableRecord = TryCast(i_Tx.GetObject(child.BlockTableRecordId, OpenMode.ForRead), BlockTableRecord) If bl.Handle = myOwnerHNDL Then 'we found the parent object, now find myHandle Dim myXrefDB As Database = bl.GetXrefDatabase(False) ' check for example on what the number means Using XTrans As Transaction = myXrefDB.TransactionManager.StartTransaction Try Dim myEntOID As ObjectId = myXrefDB.GetObjectId(False, myHNDL, 0) MsgBox(myEntOID.ObjectClass.Name & vbCr & bl.Handle.ToString & vbCr & myEntOID.ToString) Return myEntOID Catch myex As System.Exception MsgBox(myex.Message) End Try End Using Exit For Else ChildrenGet(child, i_Tx, myHNDL, myOwnerHNDL) End If End If Next End Function
Im a bit stuck on the code above.
Depending on how deep the xref nesting goes, it appears that .net will step back out of the code one level at a time.
I can hit this line with a valid ObjectId: Return myEntOID
But when I hit that point, it steps through to End Function, Like I would think it would.
Then goes back to:
ChildrenGet(child, i_Tx, myHNDL, myOwnerHNDL)
Is this normal .net behaviour, How do I exit the function with my value?
Solved! Go to Solution.
I think this is a general behavior with any recursive function.
If you want the recursion to end, you may try using a boolean value that gets passed into the function. This will let the top level recursions to know that the value that you are interested in has been found and it no longer needs to invetigate further. If so, the function can simply return which willl make it go back one level up and this will repeat until your recursion ends.
Thank you, Im just figuring out what all of the .net functions do I guess. I assumed, the RETURN would return me and exit out of the function.
Thanks again for the explanation.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register