Inventor Customization

Inventor Customization

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

Open document in last saved Level of Detail representation.

952 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: 112
Registered: ‎11-13-2007
Message 2 of 6 (945 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 (932 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: 112
Registered: ‎11-13-2007
Message 4 of 6 (918 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 (906 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: 112
Registered: ‎11-13-2007
Message 6 of 6 (900 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.