I should double check that the GetSelectedObject5 is actually returning a view. What if the user has selected some other type of object?
Also, you can use GetSelectedObjectsDrawingView2 instead.
If the selected view is a section view, ReferencedDocument will be empty. You need to get the BaseView of the section view first.
Finally, CustomInfo2 is now obsolete. Get the CustomPropertyManager from swDrawModel.Extension.
You'll probably want access the part/assembly via the getView methods instead of selection as long as there's only one model in the drawing you're interested in.
You can use the following code to get the model referenced by the first view on a drawing. Here's an example:
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Dim swView As View
Dim swExtension As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim bool As Boolean
swView = swDraw.GetFirstView 'this gets the sheet
swView = swView.GetNextView 'this gets the first view
swModel = swView.ReferencedDocument 'this is the part/assembly being referenced
swExtension = swModel.Extension
swCustProp = swExtension.CustomPropertyManager("")
bool = swCustProp.Set("Revision", "1") 'set Revision to "1"
If you really want to use selection to get the part, I would recommend using ModelDoc2.Extension to get the SelectionManager of the Drawing.
Thanks a ton! This is very helpful, however, I keep getting a run-time error 91 on the "swExtension = swModel.Extension" line.
FYI, the objects returned when you call GetSelectedObject5 on a DrawingDoc are IDrawingComponents, not Views. Maybe that's what's causing your problem. It looks like you're expecting a view. Check out the page below for more info ong GetSelectedObject.