Message 1 of 2
Export model state in assy to step
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
I have this code that exports all parts in de assy and sub assy's.
Now i went over to Inventor 2022 and use Model States.
I found a bit of code to use Model States.
But i don't have the knowledge to fit that bit of code in to the main code to make it work.
My main code that exports all the parts into a certain folder:
'define the active document as an assembly file Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = ThisDoc.FileName(False) 'without extension If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If 'get user input RUsure = MessageBox.Show ( _ "This will create a STEP file for all components.") '& vbLf & " " _ '& vbLf & "Are you sure you want to create STEP Drawings for all of the assembly components?" _ '& vbLf & "This could take a while.", "iLogic - Batch Output STEPs ",MessageBoxButtons.YesNo) If RUsure = vbNo Then Return Else End If '- - - - - - - - - - - - -STEP setup - - - - - - - - - - - - oPath = "Z:\Uni_Link\Import\Stepfiles" 'get STEP target folder path oFolder = oPath & "\" & iProperties.Value("Project","Project") & "-" & iProperties.Value("Summary","Category") & " STEP Files" 'oFolder = oPath & "\" & oAsmName & " STEP Files" 'Check for the step folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If '- - - - - - - - - - - - -Assembly - - - - - - - - - - - - ThisDoc.Document.SaveAs(oFolder & "\" & oAsmName &(".stp") , True) '- - - - - - - - - - - - -Components - - - - - - - - - - - - 'look at the files referenced by the assembly Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document 'work the referenced models For Each oRefDoc In oRefDocs Dim oCurFile As Document oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True) oCurFileName = oCurFile.FullFileName 'defines backslash As the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(oCurFileName, "\", -1) 'get the file name with the file extension Name = Right(oCurFileName, Len(oCurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) Try oCurFile.SaveAs(oFolder & "\" & ShortName & (".stp") , True) Catch MessageBox.Show("Error processing " & oCurFileName, "ilogic") End Try oCurFile.Close Next '- - - - - - - - - - - - - MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic") 'open the folder where the new files are saved Shell("explorer.exe " & oFolder,vbNormalFocus)
This is the bit of code for Model States that is called CNC i think:
Public Function GetModelStateDocument(doc As PartDocument) Dim def As PartComponentDefinition = doc.ComponentDefinition If (def.IsModelStateMember Or def.IsModelStateFactory) Then doc = def.FactoryDocument def = doc.ComponentDefinition Else Return doc End If Dim masterDoc As Document = Nothing Dim PreProductionDoc As Document = Nothing For Each modelState As ModelState In def.ModelStates If (ModelState.Name = "Master") Then If (PreProductionDoc Is Nothing) Then ModelState.Activate() End If masterDoc = ModelState.FactoryDocument End If If (ModelState.Name = "CNC") Then ModelState.Activate() PreProductionDoc = ModelState.FactoryDocument End If Next If (PreProductionDoc Is Nothing) Then Return masterDoc Else Return PreProductionDoc End If
I hope someone can help me.