ActiveLevelOfDetailRepresentation throws exception in Inventor 2012

ActiveLevelOfDetailRepresentation throws exception in Inventor 2012

rthelkap
Enthusiast Enthusiast
553 Views
3 Replies
Message 1 of 4

ActiveLevelOfDetailRepresentation throws exception in Inventor 2012

rthelkap
Enthusiast
Enthusiast

Hello,

 

The below code to get the current Level Of Detail name of an assembly, using Apprentice APIs not working on Inventor 2012 64 bit( I have not tested on Inventor 2012 32 bit).

 

On Inventor 2012 64 bit,(using Apprentice APIs) RepresentationsManagerPtr ->ActiveLevelOfDetailRepresentation() is throwing exception as indicated in the below code.

 

This used to work on Inventor 2010 and Inventor 2011.

 

Sample code is as below.

 

CString GetCurrentLODName(ApprenticeServerDocumentPtr spApprenticeDoc)
{
	CString strCurrentLOD;
	AssemblyComponentDefinitionPtr spAsseyCompDef = 0;
	RepresentationsManagerPtr spRepsMgr =  0;
	LevelOfDetailRepresentationPtr spLevelOfRep = 0;

	if(spApprenticeDoc != 0)
		spAsseyCompDef = spApprenticeDoc->ComponentDefinition;
	if(spAsseyCompDef != 0)
		spRepsMgr = spAsseyCompDef->RepresentationsManager;	
	if(spRepsMgr != 0)
		spLevelOfRep = spRepsMgr->ActiveLevelOfDetailRepresentation; //this line throws exception
	if(spLevelOfRep != NULL)
	{
		_bstr_t bstrLODName = spLevelOfRep->Name;
		strCurrentLOD.Format(L"%s",(LPCTSTR)bstrLODName); 
	}
	return strCurrentLOD;
}

Instead of Apprentice APIs, I have tried to get LOD name using Inventor APIs, and it works fine.

 

AssemblyDocument->ComponentDefinition->RepresentationsManager->ActiveLevelOfDetailRepresentation() works fine.

 

Is there any issue with getting Last LOD in Inventor 2012 64 bit, through Apprentice?

 

Thank you,

Rakesh

 

 

0 Likes
554 Views
3 Replies
Replies (3)
Message 2 of 4

YuhanZhang
Autodesk
Autodesk

Hi Rakesh,

 

I noticed this regression, and we have addressed this issue, you can supply change request ID 1404621 for progress info. And as a workaround currently I think you can try FileManager.GetLastActiveLevelOfDetailRepresentation.

 

Sorry for any inconvenience to you.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 4

rthelkap
Enthusiast
Enthusiast

Hello Rocky,

 

I understand that FileManager.GetLastActiveLevelOfDetailRepresentation() returns the last active LOD in which assembly was last saved. But ActiveLevelOfDetailRepresentation returns the current LOD in which assembly is opened which may not be same as last active LOD (returned by GetLastActiveLevelOfDetailRepresentation()). 

 

I have also observed that when an assembly is opened using ApprenticeServer.Open(), it always opens in "Master" LOD irrespective of the last saved LOD. So We can assume that the Current LOD will always be "Master" when the assembly is opened using Apprentice, without using "ActiveLevelOfDetailRepresentation". 

 

But one issue with this assumption seems to be that a different language version of Inventor(e.g, german version) may use a different string indicating "Master" LOD.

 

Could you please confirm if the above assumption that assembly always opens in "Master" LOD when opened in Apprentice is correct?

 

Thank you,

Rakesh

 

0 Likes
Message 4 of 4

YuhanZhang
Autodesk
Autodesk

Hi Rakesh,

 

I agree that the FileManager.GetLastActiveLevelOfDetailRepresentation won't tell the cuttent active LOD. The ApprenticeServer.Open() can accept a full document name or full file name, so if you pass in the assembly full file name(like "C:\myassy.iam"), then it will open the assembly with the master LOD, but if you pass in a full document name with LOD specified(like "C:\myassy.iam<LevelofDetail1>"), then it will open the assembly with the specified LOD activated.

 

So a possible workaround to know the current active LOD maybe that you check the opened document's FullDocumentName to get the active LOD. I code below function to check the active LOD with FullDocumentName:

 

Sub FindActiveLOD(oDoc As ApprenticeServerDocument)
    Dim oRepMgr As RepresentationsManager
    Set oRepMgr = oDoc.ComponentDefinition.RepresentationsManager
 
    If oDoc.FullDocumentName = oDoc.FullFileName Then
        Debug.Print "Active LOD is: " & oRepMgr.LevelOfDetailRepresentations(1).Name
    Else
        Dim oLOD As LevelOfDetailRepresentation
        For Each oLOD In oRepMgr.LevelOfDetailRepresentations
            If InStr(1, oDoc.FullDocumentName, oLOD.Name) Then
                Debug.Print "Active LOD is: " & oLOD.Name
                Exit For
            End If
            
        Next
    End If
End Sub

 

Note:if the FullDocumentName is the same as FullFileName, then the active LOD is master(localized Inventor should have the local language string), but the master LOD should always be the first LOD in the LevelOfDetailRepresentations collection. 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes