Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am trying to write an iLogic rule that allows me to derive solid bodies from a multi solid body IPT file. There are a few things I am wanting it to do.
1. This first one is preferred but not required. Only derive solid bodies that I have selected.
2. Lets user select which template file to use for all the derived parts.
3. Name the new IPT files with the name that the solid body was called.
4. Put the new IPT files into an assembly file.
I found the below code and have been able to edit it a little bit but I'm fairly new to iLogic so I still don't know all the ins and outs.
Sub Main() Dim NewName As String NewName = InputBox("New Name (EX:P12344567-123-Series)","Provide name") ' set a reference to the active partdocument Dim prt As PartDocument prt = ThisApplication.ActiveDocument Dim template As String Dim folder As String template = "" folder = PathName(prt.FullFileName) ' create an object collection to store the parts to put in assembly Dim prtCol As ObjectCollection prtCol = ThisApplication.TransientObjects.CreateObjectCollection Dim a As Integer: a = 0 Dim b As Integer: b = 18 Dim c As Integer: c = 1 ' loop through the filtered selection Dim sb As SurfaceBody For Each sb In prt.ComponentDefinition.SurfaceBodies ' create a new part to derive the solid body in Dim newPart As PartDocument newPart = ThisApplication.Documents.Add(kPartDocumentObject,"C:\Templates\SHEET METAL.ipt", True) ' set a reference to the derivedpartcomponents Dim dpcs As DerivedPartComponents dpcs = newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents ' create the scale definition Dim dpd As DerivedPartUniformScaleDef dpd = dpcs.CreateUniformScaleDef(prt.FullFileName) ' set the settings in another sub Call settingsDerivedPart(dpd, sb) Call dpcs.Add(dpd) Call prtCol.Add(newPart) ' set the part title to the solidbodies name newPart.PropertySets.Item("Inventor Summary Information").Item("Title").Value = sb.Name a = a + 1 If a>9 Then c = 2 End If ' Save the part ThisApplication.SilentOperation = True Call newPart.SaveAs(folder & Left(NewName,b-c) & a & ".ipt", False) ThisApplication.SilentOperation = False Next sb ' find opened assembly in which the sketch part is Dim asm As AssemblyDocument asm = ThisApplication.Documents.Open(folder & Left(NewName, 14) & ".iam") ' place in assembly? prt = Nothing For Each prt In prtCol ' create an empty matrix Dim mx As Matrix mx = ThisApplication.TransientGeometry.CreateMatrix() Dim occ As ComponentOccurrence occ = asm.ComponentDefinition.Occurrences.AddByComponentDefinition(prt.ComponentDefinition, mx) Call prt.Close(True) Next End Sub Function PathName(FullPath As String) As String ' return all left of last \ PathName = Left(FullPath, InStrRev(FullPath, "\")) End Function Sub settingsDerivedPart(ByRef dpd As DerivedPartUniformScaleDef, sb As SurfaceBody) ' set the derive style Call dpd.ExcludeAll ' include solid, exclude the others Dim dpe As DerivedPartEntity For Each dpe In dpd.Solids If dpe.ReferencedEntity.Name = sb.Name Then dpe.IncludeEntity = True End If Next End Sub
Solved! Go to Solution.