Derive Part from Multi Solid Body

Derive Part from Multi Solid Body

evan.wondra
Enthusiast Enthusiast
1,309 Views
7 Replies
Message 1 of 8

Derive Part from Multi Solid Body

evan.wondra
Enthusiast
Enthusiast

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
0 Likes
Accepted solutions (1)
1,310 Views
7 Replies
Replies (7)
Message 2 of 8

Lupe_Stewart
Advocate
Advocate

i tried all that and it didnt work for me..... the concept that i have is different but it works with what its used for 

Lupe_Stewart_0-1660053305408.png

this is my example.

the ilogic has several true false statements, it has several embedded excel sheets for flange dimensions

there is are several seperate rules for all the verbage of the 4 major parts of the assembly.

the buttons with the check marks  that you see are the true false statements.  each one goes the derive part.... i have linked all the parameters that is associated with that part to the derive part..... its more work to do... but this was my solution

0 Likes
Message 3 of 8

evan.wondra
Enthusiast
Enthusiast

It sounds like this is just pushing parameters to a derived part. I am looking to extract solid bodies and put them into their own IPT file.

0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor
Accepted solution

1. If you want to select the body before you run the rule use Select set to create a collection of selections.

 
    ' Set a reference to the select set.
    Dim oSelectSet As SelectSet = ThisApplication.ActiveDocument.SelectSet
   

 If you want to select the body after starting the rule then  use the pick function in a loop shown in this post

 

The surface bodies collection "prt.ComponentDefinition.SurfaceBodies"

will be replaced by oSelectSet

2.Replace the file path with a string variable and use an List of string and arraylist box shown here  to display the file paths to the user.

Dim PartTempList as New List (Of String)
PartTempList.add("filepath......ipt")
Dim PartTemp as String = InputListBox("Prompt",PartTempList, defaultEntry, Title := "Dialog Title", ListPrompt := "List Prompt")

newPart
= ThisApplication.Documents.Add(kPartDocumentObject,PartTemp , True)

 3. Replace the formulated name in the save as line

Left(NewName,b-c) & a

With 

sb.Name

4. Change the file path of the assembly 

asm = ThisApplication.Documents.Open(folder & Left(NewName, 14) & ".iam")

Or create a new one, supply a path of your assembly template is different ref part template above for method. 

 

Asm = ThisApplication.Documents.Add(kAssemblyDocumentObject, True)
    

If you get into trouble post the error message including more info and the code your working with.  

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 8

J-Camper
Advisor
Advisor

@evan.wondra,

 

It sounds like you are trying to recreate the native Make Components command.  Have you tried that for your workflow?

0 Likes
Message 6 of 8

evan.wondra
Enthusiast
Enthusiast

Thank you, I will test this out.

0 Likes
Message 7 of 8

evan.wondra
Enthusiast
Enthusiast

I am basically trying to remake the Make Components command, but I am wanting to run some other iLogic that I have at specific parts of the process. 

0 Likes
Message 8 of 8

evan.wondra
Enthusiast
Enthusiast

These all worked for me. Thank you for your help!

0 Likes