Setting representation Level of Detail fails due to suppressed part

Setting representation Level of Detail fails due to suppressed part

Guido.LangeTuchscherer
Enthusiast Enthusiast
991 Views
9 Replies
Message 1 of 10

Setting representation Level of Detail fails due to suppressed part

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Hello nice peaople,

 

I set the LOD before doing some other stuff, which works fine as long as there is no suppressed subpart in the assembly. It crashes or fails when there is a suppressed part in the assembly, but I can't figure out why.

Second time, when whyever LOD 1 is created it works.

 

					Dim asDoc As AssemblyDocument = ThisDoc.Document
					aComp = asDoc.ComponentDefinition
					
					'Position der Detailgenauigkeit erfassen
					Dim ActLOD As String = aComp.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name
					
					Try
						aComp.RepresentationsManager.LevelOfDetailRepresentations.Item("My LOD").Activate(True)
					Catch
						aComp.RepresentationsManager.LevelOfDetailRepresentations.Add("My LOD")
						aComp.RepresentationsManager.LevelOfDetailRepresentations.Item("My LOD").Activate(True)
					End Try



 

Falscher Parameter. (Ausnahme von HRESULT: 0x80070057 (E_INVALIDARG))

0 Likes
Accepted solutions (1)
992 Views
9 Replies
Replies (9)
Message 2 of 10

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Ok got it nearly.

If I check is the current LOD is active (which is not the case, if there have been changes to unsaved doc), then i can set the default LOD before doing what i need, and thereby not getting an error.

But I would prefer to let the user save the current LOD if it has not been created yet.

 

					Dim asDoc As AssemblyDocument = ThisDoc.Document
					aComp = asDoc.ComponentDefinition
					
					'Position der Detailgenauigkeit erfassen
					Dim ActLOD As String = aComp.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name
					
					If Not aComp.RepresentationsManager.LevelOfDetailRepresentations.Item(ActLOD).Activate(True) Then
'							MsgBox("Konnte gesetzt werden")
							'Detailgenauigkeit speichern?
							ActLOD = "Hauptansicht"
							aComp.RepresentationsManager.LevelOfDetailRepresentations.Item(ActLOD).Activate(True)
					End If
					
					Try
						aComp.RepresentationsManager.LevelOfDetailRepresentations.Item("My LOD").Activate(True)
					Catch
						aComp.RepresentationsManager.LevelOfDetailRepresentations.Add("My LOD")
						aComp.RepresentationsManager.LevelOfDetailRepresentations.Item("My LOD").Activate(True)
					End Try

 

0 Likes
Message 3 of 10

Hi there, and in different words, as far as I got, do some of you maybe know how to decifer if a level of detail actually exists?

 

Just after suppressing a part in an assembly, I can get the active LOD and then my way was to use Try (Catch) to activate the LOD (if existing), which unfortunately always succeeds, it just writes a new actual one. When the active LOD actually exists there is no problem, but when there only is a temporary one it will generate new LOD everytime I save.

 

Dim asDoc As AssemblyDocument = ThisDoc.Document
aComp = asDoc.ComponentDefinition

'Position der Detailgenauigkeit erfassen
Dim ActLOD As String = aComp.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name

Try aComp.RepresentationsManager.LevelOfDetailRepresentations.Item(ActLOD).Activate(True) 'MsgBox(ActLOD & " gesetzt") Catch AcLOD = "TempDetailgenauigkeit" 'MsgBox(AcLOD & " erstellt") 'Finally aComp.RepresentationsManager.LevelOfDetailRepresentations.Add(AcLOD) 'MsgBox(AcLOD & " aktiviert") End Try 

 

0 Likes
Message 4 of 10

dutt.thakar
Collaborator
Collaborator

@Guido.LangeTuchscherer 

 

If you are thinking about finding a specific LOD that is there in the assembly or not, you may be able to use For loop and iterate the collection of LODs and check if the one you are looking for exists or not and if it exists, Inventor will be able to activate it, and if it does not it can create it.

 

Are you looking for something like that?

 

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 5 of 10

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Hi @dutt.thakar, thanks for the input,

 

unfortunately exactly this does not work.

You can try the following :

  1. Have an assembly with 2 parts
  2. Save it
  3. Suppress one of the parts, this will generate a new active LOD
  4. run the code (dont save), the active LOD will be shown in the list of the existing LOD's although it doesn't
  5. There seems to be no place/option where to look for the actual existing LOD's

I wrote a kind of a workaround now, where i simply assume that if the active LOD is the last one in the list it doesn't exist. Which is well ok as long as not the Last one is active.

 

Dim oDoc As AssemblyDocument = ThisDoc.Document  
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition 

Dim ActLOD As String = oDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.name

Dim oList As New ArrayList

For i As Integer = 1 To oDef.RepresentationsManager.LevelOfDetailRepresentations.count
	oList.Add( oDef.RepresentationsManager.LevelOfDetailRepresentations(i).name)
Next
'oList.Add(oDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name)

oValue = InputListBox("Select LOD", oList, ActLOD, "Ilogic - LOD", "Available Selections")

oDef.RepresentationsManager.LevelOfDetailRepresentations.Item(oValue).Activate(True)

 

0 Likes
Message 6 of 10

dutt.thakar
Collaborator
Collaborator
Accepted solution

@Guido.LangeTuchscherer 

 

Ok, I am still trying to understand your point and what you are trying to achieve, Inventor generates an LOD, when we suppress the part, but it is not added in LOD list until the assembly is saved, and we can not get that from LOD collection, I agree there.

 

