0

I'm writing an add-in for Autodesk Inventor in Visual Studio using VB.net. There are many different types of documents. When I know the type of document, I want IntelliSense to list the members of that document. Is there any way to do that without Dim-ing a completely new variable?

Sub Test(o_Doc As Inventor.Document)

    Select Case True
        Case TypeOf o_Doc Is AssemblyDocument, TypeOf o_Doc Is PartDocument
            o_Doc.  ' Intellisense lists the members for Inventor.Document
    End Select

End Sub

After typing o_Doc, I press period and it lists the members of Inventor.Document. The AssemblyDocument and PartDocument both share a ComponentDefinition member, but not every type of document does. Is there a way to list all the members for the AssemblyDocument without having to insert this after the Case operator?

Dim _AssemblyDocument as Inventor.AssemblyDocument= o_Doc
_AssemblyDocument. ' lists all the members of AssemblyDocument

Edit: Changed the Dim _AssemblyDocument as Inventor.Document to AssemblyDocument

  • `_AssemblyDocument. ' lists all the members of AssemblyDocument` I don't think it does. It's still an Inventor.Document at this point. Are you missing a cast? – djv Jul 19 '19 at 22:11
  • Also see [this thread](https://forums.autodesk.com/t5/inventor-customization/c-net-access-part-and-assembly-properties/td-p/2568294) on Autodesk's website. – djv Jul 19 '19 at 22:15
  • Lastly, since you pass a `Inventor.Document` then all you should do with it is `Inventor.Document` stuff, because as far as your code is concerned that it all it is. Why do these classes share another member `ComponentDefinition`? Is there another class in their chain of inheritance with that member? Maybe you should pass the object as that. If they both have that member without it being part of an Interface of abstract class, then it is either poor design, or not meant to be used how you are using it. Sorry, I'm not familiar with the Autodesk API at all but these are just my impressions. GL! – djv Jul 19 '19 at 22:21
  • Whoops. I did a typo and just fixed it. Also, the link you sent me seems to be similar to what I am trying to figure out but in VB.Net. I'm guessing that what I'm asking is just not possible to do. – Mistaken Engineer Jul 22 '19 at 14:29

1 Answers1

0

I wanted to say No but technically if you are only looking for a way to get intellisense without declaring a new variable, you could cast,

Sub Test(o_Doc As Inventor.Document)
    Select Case True
        Case TypeOf o_Doc Is AssemblyDocument
            DirectCast(o_Doc, AssemblyDocument). ' AssemblyDocument intellisense
        Case TypeOf o_Doc Is PartDocument
            ' or if you access more than one member, With might be easier
            With DirectCast(o_Doc, PartDocument)
                . ' PartDocument intellisense 1
                . ' PartDocument intellisense 2
            End With
    End Select
End Sub

but now you have separate cases.

Again, is there another class in the inheritance chain?

  • Inventor.Document
    • Another Class / Interface?
      • AssemblyDocument
      • PartDocument

I find it odd that the derived classes would share members not declared in their base class or an interface. If they do share another common class or interface then you could test for that and cast to it, and only have one case for those two types.

djv
  • 15,168
  • 7
  • 48
  • 72
  • Thank you! The `DirectCast` command is very helpful and I didn't know that existed. I'm very certain about the inheritance. Here is the object model: https://knowledge.autodesk.com/akn-aknsite-article-attachments/b47b068f-d1f8-4410-a8e6-c89cdd618a7c.pdf – Mistaken Engineer Jul 25 '19 at 13:05
  • `DirectCast` is how you cast in VB.NET, equivalent to the C# cast `(type)object`, you also have `TryCast` with slightly different behavior, and `CType` which is a less strict type conversion function only available to VB.NET. See [this question and its answers](https://stackoverflow.com/q/2703585/832052). – djv Jul 25 '19 at 14:29