- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Please could you help me to set the active lighting style with iLogic?
This code will get the active lighting style name, but I can't set the active lighting style - what am I missing?
Dim oAssy As AssemblyDocument = ThisApplication.ActiveDocument Dim oLightStyleName As String oLightStyleName = oAssy.ActiveLightingStyle.Name MessageBox.Show(oLightStyleName, "Title") 'This line doesn't work oAssy.ActiveLightingStyle.Name = "Grid Light"
P.S. I found this post on the manufacturing dev blog. I have converted it to iLogic, but it doesn't work for me ![]()
http://adndevblog.typepad.com/manufacturing/2015/07/change-activelightingstyle.html
Sub ChangeLightingStyle()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim lss As LightingStyles
Set lss = doc.LightingStyles
' Let's just use the first style
' InternalName: "1:Cool Light"
doc.ActiveLightingStyle = lss("1:Cool Light")
End Sub
Customer Adoption Specialist | Informed Design
Opinions are my own and may not reflect those of my company.
Linkedin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @PaulMunford,
Long time no see around these parts ![]()
I ran your code and it worked the first time, but not after that in a newly created assembly file.
The reason for this is because you were changing the name (of the active lightingstyle) to the string you desired with this line, not changing the active lightingstyle to it:
oAssy.ActiveLightingStyle.Name = "Grid Light"
I've knocked up this simple rule:
Dim oAssy As AssemblyDocument = ThisApplication.ActiveDocument
Dim oLightStyleName As String
oLightStyleName = oAssy.ActiveLightingStyle.Name
MessageBox.Show(oLightStyleName, "Title")
Dim lightingstyletochangeto As LightingStyle = oAssy.LightingStyles.Item("Grid Light")
If Not oAssy.ActiveLightingStyle.Name = lightingstyletochangeto.Name Then
oAssy.ActiveLightingStyle = lightingstyletochangeto
InventorVb.DocumentUpdate()
Else
MessageBox.Show("We're already using the desired lighting style!")
End IfWhich appears on the surface to answer your question. When it runs however, the active lightingstyle on the "View" tab of the Inventor interface doesn't seem to update so there must either be:
- a bug OR
- a missing update function I haven't used to update the Inventor interface
I'm not sure which without further investigation.
Cheers,
Alex.
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try below iLogic code to set lightstyle.
Dim doc As Document
doc = ThisApplication.ActiveDocument
Dim ls As LightingStyle
If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oAssy As AssemblyDocument
oAssy = doc
ls = oAssy.LightingStyles.Item("Grid Light")
oAssy.ActiveLightingStyle = ls
Else If doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPart As PartDocument
oPart = doc
ls = oPart.LightingStyles.Item("Grid Light")
oPart.ActiveLightingStyle = ls
End If
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It was so much easier when I could just stop by your desk ![]()
Thanks very much for that - it's ideal. I understand now that I need to call it up as an item, not just change it's name. I need to get better at browsing the object model and understanding hat I can do with it ![]()
I will be back with my next question shortly - i'm sure!
Paul
Customer Adoption Specialist | Informed Design
Opinions are my own and may not reflect those of my company.
Linkedin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Awesome!
Thanks @chandra.shekar.g you anticipated my next task:)
My ultimate goal is to create an iLogic rule that will step through all files in an assembly, open the file, change the lighting style and save the file - to update the thumbnail.
Paul
Customer Adoption Specialist | Informed Design
Opinions are my own and may not reflect those of my company.
Linkedin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
psuedo-code for that would be something like:
Sub Main()
dim stylename as string = "My Chosen Stylename"
For each doc as Document in ThisAssembly.AllReferencedDocuments
If typeof doc is PartDocument then
setPartLighting(stylename)
else 'assembly
setAssemblyLighting(stylename)
end if
Next
End Sub
Sub SetPartLighting(Byval stylename as string)
'copy in the answers from above and hope the magic smoke doesn't escape!
End Sub
Sub SetAssemblyLighting(Byval stylename as string)
'copy in the answers from above and hope the magic smoke doesn't escape!
End Sub
![]()
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That looks encouraging!
I had the error:
'AllReferencedDocments' is not a member of 'Autodesk.iLogic.Interfaces.iManagedAssembly' ?
So I changed it to:
ThisAssembly.Document.AllReferencedDocuments
The code runs - but it doesn't seem to work ![]()
An additional question, would the part file actually need to be opened and saved to get the thumbnail to update?
Customer Adoption Specialist | Informed Design
Opinions are my own and may not reflect those of my company.
Linkedin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You saw the bit in my reply that said "pseudo-code" right?
![]()
The best thing you can do is share what code you have for me/others to see.
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example