Update IDW with each model state and save as separate PDF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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.
So, how do I change the model state on the IDW based on the active model state in the assembly/parts file through iLogic?
Assembly code:
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 & "\" & dwg_template & ".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 & "\PDF"
pdfFile = oFolder & "\rsi" & dwg_number & ".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
IDW code:
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 & "\" & "R39225-MD5-FIN" & ".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
*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.