<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update IDW with each model state and save as separate PDF in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11621341#M146568</link>
    <description>&lt;P&gt;I haven't got to use model states yet but my assumption is that it is very similar to iparts. &lt;A href="https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/automate-idw-drawing-file-creation-for-all-ipart-members/m-p/9420094#M108255" target="_blank" rel="noopener"&gt;Here&lt;/A&gt; is a link to ipart workflow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the business portion of ipart view change for member.&amp;nbsp;&lt;/P&gt;&lt;P&gt;*********&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For i = 1 To iPartF.TableRows.Count - 1&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Set oPartDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Dim sPath As String&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sPath = Replace(oPartDoc.FullFileName, iPartF.FileNameColumn(i).Value, iPartF.FileNameColumn(i + 1).Value)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Call iPartF.CreateMember(i + 1)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sPath)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 01:18:19 GMT</pubDate>
    <dc:creator>A.Acheson</dc:creator>
    <dc:date>2022-12-15T01:18:19Z</dc:date>
    <item>
      <title>Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11618418#M146511</link>
      <description>&lt;P&gt;I am attempting to update some code I have used over the years to transition away from iFactories. The iLogic code below is currently located in an assembly file, though I'm trying to write it in a way that it will work in a parts file as well. So far it will iterate through each model state. When it comes to a value of true on the generate field*, it will execute the code to generate a PDF.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GeneratePrint mostly works. It will open the IDW and export as a PDF. However, the model state on the IDW does not change to whatever the current active model state is. It must be updated manually or through code. I have tried updating the IDW view from the assembly iLogic code, and I've tried to update it from the IDW. Neither is working very well for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, how do I change the model state on the IDW based on the active model state in the assembly/parts file through iLogic?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assembly code:&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub Main()
	Dim oDoc As Document
	oDoc = ThisApplication.ActiveDocument
	    
	Dim oDef As ComponentDefinition
	oDef = oDoc.ComponentDefinition
	
	Dim oStates As ModelStates 	
	oStates = oDef.ModelStates

	Dim oTable As ModelStateTable	
	oTable = oStates.ModelStateTable

	Dim oRow As ModelStateTableRow 
	For Each oRow In oTable.TableRows
		ThisDoc.ActiveModelState = oRow.MemberName
		
		If iProperties.Value("Custom", "Generate") = True Then
		    'MessageBox.Show(oRow.MemberName)
			GeneratePrint(iProperties.Value("Custom", "DWGTemplate"),iProperties.Value("Custom", "DWGNumber"), oRow.MemberName)
		End If
		
	Next
End Sub


Sub GeneratePrint(dwg_template As String, dwg_number As String, model_state_fin As String)
	Dim oDoc As DrawingDocument
	dwgFile = ThisDoc.Path &amp;amp; "\" &amp;amp; dwg_template &amp;amp; ".idw"
	
	'this will prevent faded images when generating pdf files
	ThisApplication.DrawingOptions.EnableBackgroundUpdates = False
'	'speed up the process
'	ThisApplication.ScreenUpdating = False

	'get PDF target folder path
	oFolder = ThisDoc.Path &amp;amp; "\PDF"
	pdfFile = oFolder &amp;amp; "\rsi" &amp;amp; dwg_number &amp;amp; ".pdf"
	
	'Check for the PDF folder and create it if it does not exist
	If Not System.IO.Directory.Exists(oFolder) Then
	    System.IO.Directory.CreateDirectory(oFolder)
	End If

	'RuleParametersOutput()
	iLogicVb.UpdateWhenDone = True
	InventorVb.DocumentUpdate()
	ThisDoc.Save
	
	oDoc = ThisApplication.Documents.Open(dwgFile)

