why does ComponentDefinition became not a member of Document ?

why does ComponentDefinition became not a member of Document ?

Anonymous
Not applicable
1,498 Views
8 Replies
Message 1 of 9

why does ComponentDefinition became not a member of Document ?

Anonymous
Not applicable
Recently I have met a seriously problem when I want to get the userparameters in a document
One exception will occasionally happen. The code of getting the userparameters as follow:
Dim oParams As Inventor.Parameters
Dim tcDefinition As Inventor.ComponentDefinition
tcDefinition = oDoc.ComponentDefinition "''Exception: Member not Found

oParams = tcDefinition.Parameters
Dim oUserParams As Inventor.UserParameters
oUserParams = oParams.UserParameters
I use VB2003.Net. This exception happens not usually, but it is serious.
I have payed nearly 2 weeks in this problem. Can someone give me some help?
I have attached a bitmap to show the exception scene
0 Likes
1,499 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
I used VB6/VBA in Inventor 11 and made the following changes (I think you cannot do oDoc.ComponentDefinition) it has to be oPart or oAssembly. Also need to use the Set syntax in VBA not sure how .Net works

Dim oPart As PartDocument
Set oPart = ThisApplication.ActiveDocument 'You can change were the document is but I have just said its the one thats on screen

If oPart.DocumentType = kPartDocumentObject Then
Dim oParams As Inventor.Parameters
Dim tcDefinition As Inventor.ComponentDefinition
Set tcDefinition = oPart.ComponentDefinition

Set oParams = tcDefinition.Parameters
Dim oUserParams As Inventor.UserParameters
Set oUserParams = oParams.UserParameters
Else: End If

If you are looking at an assembly you may need to traverse through it first to get to each part parameters.

Going for Easter holidays now so hope this helps in the mean time.
0 Likes
Message 3 of 9

Anonymous
Not applicable
Thank your for your replay, It's my fault that
there are other pre-codes before my original posted problem,and now i will give the full codes as follow:

Dim oDoc As Document
oDoc = InventorApplication.ActiveDocument
If oDoc Is Nothing Then
Exit Sub
ElseIf oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
Exit Sub
End If

If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oParams As Inventor.Parameters
Dim tcDefinition As Inventor.ComponentDefinition
tcDefinition = oDoc.ComponentDefinition ''Exception: Member not Found
oParams = tcDefinition.Parameters
Dim oUserParams As Inventor.UserParameters
oUserParams = oParams.UserParameters
End if Message was edited by: panwanbin
0 Likes
Message 4 of 9

Anonymous
Not applicable
The error is because the Document object does not have a .ComponentDefinition method.

You will need to assign oDoc to a PartDocument object or AssemblyDocument object before calling the method.

If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPartDoc as PartDocument
set oPartDoc = oDoc
Dim oParams As Inventor.Parameters
Dim tcDefinition As Inventor.ComponentDefinition
tcDefinition = oPartDoc.ComponentDefinition ' this shouldn't throw an exception
...
0 Likes
Message 5 of 9

Anonymous
Not applicable
This should work. The PartDocument and AssemblyDocument objects are derived
from the base class Document object. Using a Document object to represent
these derived classes should be ok. When you're coding you won't see
ComponentDefinition as an option in Intellisense but that's because at
design time VB doesn't know what actual object will be available at runtime
so it has to go by what's defined in the type library for the Document
object. During run time it's able to see that the object is actually a
PartDocument or AssemblyDocument and you will have access to the unique
properties and methods they support.

I haven't heard of any problems previously reported in this area. I just
wrote a quick test in VB 2005 to make sure there wasn't something funny with
.Net and COM Interop but the test worked fine. Do you have a case where
this consistently fails?
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5544072@discussion.autodesk.com...
Thank your for your replay, It's my fault that
there are other pre-codes before my original posted problem,and now i will
give the full codes as follow:

Dim oDoc As Document
oDoc = InventorApplication.ActiveDocument
If oDoc Is Nothing Then
Exit Sub
ElseIf oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
oDoc.DocumentType <>
DocumentTypeEnum.kPartDocumentObject Then
Exit Sub
End If

If oDoc.DocumentType = DocumentTypeEnum
kPartDocumentObject Then
Dim oParams As Inventor.Parameters
Dim tcDefinition As Inventor.ComponentDefinition
tcDefinition = oDoc.ComponentDefinition ''Exception: Member not Found
oParams = tcDefinition.Parameters
Dim oUserParams As Inventor.UserParameters
oUserParams = oParams.UserParameters
End if

Message was edited by: panwanbin
0 Likes
Message 6 of 9

Anonymous
Not applicable
Brian, AFAIK because the ComponentDefinition member function is not defined for a Document object (AFAIK) it cannot be called from a reference to a Document object. If the user knows that it is really a PartDocument (e.g. by checking type), then it can be "cast" to a more specific class by Dimming the more specific object and setting it to the less specific class reference.

Dim oPartDoc as PartDocument
Set oPartDoc = oDoc

This may have changed for .NET though.
0 Likes
Message 7 of 9

Anonymous
Not applicable
You don't have to cast it. VB takes care of this itself. I've used this in
many programs that I wanted to be able to work in either a part or assembly
document. During the initial coding I would declare:

Dim oDoc as PartDocument

just so I could get intellisense to ease creating the code. Once I had the
code written I would change this to

Dim oDoc as Document

and continue my testing.

Here's a simple VBA program that illustrates this. It calls the
ComponentDefinition property, which doesn't exist on the Document object,
and also calls the Parameters property, which doesn't exist on the
ComponentDefinition object (only on the PartComponentDefinition and
AssemblyComponentDefinition objects). It works fine. It tried a similar
test in VB 2005 and it worked there too.

Public Sub DocBaseClass()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

Dim oCompDef As ComponentDefinition
Set oCompDef = oDoc.ComponentDefinition

Dim oParams As Parameters
Set oParams = oCompDef.Parameters

MsgBox "There are " & oParams.Count & " parameters."
End Sub

--
Brian Ekins
Autodesk Inventor API


wrote in message news:5544366@discussion.autodesk.com...
Brian, AFAIK because the ComponentDefinition member function is not defined
for a Document object (AFAIK) it cannot be called from a reference to a
Document object. If the user knows that it is really a PartDocument (e.g.
by checking type), then it can be "cast" to a more specific class by Dimming
the more specific object and setting it to the less specific class
reference.

Dim oPartDoc as PartDocument
Set oPartDoc = oDoc

This may have changed for .NET though.
0 Likes
Message 8 of 9

Anonymous
Not applicable
ah yes, works here too. Sorry!
0 Likes
Message 9 of 9

Anonymous
Not applicable
Thank you , now i use static_cast to convert the document to a part doc or an assembly doc by
"if" sentence. It seems that now my software is
more stable and robust.
0 Likes