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: 

Unable to set light vector with VB.net

0 REPLIES 0
Reply
Message 1 of 1
dschwab
124 Views, 0 Replies

Unable to set light vector with VB.net

I have been building automations that save custom Attributes to DesignViewRepresentation objects so I can batch render with custom PerspectiveAngle and ActiveLightingStyle.Lights. I can change the Intensity of a light, but I have been unable to change the Direction vector successfully. It just doesn't update the values. Any ideas?

 

Attachment: The attached should run in an assembly. Clicking "no" should allow you to change lighting properties or FOV for the specific view. Then it will open another dialogue for some finer control. I have some debug info showing once you have gone through this process to save lighting. You will need two views with different lights to see it fail. Pardon my syntax, I am self-taught.

 

TLDR: Inventor light direction vectors don't want to change? Help!

 

Most relevant code: Start at line 25 (127 in attachment)

' RESTORE VIEW v1.2
Function RestoreView(oView As DesignViewRepresentation) As Boolean
		Dim TransVals As New List(Of String)
		Dim InvisVals As New List(Of String)
		
		Try

			For Each oAttributeSet As AttributeSet In oView.AttributeSets
			If oAttributeSet.Name = "TransparentOccurrences"
				
				For Each oAttribute As Attribute In oAttributeSet
					If oAttribute.Name.Contains("Trans") Then TransVals.Add(oAttribute.Value)
					If oAttribute.Name.Contains("Invis") Then InvisVals.Add(oAttribute.Value)
				Next
				
			Else If oAttributeSet.Name = "FieldOfView"
				
				Try
					If oAttributeSet.Item(1).Value = 0 Then oAttributeSet.Item(1).Value = .65
					CurrentCamera.PerspectiveAngle = oAttributeSet.Item(1).Value
				Catch
					oAttributeSet.Delete
				End Try
				
			Else If oAttributeSet.Name = "ViewLighting"
				
				
				'///////////// DEBUG //////////////
				MsgBox("saved light 1 vector: " & oAttributeSet.Item(1).Value & " x " & oAttributeSet.Item(2).Value & " x " & oAttributeSet.Item(3).Value)
				MsgBox("saved light 2 vector: " & oAttributeSet.Item(5).Value & " x " & oAttributeSet.Item(6).Value & " x " & oAttributeSet.Item(7).Value)
				
				'attempt 1
				oAssembly.ActiveLightingStyle.Lights.Item(1).Direction.X = oAttributeSet.Item(1).Value
				oAssembly.ActiveLightingStyle.Lights.Item(1).Direction.X = oAttributeSet.Item(1).Value
				oAssembly.ActiveLightingStyle.Lights.Item(1).Direction.X = oAttributeSet.Item(1).Value
				oAssembly.ActiveLightingStyle.Lights.Item(1).Intensity = oAttributeSet.Item(4).Value
				
				'attempt 2
				oAssembly.ActiveLightingStyle.Lights.Item(2).Direction.PutVectorData({oAttributeSet.Item(5).Value, oAttributeSet.Item(6).Value, oAttributeSet.Item(7).Value})
				oAssembly.ActiveLightingStyle.Lights.Item(2).Intensity = oAttributeSet.Item(8).Value
				
				'///////////// DEBUG //////////////
				MsgBox("actual light 1 vector: " & oAssembly.ActiveLightingStyle.Lights.Item(1).Direction.X & " x " & oAssembly.ActiveLightingStyle.Lights.Item(1).Direction.Y & " x " & oAssembly.ActiveLightingStyle.Lights.Item(1).Direction.Z)
				MsgBox("actual light 2 vector: " & oAssembly.ActiveLightingStyle.Lights.Item(2).Direction.X & " x " & oAssembly.ActiveLightingStyle.Lights.Item(2).Direction.Y & " x " & oAssembly.ActiveLightingStyle.Lights.Item(2).Direction.Z)
				
				
			End If
		Next
		Dim oComponent As ComponentOccurrence
		For Each oComponent In oAssembly.ComponentDefinition.Occurrences
			If Not(oComponent.Suppressed)
				If InvisVals.Contains(oComponent.Name) Then
					oComponent.Transparent = False
					oComponent.Visible = False
				Else If TransVals.Contains(oComponent.Name) Then
					oComponent.Transparent = True
					oComponent.Visible = True
				Else If IsHallPart(oComponent.Name) Then
					oComponent.Visible = False
				Else
					oComponent.Transparent = False
					oComponent.Visible = True
				End If
			End If
		Next

		'set camera location
		CurrentCamera.ApplyWithoutTransition
		oView.RestoreCamera()
		
	Catch ' it is possible to lose views. The view is deleted, but still is counted in the count. Weird. This catches it.
		Return False ' failed
	End Try
	
	Return True
End Function

 

 

 

 

Labels (2)
0 REPLIES 0

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report