'	ThisApplication.ScreenUpdating = True

	oDoc.SaveAs(pdfFile, True)
	oDoc.Close(True)

	'turn this back on, it will speed up regular use.
	ThisApplication.DrawingOptions.EnableBackgroundUpdates = True
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IDW code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub Main()
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim width As Double
	Dim length As Double
	Dim oScale As Double
	
	
	'get current active sheet
	Dim oSheet As Sheet
	oSheet = oDoc.ActiveSheet

	Dim oAssyDoc As AssemblyDocument
	ModelStateFile = ThisDoc.Path &amp;amp; "\" &amp;amp; "R39225-MD5-FIN" &amp;amp; ".iam"
	'oAssyDoc = ThisApplication.Documents.Open(ModelStateFile,False)

	'ActiveSheet.View("FRONT").View.SetActiveModelState(oAssyDoc.ActiveModelState)

	width = Parameter("R39225-MD5-FIN.iam.width")
	length = Parameter("R39225-MD5-FIN.iam.length")

	oScale = Round(Min(Min(ActiveSheet.Height / 2.5 / length, ActiveSheet.Width / 4.1 / width), .18), 2)
	ActiveSheet.View("FRONT").Scale = oScale
	ActiveSheet.View("BACK").Scale = oScale
	ActiveSheet.View("ISO").Scale = oScale

	'set active sheet back to original
	oSheet.Activate	
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*I had to use a custom iProperty to reference the value. I tried to find a way to read directly from the table row, but could not find a way to do this. If anyone knows how to read a cell value instead of having to place the value in an iProperty, that would be welcome information.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 23:21:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11618418#M146511</guid>
      <dc:creator>insomnix</dc:creator>
      <dc:date>2022-12-13T23:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11621186#M146567</link>
      <description>&lt;P&gt;I've attached two files, an ipt and idw. They are smaller than the assembly I was working on in the previous example. At this point everything works as expected, except how do I update the model state on the IDW?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 23:18:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11621186#M146567</guid>
      <dc:creator>insomnix</dc:creator>
      <dc:date>2022-12-14T23:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11621341#M146568</link>
      <description>&lt;P&gt;I haven't got to use model states yet but my assumption is that it is very similar to iparts. &lt;A href="https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/automate-idw-drawing-file-creation-for-all-ipart-members/m-p/9420094#M108255" target="_blank" rel="noopener"&gt;Here&lt;/A&gt; is a link to ipart workflow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the business portion of ipart view change for member.&amp;nbsp;&lt;/P&gt;&lt;P&gt;*********&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For i = 1 To iPartF.TableRows.Count - 1&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Set oPartDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Dim sPath As String&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;sPath = Replace(oPartDoc.FullFileName, iPartF.FileNameColumn(i).Value, iPartF.FileNameColumn(i + 1).Value)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Call iPartF.CreateMember(i + 1)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sPath)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 01:18:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11621341#M146568</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2022-12-15T01:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11623843#M146616</link>
      <description>&lt;P&gt;Model states are a bit different.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the idw I created a test rule and entered the below line, which switched the model state on the drawing. However, I cant figure out how I can use this line to assign the model state to the idw view from the iam or ipt. If you look at the ipt, I am already iterating through each model in the generate rule.&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;ActiveSheet.View("FRONT").View.SetActiveModelState("U420521A")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, I can't work out how to iterate through each model state from the IDW. The only reason I need to iterate through the model state is so I can capture the width and length parameters from the ipt to scale the drawing properly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 23:17:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11623843#M146616</guid>
      <dc:creator>insomnix</dc:creator>
      <dc:date>2022-12-15T23:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11623894#M146617</link>
      <description>&lt;P&gt;OK, forward movement. I found the line I need to change the model state in the view. Still some work to do here. There were some odd results with the part number field in the title block, like it wasn't updating with the model state change. I may just need to add a line to save before I print. Will try to work that out tomorrow unless someone has a suggestion.&amp;nbsp; Until then, the update I made to the generate rule is below.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;	oDoc = ThisApplication.Documents.Open(dwgFile)

	Dim View As DrawingView

	For Each sheet As Sheet In oDoc.Sheets
		Sheet.Activate
		Try
			If Sheet.DrawingViews.Count &amp;gt; 0 Then
		        For Each View In Sheet.DrawingViews
					If View.Name = "FRONT" Then
						View.SetActiveModelState(model_state_fin)
					End If
		        Next
		    End If
		Catch

		End Try
	Next&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 23:51:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11623894#M146617</guid>
      <dc:creator>insomnix</dc:creator>
      <dc:date>2022-12-15T23:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11623993#M146618</link>
      <description>&lt;P&gt;I never thought to look in the drawing view. To pick up the model state name to set active you will need to loop through the assembly/part model state table and generate the list you want and pick one to set active. Much like you would do for design view reps. You can pick up the model document from the&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;oView.ReferencedDocumentDescriptor.ReferencedDocument&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And your first post is looping through the table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 01:17:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11623993#M146618</guid>
      <dc:creator>A.Acheson</dc:creator>
      <dc:date>2022-12-16T01:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11626132#M146683</link>
      <description>&lt;P&gt;This is still not completely solved. I'm seeing some oddities in the pages, they are not updating correctly. I've attached some working docs. I'm hoping someone with more robust knowledge of Inventor and iLogic can help me figure this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One issue looks like the width and length parameters are not updating in the iLogic code when the model state changes, which is strange considering the image of the part changes to the new size. This can be demonstrated by running the generate rule, where it will iterate through the blanks but the message box will show the same size for every blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another oddity that mostly happens on the last sheet, but can happen on other sheets or not at all; the field text populated from iProperties does not update. C&lt;SPAN&gt;ustom or project properties doesn't appear to matter, I've dropped several UpdateWhenDone and DocumentUpdate commands, but they don't help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="inherit"&gt;A low priority oddity that has a work around, but is just irritating; I moved most of the IDW updates to the IPT, mostly due to the iLogic trigger on open didn't seam to be working well in the IDW. Using the code to find the sheet size of the IDW from the IPT results in numbers 10 times higher than similar code ran in the IDW. This can be demonstrated by running the check sheet size rule in each of the attached files. Maybe there is a reason for this, but I can't think what that reason might be. It's &lt;/FONT&gt;just&lt;FONT face="inherit"&gt;&amp;nbsp;inconsistent.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="inherit"&gt;Thanks for the help so far.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2022 00:06:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11626132#M146683</guid>
      <dc:creator>insomnix</dc:creator>
      <dc:date>2022-12-17T00:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update IDW with each model state and save as separate PDF</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11630789#M146787</link>
      <description>&lt;P&gt;Found a solution to one of my issues. I don't know why I cannot just pull the user parameters using the standard method, but using the below does provide the correct values as I cycle through the Model States.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Parameter.Param("length").Value
Parameter.Param("width").Value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 01:25:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/update-idw-with-each-model-state-and-save-as-separate-pdf/m-p/11630789#M146787</guid>
      <dc:creator>insomnix</dc:creator>
      <dc:date>2022-12-20T01:25:23Z</dc:date>
    </item>
  </channel>
</rss>

