Message 1 of 7
Create Assembly/Sub Assembly structure using iLogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If, for instance I know ahead of time what the rough structure of my assembly is going to be (based on a file structure from a CD I was given) how easy is it to recreate this structure using iLogic?
My file structure looks a little like this:
<dir name="e:\"> <file parentassembly="THE-TOP-LEVEL-ASSEMBLY" friendlyname="TOP-LEVEL-ASSEMBLY" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="PART-NAME" /> <dir name="1ST-LEVEL-SUB-ASSEMBLY"> <file parentassembly="TOP-LEVEL-ASSEMBLY" friendlyname="1ST-LEVEL-SUB-ASSEMBLY" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="2ND-LEVEL-SUB-ASSEMBLY-003" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="2ND-LEVEL-SUB-ASSEMBLY-004" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="PART-NAME" /> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="PART-NAME" /> <dir name="2ND-LEVEL-SUB-ASSEMBLY-000"> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="2ND-LEVEL-SUB-ASSEMBLY-000" /> </dir> <dir name="2ND-LEVEL-SUB-ASSEMBLY-001"> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="2ND-LEVEL-SUB-ASSEMBLY-001" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-001" friendlyname="PART-NAME" /> </dir> <dir name="2ND-LEVEL-SUB-ASSEMBLY-002"> <file parentassembly="1ST-LEVEL-SUB-ASSEMBLY" friendlyname="2ND-LEVEL-SUB-ASSEMBLY-002" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> <file parentassembly="2ND-LEVEL-SUB-ASSEMBLY-002" friendlyname="PART-NAME" /> </dir>
Incidentally, the above code was created from a small console app I wrote:
Imports System.Collections.Generic Imports System.IO Imports System.Linq Imports System.Text Imports System.Text.RegularExpressions Imports System.Xml.Linq Module Module1 Public Sub Main() Console.WriteLine("Enter Path to Parse...") Dim rootPath As String = Console.ReadLine() Dim dir = New DirectoryInfo(rootPath) Dim doc = New XDocument(GetDirectoryXml(dir)) doc.Save("C:\temp\VBtest.xml") Console.WriteLine(doc.ToString()) Console.Read() End Sub Public Function GetDirectoryXml(ByVal dir As DirectoryInfo) As Object Dim info = New XElement("dir", New XAttribute("name", dir.Name)) If Not dir.Name.Contains("Superseded") Then For Each file As FileInfo In dir.GetFiles() 'info.Add(New XElement("file", New XAttribute("name", file.Name), New XAttribute("friendlyname", GetFriendlyName(file.Name)))) If Not file.Name.Contains("IL") And Not file.Name.Contains("DL") And Not file.Name.Contains("SP") Then 'if the directory name is the same as the assembly name then the parentassembly is the folder above! If GetFriendlyDirName(dir.Name) = GetFriendlyName(file.Name) Then If getsheetnum(file.Name) <= 1 Then info.Add(New XElement("file", New XAttribute("parentassembly", GetFriendlyDirName(dir.Parent.Name)), New XAttribute("friendlyname", GetFriendlyName(file.Name)))) End If Else If getsheetnum(file.Name) <= 1 Then info.Add(New XElement("file", New XAttribute("parentassembly", GetFriendlyDirName(dir.Name)), New XAttribute("friendlyname", GetFriendlyName(file.Name)))) End If End If End If Next For Each subDir As DirectoryInfo In dir.GetDirectories() If Not subDir.Name.Contains("Superseded") Then info.Add(GetDirectoryXml(subDir)) End If Next End If Return info End Function Public Function GetFriendlyName(p As String) As Object Dim f As String = String.Empty Dim r As New Regex("\w{2}-\d{5,}|\w{2}-\w\d{5,}") f = r.Match(p).Captures(0).ToString() + "-000" Console.WriteLine(f) Return f End Function Public Function GetFriendlyDirName(p1 As String) As Object If Not p1.Contains(":") Then Dim f As String = String.Empty Dim r As New Regex("\d{3,}|\w\d{3,}") f = "AS-" + r.Match(p1).Captures(0).ToString() + "-000" Return f Else Return p1 End If End Function Private Function getsheetnum(p1 As String) As Integer Dim f As String = String.Empty Dim pattern As String = "(.*)(sht-)(\d{3})(.*)" Dim matches As MatchCollection = Regex.Matches(p1, pattern) For Each m As Match In matches Dim g As Group = m.Groups(3) f = CInt(g.Value) Next Return CInt(f) End Function End Module
I was thinking that since the above works for folders/subfolders (because of the recursive nature) that it should work in Inventor iLogic (with some tweaks) for creating the sub-assemblies/parts etc.
Can anyone offer any pointers?
Thanks,
Alex.
----------------------------------------------------------------
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example