Unable to add Attributesets using ApprenticeServer

Unable to add Attributesets using ApprenticeServer

lmc.engineering
Advocate Advocate
256 Views
2 Replies
Message 1 of 3

Unable to add Attributesets using ApprenticeServer

lmc.engineering
Advocate
Advocate

Hi All,

 

I'm attempting to add an attributeset to a document using Apprentice, however, I am getting a System.Runtime.InteropServices.COMException when it comes to adding it. As below:

 

1.PNG

 Code as follows:

        Dim m_ApprenticeApp As ApprenticeServerComponent = New ApprenticeServerComponent()
        Dim doc As ApprenticeServerDocument
        Dim ffn As String = "C:\temp\Part1.ipt"
        doc = m_ApprenticeApp.Open(ffn)

        Dim NameOfNewPS As String = "MyNewSet"
        Dim oNewPS As AttributeSet

        If doc.AttributeManager.FindAttributeSets(NameOfNewPS).Count > 0 Then
            ' if the set exists aleady
            oNewPS = doc.AttributeSets(NameOfNewPS)
        Else
            ' add a new one
            oNewPS = doc.AttributeSets.Add(NameOfNewPS)
        End If

 

I have it set to compile using x64, and have reference to the autodesk.inventor.interop. I should note that I can add iProperties with no issues using this:

 

        Dim m_ApprenticeApp As ApprenticeServerComponent = New ApprenticeServerComponent()
        Dim doc As ApprenticeServerDocument
        Dim ffn As String = "C:\temp\Part1.ipt"
        doc = m_ApprenticeApp.Open(ffn)

        Dim iPropSet As Inventor.PropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
        Dim prop As Inventor.Property = Nothing
        Dim PropName As String = "Test"
        Dim found As Boolean = False
        For Each prop In iPropSet
            Debug.WriteLine(prop.Name)
            If prop.Name = PropName Then
                found = True
                Exit For
            End If
        Next
        If Not found Then
            prop = iPropSet.Add("1234", "Test")
        End If
        doc.PropertySets.FlushToFile()

 

This link confirms attributes are read/write and gives an example. I can't seem to figure out where it's going wrong at my end. Can anyone shed any light?

 

Regards

0 Likes
257 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @lmc.engineering.  I do not use Apprentice Server, so this is just an educated guess, but have you tried declaring the 'oNewPS' variable As Inventor.AttributeSet, instead of just AttributeSet.  I know that sometimes when other references/Imports are involved, sometimes object Types can get misunderstood.  One good example is the TextBox object.  There is an Inventor.TextBox, and there is a System.Windows.Forms.TextBox, and that has always required the additional specification when declaring the variables.  And I know that there are many VB objects with 'Attribute' as part of their Type name, but not sure if AttributeSet is a specific one though. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

lmc.engineering
Advocate
Advocate

Hi @WCrihfield

 

Thanks for your reply.

 

Sadly that had no effect on the issue. This one has got me stumped.

 

Thanks

0 Likes