How to distinguish iPart vs standard part using Apprentice

How to distinguish iPart vs standard part using Apprentice

JeffYao28
Enthusiast Enthusiast
617 Views
4 Replies
Message 1 of 5

How to distinguish iPart vs standard part using Apprentice

JeffYao28
Enthusiast
Enthusiast

 

Dear Support or Anyone,

 

How to distinguish iPart vs standard part using Apprentice 2016, or Inventor API?

 

Thank you!

 

 

Jeff Yao

 

0 Likes
Accepted solutions (1)
618 Views
4 Replies
Replies (4)
Message 2 of 5

frederic.vandenplas
Collaborator
Collaborator

In inventor vba, it can be tested like this

In apprentice you'll need to change it to ApprenticeServerDocument

 

Sub CheckForIpart()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Debug.Print oDoc.ComponentDefinition.IsiPartFactory

End Sub
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 5

JeffYao28
Enthusiast
Enthusiast

 

Hi Frederic,

 

Thank you much for the prompt response! I guess I'd appreciate more of  the Apprentice Service method, because it might be faster to open a document. My code is like below:

 

Inventor.ApprenticeServerDocument objApprenticeServerDocument;
//open the specified file
objApprenticeServerDocument = objapprenticeServerApp.Open(txtFileName.Text);

Inventor.ComponentDefinition definition1 = objApprenticeServerDocument.ComponentDefinition;

 

But Inventor.ComponentDefinition doesn't have IsiPartFactory property.

 

My C# project reference to Apprentice is  C:\WINDOWS\assembly\GAC_MSIL\Autodesk.Inventor.Interop\16.0.0.0__d84147f8b4276564\Autodesk.Inventor.Interop.dll

 

I'd appreciate this "IsiPartFactory" property when I'm opening thousands of part files in batch process to re-organize the documents. I think to open these documents using Inventor API (not Apprentice) can be quite time consuming. But Apprentice seems to be much faster.

 

Thank you!

 

Jeff Yao

0 Likes
Message 4 of 5

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi Jeff,

 

You could cast the ComponentDefinition to a PartComponentDefinition and then use the IsiPartFactory property. Below is the code I used to test. I added a button to the form in this SDK sample:

C:\Users\Public\Documents\Autodesk\Inventor 2017\SDK\DeveloperTools\Samples\VCSharp.NET\Standalone Applications\ApprenticeServer\AssemblyTree

 

(there is no error checking to see that the ApprenticeServerDocument is an ipt)

 

        private void button1_Click(object sender, EventArgs e)
        {
            Inventor.ApprenticeServerDocument objapprenticeServerDocument;
            string strFileName = @"C:\Users\brillw\Documents\Inventor\WB_2-18-16\iPart_Test_WB.ipt";

            //string strFileName = @"C:\Users\brillw\Documents\Inventor\WB_2-18-16\cylinder.ipt";
            //open the specified file
            objapprenticeServerDocument = objapprenticeServerApp.Open(strFileName);

            Inventor.PartComponentDefinition prtCompDef = (Inventor.PartComponentDefinition)objapprenticeServerDocument.ComponentDefinition;
            bool bIsIpart = prtCompDef.IsiPartFactory;
  
        }

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 5 of 5

JeffYao28
Enthusiast
Enthusiast

 

Hi Wayne,

 

Your code worked. Thank you so much!

 

Jeff Yao

0 Likes