You can follow the same way as brian showed in his fusion sample. You can check if a particular sketch is in your part and edit the text box that is in that sketch. But when you start writing your code you need to think when you are going to run your code. On part level or on assembly level? Inventor has a slightly different structure as it comes to parts and assemblies.
here is a small sample rule that you can run on part level.
Sub main
Dim oDoc As PartDocument
oDoc = ThisDoc.Document
Dim oCompdef As PartComponentDefinition
oCompdef = oDoc.ComponentDefinition
Dim sk As PlanarSketch
'try to get the sketch "CompName"
Try
sk = oCompdef.Sketches.Item("CompName")
Catch
Logger.Info("no sketch found.")
Exit Sub
End Try
'assuming that the sketch contains a textbox and that the file is saved.
sk.TextBoxes.Item(1).Text = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
End Sub