Inventor Customization

Reply
Valued Contributor
rthelkap
Posts: 73
Registered: ‎11-01-2006
Message 1 of 6 (889 Views)

Open document in last saved Level of Detail representation.

889 Views, 5 Replies
09-26-2010 11:42 PM

Hello,

 

Our requirement is to open an assembly in the  Level of Detail representation  in which the assembly was last saved.

 

When we open an assembly through "File->Open" , Inventor opens the assembly correctly in last saved Level of Detail representation.

 

But when assembly is opened through API Documents->Open(), the file always opens in Master Level of Detail representation.

 

I understand that Documents->OpenWithOptions() can be used to open document in desired LOD, but in this case we do not know the last saved LOD for the assembly, and hence the name can not be supplied to Documents->OpenWithOptions().

 

Is there a way through APIs to open assembly in last saved LOD?

[ We are using Inventor 2010 SP3]

 

Thank You,

Rthelkap

Board Manager
sanjay.ramaswamy
Posts: 107
Registered: ‎11-13-2007
Message 2 of 6 (882 Views)

Re: Open document in last saved Level of Detail representation.

09-27-2010 03:47 PM in reply to: rthelkap

Get the last active representation using FileManager.GetLastActiveLevelOfDetailRepresentation and use that LOD in the OpenWithOptions method.

 

Valued Contributor
rthelkap
Posts: 73
Registered: ‎11-01-2006
Message 3 of 6 (869 Views)

Re: Open document in last saved Level of Detail representation.

09-27-2010 10:55 PM in reply to: sanjay.ramaswamy

Hello Sanjay,

 

 Thank you for the reply. I am able to open assembly in last saved LOD through regular Inventor APIs.

  

Sometimes we also need to open assemblies in last saved LOD, using apprentice server component.

But ApprenticeServer.OpenWithOptions() throws exception "the parameter is incorrect"

  

 

the sample code is as shown below

  

 

BSTR GetLastLOD(BSTR bstrFilePath)     // returns last LOD

 {

  BSTR bstrLastLOD;

  FileManagerPtr spFileManager = 0;

  spFileManager = spApp->FileManager;

  bstrLastLOD = spFileManager->MethodGetLastActiveLevelOfDetailRepresentation(bstrFilePath);

  return bstrLastLOD;

 }

 

 ApprenticeServerDocumentPtr OpenDocApprenticeWithOptions()

 {

  HRESULT hr = S_OK;

  ApprenticeServerDocumentPtr spDocument = 0;

  NameValueMapPtr docOpenOptions = spApprenticeServer->TransientObjects->MethodCreateNameValueMap();

 if(docOpenOptions != 0)

 { 

   BSTR bstrFilePath = ::smileyfrustrated:ysAllocString(L"E:\\INV_WORK_DIR\\files\\Assembly1.iam");

   BSTR bstrLastLOD = GetLastLOD(bstrFilePath);

   docOpenOptions->MethodAdd(L"LevelOfDetailRepresentation", bstrLastLOD);

 

   //This line MethodOpenWithOptions() throws exception "the parameter is incorrect"

 

   spDocument = spApprenticeServer->MethodOpenWithOptions(bstrFilePath,docOpenOptions);

 

   SysFreeString(bstrLastLOD);

   SysFreeString(bstrFilePath);

 }

return spDocument;

}

 

Is there anything wrong here or MethodOpenWithOptions() method not supported through apprentice?

 

Thank you,

 Rakesh

 

 

 

 

 

 

 

Board Manager
sanjay.ramaswamy
Posts: 107
Registered: ‎11-13-2007
Message 4 of 6 (855 Views)

Re: Open document in last saved Level of Detail representation.

09-28-2010 11:06 AM in reply to: rthelkap

You're right. Apprentice does seem to have a problem with the OpenWithOptions method. I'll have this issue filed in our database. Thanks for reporting.

 

Luckily, there's an alternate way to open a document with a specific LOD. The following VB code should demonstrate...

 

    Dim strFullFileName As String
    strFullFileName = "C:\temp\Assembly1.iam"
       
    ' Set a reference to the FileManager object.
    Dim oFileManager As FileManager
    Set oFileManager = oApprentice.FileManager
    
    ' Get the name of the last active Level of Detail (LOD) Representation.
    Dim strLastActiveLOD As String
    strLastActiveLOD = oFileManager.GetLastActiveLevelOfDetailRepresentation(strFullFileName)
    
    ' Use the full file name and LOD name to get the full document name.
    Dim strFullDocumentName As String
    strFullDocumentName = oFileManager.GetFullDocumentName(strFullFileName, strLastActiveLOD)
    
     ' Create a new NameValueMap object
    Dim oDocOpenOptions As NameValueMap
    Set oDocOpenOptions = oApprentice.TransientObjects.CreateNameValueMap

    ' Open the document.
    Dim oDoc As ApprenticeServerDocument
    Set oDoc = oApprentice.OpenWithOptions(strFullDocumentName, oDocOpenOptions)

 

Valued Contributor
rthelkap
Posts: 73
Registered: ‎11-01-2006
Message 5 of 6 (843 Views)

Re: Open document in last saved Level of Detail representation.

09-29-2010 04:04 AM in reply to: rthelkap

Hello Sanjay,

The alternate solution is working to open assembly in specified LOD using apprentice.

 

I am facing another issue w.r.to replacing suppressed components of an assembly when assembly is opened in apprentice.

 

When an assembly that is in non-master LOD(meaning few components are suppressed) is opened in apprentice server,

the RreplaceReference() is not working.

 

e.g.

Let us say an assembly has single part that is suppressed, and say the LOD is "LevelOfDetail1". Now open the assembly using apprentice in "LevelOfDetail" then try to perform replace reference.

 

The sample code is as below

 

ApprenticeServerDocumentPtr spDocument = function_to_get_assemblydoc(path) //as per the suggested method,

FilePtr spFile = spDocument->File;

FileDescriptorsEnumeratorPtr spFileDescEnum = spFile->ReferencedFileDescriptors;

long

nCountOfRefFiles = spFileDescEnum->Count;

for

{

 FileDescriptorPtr spFileDescriptor;

 spFileDescriptor = spFileDescEnum->GetItem(i);

 if(spFileDescriptor != NULL)

 {

   for(long i = 1; i <= nCountOfRefFiles; i++)

    //Say original location is E:\\INV_WORK_DIR\\files\\Part1.ipt, and this  needs to be replaced.

    //The below line is throwing exception

     hr = spFileDescriptor->MethodReplaceReference(L"E:\\INV_WORK_DIR\\edit\\Part1.ipt");

 }

 //Save assembly because components are replaced

 FileSaveAsPtr spFileSaveAs = spApprenticeServer->FileSaveAs;

 spFileSaveAs->MethodAddFileToSave(spDocument,spDocument->FullFileName);

 spFileSaveAs->MethodExecuteSave();

}

 

If the same code executed using regular Inventor APIs, i.e, if we open assembly using Documents->OpenWithOptions() in "LevelofDetail1" the above code works and the suppressed components are also replaced.

 

If assembly is opened in Apprentice in master LOD, only then all the components are getting replaced.

 

Thank You,

Rakesh

Board Manager
sanjay.ramaswamy
Posts: 107
Registered: ‎11-13-2007
Message 6 of 6 (837 Views)

Re: Open document in last saved Level of Detail representation.

09-29-2010 12:09 PM in reply to: rthelkap

Unfortunately, this is a known limitation. In Apprentice, you'll need to open the Master rep to replace references.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube