Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open document in last saved Level of Detail representation.

5 REPLIES 5
Reply
Message 1 of 6
rthelkap
2250 Views, 5 Replies

Open document in last saved Level of Detail representation.

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

5 REPLIES 5
Message 2 of 6
sanjay.ramaswamy
in reply to: rthelkap

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

 

Message 3 of 6
rthelkap
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 = ::SysAllocString(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

 

 

 

 

 

 

 

Message 4 of 6
sanjay.ramaswamy
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)

 

Message 5 of 6
rthelkap
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

Message 6 of 6
sanjay.ramaswamy
in reply to: rthelkap

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report