Dxf generator for all open assemblies.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I have an external rule exporting flat patterns from assemblies (similar can be found on this forum, mine's a bit modified) and I would like to run it for all open assemblies in inventor (2018, professional). Basicly i want to put this dxf generator in some kind of loop, open all *.iams I need to and run it. I tried with some counters active docs, with "for each" loops, "do while" loops. the best results i get from simple for each loop. it ran generator for every open iam (generator has prompting windows and all behave well, they are prompting), which is cool, BUT generates dxfs only for first, active iam, from which I started. Is it possible to put this generator in loop for all open iams? Can someone smarter help me?
Thank You in advance, and sorry for lousy english. also some parts of code are in polish. Also for working generator You have to have a folder named #DXF in folder where main iam is.
Mateusz.
for each:
Dim aDoc As AssemblyDocument aDoc = ThisApplication.ActiveDocument Dim iDoc As Document For Each iDoc In aDoc.AllReferencedDocuments iLogicVb.RunExternalRule("generator dxfow.txt") ThisDoc.Document.Close(True) Next
dxf generator:
Class ThisRule Dim partDox As Document Sub Main() Dxf() Zamk() End Sub Sub Dxf() If MsgBox("Ta regula wygeneruje pliki dxf dla wszystkich plikow. Czy chcesz kontynuowac?", vbOKCancel + vbExclamation, "Batch Write Flat Pattern") = vbCancel Then Exit Sub partDox = ThisDoc.Document ' Sets up the variable "MyFile" to be each file in the directory ' This example looks for all the files that have an .ipt extension. ' This can be changed to whatever extension is needed. Also, this ' macro searches the current directory. This can be changed to any ' directory. Dim Directory As String Directory = ThisDoc.Path 'search for files. Dim docFile As Document ' Starts the Loop, which will Continue Until there are no more files ' found. For Each docFile In partDox.AllReferencedDocuments ' Displays a message box with the name of the file. This can be ' changed to any procedure that would be needed to run on every ' file in the directory such as opening each file. 'opens file: partDox = ThisApplication.Documents.Open(docFile.FullFileName, False) ThisApplication.SilentOperation = True 'Test to make sure we opened a sheet metal part If(docFile.DocumentSubType.DocumentSubTypeID.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")) Then DefaultChoice = True 'MsgBox(MyFile) '---------------------------------------------------------------------------------- '---------------------------------------------------------------------------------- Dim oPropSet As PropertySet Dim oProp As Inventor.Property Dim invPartNoProperty As Inventor.Property = partDox. _ PropertySets.Item("Design Tracking Properties").Item("Part Number") PartNumber = invPartNoProperty.Value Dim invDescriptionProperty As Inventor.Property = partDox. _ PropertySets.Item("Design Tracking Properties").Item("Description") Description = invDescriptionProperty.Value Dim invMaterialProperty As Inventor.Property = partDox. _ PropertySets.Item("Design Tracking Properties").Item("Material") Mat = invMaterialProperty.Value ' Dim invGrubProperty As Inventor.Property = partDox. _ ' PropertySets.Item("Design Tracking Properties").Item("Thickness") namex = docFile.FullFileName name = IO.Path.GetFileName(namex) Grub = Parameter(name, "Grubość") 'MsgBox(Grub) '----------------------------------------- '---------------------------------------------------------------------------------- Dim FilePATH As String = "FilePATH" customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties") Try prop= customPropertySet.Item(FilePATH) Catch customPropertySet.Add("", FilePATH) End Try If iProperties.Value("Custom", "FilePATH") = "" Then iProperties.Value("Custom", "FilePATH") = "C:\" Else End If 'Dim partDoc As PartDocument ' If partDox.Document.DocumentType <> kPartDocumentObject Then ' ' MessageBox.Show ("Please open a part document", "iLogic") ' ' End If FilePATH = ThisDoc.Path & "\#DXF" 'InputBox("Enter a FilePATH for part file", "iLogic", iProperties.Value("Custom", "FilePATH")) iProperties.Value("Custom", "FilePATH") = FilePATH '---------------------------------------------------------------------------------- 'Dim oDoc As PartDocument 'oDoc = partDox Dim oCompDef As SheetMetalComponentDefinition oCompDef = partDox.ComponentDefinition ' If oCompDef.HasFlatPattern = False Then ' ' oCompDef.Unfold ' ' Else ' ' oCompDef.FlatPattern.Edit ' End If Dim sOut As String Dim sPATH As String sPATH = iProperties.Value("Custom", "FilePATH") sOut = "FLAT PATTERN DWG?AcadVersion=2004&OuterProfileLayer=Burn&InteriorProfilesLayer=Burn&InvisibleLayers=IV_UNCONSUMEND_SKETCHES;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_ARC_CENTERS;IV_TOOL_CENTER_DOWN;IV_TOOL_CENTER;IV_ARC_CENTERS;IV_TANGENT;IV_BEND;IV_BEND_DOWN&SplineTolerance Double 0.01"'"FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_INTERIOR_PROFILES" Dim sFname As String 'Name = InputBox("Please enter your file name", "Save As", "") sFname = sPATH & "\" & PartNumber & " " &" - " & Mat & " " & Grub & " mm - szt " & ".dxf" 'MessageBox.Show("DXF SAVED TO: " & sFname ,"DXF Saved", MessageBoxButtons.OK) oCompDef.DataIO.WriteDataToFile( sOut, sFname) oDoc = ThisApplication.ActiveDocument 'Dim oSMDef As SheetMetalComponentDefinition ' 'oSMDef = oDoc.ComponentDefinition ' 'oSMDef.FlatPattern.ExitEdit 'This code has been adapted from http://www.cadlinecommunity.co.uk/Blogs/Blog.aspx?ScoId= '4733ef2d-cd48-4bd9-a280-1d88dbbf3556&returnTo=%2fBlogs%2fclintonbrown%2fDefault.aspx '&returnTitle=Clinton+Brown%20Blog '---------------------------------------------------------------------------------- End If partDox.Close(False) partDox = Nothing ThisApplication.SilentOperation = False Next 'MsgBox("Grubosc: " & Grub, vbOKOnly) MsgBox("Wszystkie pliki zostały poprawnie zapisane do folderu #DXF.", vbOKOnly, "Batch Write Flat Pattern") End Sub Sub Zamk() ThisDoc.Document.Close(True) End Sub End Class