By Wayne Brill
There is not any Inventor API for Inventor Studio. A work around to control a setting for rendering as shown in this screenshot is to change the value of an Inventor attribute named “com.autodesk.archon.rendering that is stored in the document”.
Here is a VBA example that changes the “Render by iteration” setting.
Sub InventorStudioRenderOptions_test() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument If oDoc.DocumentType kPartDocumentObject And _ oDoc.DocumentType kAssemblyDocumentObject Then MsgBox "Please open a part or assembly document!" Exit Sub End If Dim oCompDef As ComponentDefinition Set oCompDef = oDoc.ComponentDefinition Dim oAttSet As AttributeSet If oCompDef.AttributeSets.NameIsUsed("com.autodesk.archon.rendering") Then Set oAttSet = oCompDef.AttributeSets("com.autodesk.archon.rendering") Else Set oAttSet = oCompDef.AttributeSets.Add("com.autodesk.archon.rendering") End If Dim oAtt As Inventor.Attribute If oAttSet.NameIsUsed("Options") Then Set oAtt = oAttSet.Item("Options") 'Get the value of the attribute Dim strAttValue As String strAttValue = oAtt.Value Dim XDoc As Object Set XDoc = CreateObject("MSXML2.DOMDocument") XDoc.async = False: XDoc.validateOnParse = False ' load the value of the Inventor attribute into the XML doc XDoc.loadXML strAttValue Dim optionsXMLNodeSel As Object Set optionsXMLNodeSel = XDoc.selectNodes("Options") Dim optionsXMLElement As IXMLDOMElement Set optionsXMLElement = optionsXMLNodeSel(0) Dim strAtt As String strAtt = optionsXMLElement.getAttribute("RayTracingDuration") ' Change the option (XML attribute) Call optionsXMLElement.setAttribute("RayTracingDuration", 45) 'Update the Inventor attribute oAtt.Value = XDoc.XML Else Dim sWidth As String, sHeight As String sWidth = oDoc.Views(1).Width sHeight = oDoc.Views(1).Height ' Set the Iteration value Dim sIteration As String sIteration = "80.0" Dim sValue As String sValue = "" & vbCrLf sValue = sValue & "" Set oAtt = oAttSet.Add("Options", kStringType, sValue) End IfEnd Sub
Here is the example in VB.NET
Need to add this imports for the XML objects:
Imports System.Xml
Sub InventorStudioRenderOptions_test() Dim oDoc As Document oDoc = m_inventorApp.ActiveDocument If oDoc.DocumentType DocumentTypeEnum.kPartDocumentObject And _ oDoc.DocumentType DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("Please open a part or assembly document!") Exit Sub End If Dim oCompDef As ComponentDefinition oCompDef = oDoc.ComponentDefinition Dim oAttSet As AttributeSet If oCompDef.AttributeSets.NameIsUsed("com.autodesk.archon.rendering") Then oAttSet = oCompDef.AttributeSets("com.autodesk.archon.rendering") Else oAttSet = oCompDef.AttributeSets.Add("com.autodesk.archon.rendering") End If Dim oAtt As Inventor.Attribute If oAttSet.NameIsUsed("Options") Then oAtt = oAttSet.Item("Options") 'Get the value of the attribute Dim strAttValue As String strAttValue = oAtt.Value Dim XDoc As XmlDocument XDoc = New XmlDocument ' load the value of the Inventor attribute into the XML doc XDoc.LoadXml(strAttValue) Dim optionsXMLNodeSel As Object optionsXMLNodeSel = XDoc.SelectNodes("Options") Dim optionsXMLElement As XmlElement optionsXMLElement = optionsXMLNodeSel(0) Dim strAtt As String strAtt = optionsXMLElement.GetAttribute("RayTracingDuration") ' Change the option (XML attribute) Call optionsXMLElement.SetAttribute("RayTracingDuration", 45) 'Update the Inventor attribute oAtt.Value = XDoc.InnerXml Else Dim sWidth As String, sHeight As String sWidth = oDoc.Views(1).Width sHeight = oDoc.Views(1).Height ' Set the Iteration value Dim sIteration As String sIteration = "80.0" Dim sValue As String sValue = "" & vbCrLf sValue = sValue & "" oAtt = oAttSet.Add("Options", ValueTypeEnum.kStringType, sValue) End IfEnd Sub


Leave a Reply