I have found a workaround where you can see if there is any unsaved LOD exist, It is not reliable but may be able to serve your purpose, Whenever any part is suppressed in Inventor it by default creates a LOD, and the name is always containing "LevelofDetail", and the same is reflected at the top in assembly name. What I did in below code as a starter is to see if the assembly display name contains the word "LevelofDetail" if it does that means there is an unsaved LOD. See the below code, it will also show the name of the unsaved LOD in the messagebox.

 

Dim asDoc As AssemblyDocument = ThisDoc.Document
Dim aComp As AssemblyComponentDefinition = asDoc.ComponentDefinition

Dim LOD As LevelOfDetailRepresentation = asDoc.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation
Dim Str As String

'MessageBox.Show(asDoc.DisplayName)

If asDoc.DisplayName.Contains("LevelofDetail")
	MessageBox.Show("There is an active unsaved LOD",LOD.Name)
	
	
End If

 

Hope this will be a small help in your goal. Kindly reply here and we can try to solve your problem in more detail.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 7 of 10

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Hi @dutt.thakar thanks alot,

 

did not think of that, seems to work well and much better than my way and saves me some lines of code as well.

 

Thanks!

 

0 Likes
Message 8 of 10

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Just for explaining reasons,

 

I am trying to get the current LOD, checking if it is existing or not.

In case it exist continue my code, if it doesn't exist save it into a temporary LOD to active after my code.

 

My code adds a new LOD in which all referenced parts are suppressed, cycling though all the subparts and subassemblies in an assembly and after that reading the rangebox measures to ensure as close as possible measures of the current active assembly.

0 Likes
Message 9 of 10

Guido.LangeTuchscherer
Enthusiast
Enthusiast

I actually found an even better solution to check if the Active LOD current Browser Node exists, using this:

https://forums.autodesk.com/t5/inventor-customization/how-to-copy-a-level-of-detail-to-a-design-view...

 

Dim asDoc As AssemblyDocument = ThisDoc.Document
aComp = asDoc.ComponentDefinition

'Position der Detailgenauigkeit erfassen
Dim ActLOD As String = aComp.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name

Dim LODact As LevelOfDetailRepresentation = aComp.RepresentationsManager.ActiveLevelOfDetailRepresentation
LODrep = aComp.RepresentationsManager.LevelOfDetailRepresentations
'Dim Str As String

Dim oLODRep As LevelOfDetailRepresentation = asDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Item(ActLOD)
	  
'  asDoc.BrowserPanes.Item("Model").Activate
  
  Dim oNativeBrowserNodeDef As NativeBrowserNodeDefinition 
  
  Try 
  oNativeBrowserNodeDef = asDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oLODRep)
  MsgBox(ActLOD & " | " & "Aktiv vorhanden")
Catch 
	MsgBox(ActLOD & " | " & "Aktive nicht vorhanden")
End Try
0 Likes
Message 10 of 10

Cleaned up the code and found out how to read the node of LOD whereby you can identify if it exists or not.

 

Dim asDoc As AssemblyDocument = ThisDoc.Document
aComp = asDoc.ComponentDefinition

'Position der Detailgenauigkeit erfassen
Dim ActLOD As String = aComp.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name

'Definieren der Detailgenauigkeit
Dim oLODRep As LevelOfDetailRepresentation = asDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Item(ActLOD)
	  
'Browser knoten definieren
Dim oNativeBrowserNodeDef As NativeBrowserNodeDefinition 

'Versuchen die Aktive Detailgenauigkeit im Browserknoten zu definieren
Try 
	oNativeBrowserNodeDef = asDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oLODRep)
'	MsgBox(ActLOD & " | " & "Aktiv vorhanden")
Catch 
'	MsgBox(ActLOD & " | " & "Aktive nicht vorhanden")
	ActLOD = "Hauptansicht"
End Try
  
			'Temporäre und für Abmessungen notwendige Detailgenauigkeit erstellen
			Try 'Für Abmessungen ohne Referenzbauteile
				aComp.RepresentationsManager.LevelOfDetailRepresentations.Item("Ohne Referenzbauteile").Activate(True)
			Catch 
				aComp.RepresentationsManager.LevelOfDetailRepresentations.Add("Ohne Referenzbauteile")
				aComp.RepresentationsManager.LevelOfDetailRepresentations.Item("Ohne Referenzbauteile").Activate(True)
			End Try

			'Alle referenzbauteile unterdrücken
			Dim aOcc As ComponentOccurrence

			' Für jede Occurrence (subobjekt in BG) prüfen ob Referenzteil und wenn ja unterdrücken
			For Each aOcc In aComp.Occurrences
				If aOcc.BOMStructure = kReferenceBOMStructure Then
						'dann unterdrücken
						aOcc.Suppress
				Else
					aOcc.Unsuppress
				End If
			Next
  
  		XMax = Round(Measure.ExtentsLength, 0)
		YMax = Round(Measure.ExtentsWidth, 0)
		ZMax = Round(Measure.ExtentsHeight, 0)

		'write measures into iProperty, L=x, B=y, H=z
		iProperties.Value("Custom", "Abmessung-Test") = XMax & " x " & YMax & " x " & ZMax '& " mm"
  
  'Anschließend wieder Detailgenauigkeit von vorher oder Temp aktivieren
aComp.RepresentationsManager.LevelOfDetailRepresentations.Item(ActLOD).Activate(True)

 

Somehow this fails though in my main routine, something with the try catch which makes trouble.

0 Likes