iLogic Automate Component Pattern/Packaging Problem

iLogic Automate Component Pattern/Packaging Problem

nicholas_peckett
Participant Participant
692 Views
10 Replies
Message 1 of 11

iLogic Automate Component Pattern/Packaging Problem

nicholas_peckett
Participant
Participant

Hi,

 

I need some help using iLogic in Inventor.

 

I work for a company that PVD coats components for many customers. As part of my role, I am required to create circular and rectangular patterns of each customer component to see how many fit in a machine for loading calculations and costing.

 

For example, a machine has loading parameters of 170mm in diameter and 1300mm in height (essentially a cylinder).

It appears that my predecessors did this entirely manually by sketching a 170mm diameter circle, constraining that circle to a plane and feature of the component, and then patterning the component around the circle with a set spacing. Finally, they would create a rectangular pattern with spacing between circular pattern rows up to the maximum working height of the machine.

 

To me, this is a very slow and inefficient process, and I am trying to see if iLogic can help me speed this up.

I understand that there may be no way to avoid constraining the part to a sketch initially, but can anyone help me automate the rest of the process? If I can specify  minimum part spacings and overall pattern height, that would be perfect.

 

I have attached an image to help illustrate what I am trying to do.

Thank you.

0 Likes
Accepted solutions (1)
693 Views
10 Replies
Replies (10)
Message 2 of 11

C_Haines_ENG
Collaborator
Collaborator

This is entirely possible, what would be your ideal use-case scenario? Walk me through the process.

 

Do you want to just select a component and have it create an assembly and do the whole patterning?

0 Likes
Message 3 of 11

nicholas_peckett
Participant
Participant

Hi,

 

I would like to first constrain the part to a circular sketch and create a Z-axis in the centre of the sketch. That way I can best orientate a part for PVD coating depending on the important coating face.

 

For the rest of the process ideally if I could simply input the parameters like minimum spacing between parts (around and up)  and the maximum height limit of the machine.

 

I hope that makes sense.

 

Thank you.

0 Likes
Message 4 of 11

C_Haines_ENG
Collaborator
Collaborator

These are pretty basic iLogic rules, but they should get you started pretty well. Its two rules, one to create an assembly so that you can constrain the part. This could be automated as well but I don't know the kind of parts you are working with enough to do this.

Sub Main 'CREATES ASSEMBLY FILE, DRAWS CIRCLE, ADDS PART FILE

	Dim PartPath As String = "FILE PATH HERE"
	Dim AsmTemplate As String = "ASSEMBLY FILE TEMPLATE HERE"
	oCircleRad = InputBox("Enter Radius Of Circle (cm)", "", "10")

	Dim oAsm As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject, AsmTemplate, True)
	Dim oAsmDef As AssemblyComponentDefinition = oAsm.ComponentDefinition

	oAsmDef.WorkPlanes(2).Visible = True: oAsmDef.WorkAxes(2).Visible = True

	Dim oMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix

	Dim oPart As ComponentOccurrence = oAsmDef.Occurrences.Add(PartPath, oMatrix)
	oPart.Grounded = False

	Dim oSketch As Sketch = oAsmDef.Sketches.Add(oAsmDef.WorkPlanes(2), True)
	Dim oCenter As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
	Dim oCircle As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oCenter, oCircleRad)
	oSketch.GeometricConstraints.AddGround(oCircle.CenterSketchPoint)
	Dim oDim As DiameterDimConstraint = oSketch.DimensionConstraints.AddDiameter(oCircle, oCenter, False)

End Sub

The second rule seems to be more like what you were looking for. This will take the first part in the newly created assembly and pattern it.

Sub Main 'PATTERNS FIRST COMPONENT IN ASSEMBLY FILE, CREATES CIRCULAR PATTERN AND THEN RECTANGULAR PATTERN

	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oAsmDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
	Dim oPartCollect As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	
	Dim oQty As Integer = InputBox("Enter Circular Qty", "", "2")

	Dim oPart As ComponentOccurrence = oAsmDef.Occurrences(1)
	oPartCollect.Add(oPart)
	
	Dim oCirclePat As CircularOccurrencePattern = oAsmDef.OccurrencePatterns.AddCircularPattern(oPartCollect, oAsmDef.WorkAxes(2), True, 360 / oQty & " deg", oQty & " ul")
	
	oPartCollect.Clear
	oPartCollect.Add(oCirclePat)
	
	Dim oStack As Integer = InputBox("Enter Vertical Qty", "", "2")
	Dim oStackDist As Integer = InputBox("Enter Vertical Spacing", "", oPart.RangeBox.MaxPoint.Y - oPart.RangeBox.MinPoint.Y)
	
	Dim oVerticalPat As RectangularOccurrencePattern = oAsmDef.OccurrencePatterns.AddRectangularPattern(oPartCollect, oAsmDef.WorkAxes(2), True, oStackDist & " cm" _
	, oStack & " ul")

End Sub

Let me know how these work out for you.

0 Likes
Message 5 of 11

nicholas_peckett
Participant
Participant

Thanks for looking into this. The script is almost exactly what I need.

 

The only problem is the part does not circular pattern around a preset diameter. It seems to only pattern around or very close to itself. Also I cannot set a circular pattern spacing. I can on the rectangular pattern.

 

Image attached.

It is really close to what I need. 

 

Thank you! 

0 Likes
Message 6 of 11

C_Haines_ENG
Collaborator
Collaborator

So the "Object" its patterning around every time is the Y Axis. Are you using the first program as well? The first one creates the assembly and the circle for you to constrain to, that way the Y axis is always available. I can change this if being limited to the Y Axis is an issue. 

 

Secondly, the spacing on the circular pattern was frustrating for me too. The circular pattern in Assemblies acts very different to the circular pattern in part files. You can only say how many, and how many degrees are in between each item. With that in mind, what number do you want to enter to get the correct circular pattern? Right now its taking a quantity and spacing them evenly.

0 Likes
Message 7 of 11

nicholas_peckett
Participant
Participant

In truth the axis I pattern around can be variably, so an always constant Y axis wont work . For example, there are times when a customer will send a step file. The orientation on these step files are not consistent so I tend to create a new axis anyway. Also the parts need to be orientated in a way for optimal coating so this makes it more complicated...

 

Most of the time I do this entire process in a part file and not assembly but either way is fine.

 

Also, the first script generates an error message.

 

Error on line 7 in rule: Rule0, in document: PART NAME.ipt

The parameter is incorrect. (0x80070057 (E_INVALIDARG))

 

I think it best if I attached some screenshots of my workflow so you understand the process and can advise it what I am trying to partly automate is possible.

 

Thank you 

 

Workflow.png

 

 

0 Likes
Message 8 of 11

C_Haines_ENG
Collaborator
Collaborator

This isn't nessicarily a completed script, but I want to check that the workflow is more or less what you're looking for before I add anything more.

 

This code will ONLY work in part files. You must draw the circle yourself, and once that is done you can run the rule and click on the sketched circle. You don't have to create the work axis. It is grabbing the first solid body in the part so if there are multiple solids ill have to tweak the rule. If you like this rule enough than we should look into creating a template file with a user form for more rapid adjustments.

 

 

Sub Main

	'[ SETUP
	Dim oDoc As PartDocument = ThisDoc.Document
	Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

	Dim oCircle As SketchCircle = ThisApplication.CommandManager.Pick(kSketchCurveCircularFilter, "Select Sketched Circle")
	If oCircle Is Nothing Then Exit Sub

	'[ FIND AXIS FOR PATTERN
	Dim oAxis As WorkAxis
	For Each oAxis In oDef.WorkAxes

		If oAxis.Line.Direction.IsParallelTo(oCircle.Parent.PlanarEntity.Geometry.Normal) Then Exit For

	Next

	Dim PartHeight As Double = GetSize(oDef, oAxis)
	Logger.Info(PartHeight)

	Dim oSearch As ObjectsEnumerator = oDef.FindUsingPoint(oCircle.CenterSketchPoint.Geometry3d, {kWorkAxisFilter })

	'CREATE AXIS IF IT DOESNT EXIST
	If oSearch.Count = 0
		oAxis = oDef.WorkAxes.AddByLineAndPoint(oAxis, oCircle.CenterSketchPoint)
	Else
		oAxis = oSearch(1)
	End If
	']

	'[ CREATE PATTERNS
	Dim oParts As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	oParts.Add(oDef.SurfaceBodies(1))

	Dim oCircQty As Integer = InputBox("Enter Circular QTY", "", "2")

	Dim oCircDef As CircularPatternFeatureDefinition = oDef.Features.CircularPatternFeatures.CreateDefinition(oParts, oAxis, True, oCircQty, 0)
	Dim oCircPat As CircularPatternFeature = oDef.Features.CircularPatternFeatures.AddByDefinition(oCircDef)
	oCircPat.Parameters.Item(1).Value = 2 * Math.PI

	oDoc.Update

	Dim oMachHeight As Integer = InputBox("Enter Machine Height (mm)", "", "100")
	Dim oMaxRectQty As Integer = Floor(oMachHeight / PartHeight)
	Dim oRectQty As Integer = InputBox("Enter Rectanguar QTY" & vbLf & vbLf & "You can fit a maximum of " & oMaxRectQty, "", oMaxRectQty)

	Dim oRectDef As RectangularPatternFeatureDefinition = oDef.Features.RectangularPatternFeatures.CreateDefinition(oParts, oAxis, True, oRectQty, oMachHeight - PartHeight & " mm", kFitted)
	Dim oRectPat As RectangularPatternFeature = oDef.Features.RectangularPatternFeatures.AddByDefinition(oRectDef)

	oDoc.Update
	']

End Sub

Function GetSize(oDef As PartComponentDefinition, oAxis As WorkAxis)

	Dim MaxPoint As Point = oDef.SurfaceBodies(1).RangeBox.MaxPoint
	Dim MinPoint As Point = oDef.SurfaceBodies(1).RangeBox.MinPoint

	Logger.Info(Left(oAxis.Name, 1))

	Select Case Left(oAxis.Name, 1)
		Case "X" : Return (MaxPoint.X - MinPoint.X) * 10
		Case "Y" : Return (MaxPoint.Y - MinPoint.Y) * 10
		Case "Z" : Return (MaxPoint.Z - MinPoint.Z) * 10
	End Select

End Function

 

 

 

0 Likes
Message 9 of 11

nicholas_peckett
Participant
Participant

Many thanks for this.

 

This version is near perfect and will be very helpful. I tested  with many parts and they all worked flawless.

 

The only error  encountered is when working with customer provided step files. It seems like the issue might be related to the plane of the selected circle not being parallel to any of the existing work axes plane and so is correctly identified and handled. 

 

If this could be fixed that would be perfect.

0 Likes
Message 10 of 11

C_Haines_ENG
Collaborator
Collaborator

When posting code, make sure to attach it using the "Insert/Edit code sample" formatting tool. Make it MUCH easier to read.

 

C_Haines_ENG_0-1736436110920.png

 

As for the "Axis" fix, Ill have to look into Oriented Box Objects as the only reason I'm able to determine the "Maximum Qty" on the rectangular pattern is because the the part is oriented on a origin axis. 

 

0 Likes
Message 11 of 11

nicholas_peckett
Participant
Participant
Accepted solution
Sub Main()

    ' SETUP
    Dim oDoc As PartDocument = ThisDoc.Document
    Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

    ' 1. Select Sketched Circle
    Dim oCircle As SketchCircle = ThisApplication.CommandManager.Pick(kSketchCurveCircularFilter, "Select Sketched Circle")
    If oCircle Is Nothing Then Exit Sub

    ' 2. Find or Create Axis
    Dim oAxis As WorkAxis
    For Each oAxis In oDef.WorkAxes
        If oAxis.Line.Direction.IsParallelTo(oCircle.Parent.PlanarEntity.Geometry.Normal) Then Exit For
    Next

    ' Find or Create Axis
    Dim oSearch As ObjectsEnumerator = oDef.FindUsingPoint(oCircle.CenterSketchPoint.Geometry3d, {kWorkAxisFilter})
    If oSearch.Count = 0 Then
        oAxis = oDef.WorkAxes.AddByLineAndPoint(oAxis, oCircle.CenterSketchPoint)
    Else
        oAxis = oSearch(1)
    End If

    ' 3. Ask for circle pattern quantity
    Dim oCircQty As Integer = InputBox("Enter Circular QTY", "", "2")
    If oCircQty <= 0 Then Exit Sub ' Ensure valid input

    ' 4. Ask for part height
    Dim PartHeight As Double = InputBox("Enter Part Height (mm)", "", "10")
    If PartHeight <= 0 Then Exit Sub ' Ensure valid input

    ' 5. Input Machine Height limit
    Dim oMachHeight As Integer = InputBox("Enter Machine Height (mm)", "", "100")
    If oMachHeight <= 0 Then Exit Sub ' Ensure valid input

    ' 6. Ask for minimum gap between rectangular patterns
    Dim oGap As Double = InputBox("Enter Desired Gap Between Patterns (mm)", "", "10")
    If oGap < 0 Then Exit Sub ' Ensure valid input

    ' 7. Calculate Maximum Rectangular Quantity
    Dim oMaxRectQty As Integer = Floor((oMachHeight + oGap) / (PartHeight + oGap))
    MsgBox("Maximum Rectangular QTY considering the machine height and gap: " & oMaxRectQty)

    ' 8. Input Pattern Quantities
    Dim oRectQty As Integer = InputBox("Enter Rectangular QTY" & vbLf & vbLf & "You can fit a maximum of " & oMaxRectQty, "", oMaxRectQty)
    If oRectQty <= 0 Or oRectQty > oMaxRectQty Then Exit Sub ' Ensure valid input

    ' 9. Create Patterns
    Dim oParts As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
    oParts.Add(oDef.SurfaceBodies(1))

    ' Circular Pattern
    Dim oCircDef As CircularPatternFeatureDefinition = oDef.Features.CircularPatternFeatures.CreateDefinition(oParts, oAxis, True, oCircQty, 0)
    Dim oCircPat As CircularPatternFeature = oDef.Features.CircularPatternFeatures.AddByDefinition(oCircDef)
    oCircPat.Parameters.Item(1).Value = 2 * Math.PI

    oDoc.Update

    ' Rectangular Pattern
    Dim oRectDef As RectangularPatternFeatureDefinition = oDef.Features.RectangularPatternFeatures.CreateDefinition(oParts, oAxis, True, oRectQty, (PartHeight + oGap) & " mm", kfitted)
    Dim oRectPat As RectangularPatternFeature = oDef.Features.RectangularPatternFeatures.AddByDefinition(oRectDef)

    oDoc.Update

End Sub

Function GetSize(oDef As PartComponentDefinition, oAxis As WorkAxis) As Double
    Dim MaxPoint As Point = oDef.SurfaceBodies(1).RangeBox.MaxPoint
    Dim MinPoint As Point = oDef.SurfaceBodies(1).RangeBox.MinPoint

    Select Case Left(oAxis.Name, 1)
        Case "X" : Return (MaxPoint.X - MinPoint.X) * 10
        Case "Y" : Return (MaxPoint.Y - MinPoint.Y) * 10
        Case "Z" : Return (MaxPoint.Z - MinPoint.Z) * 10
    End Select

    Return 0
End Function
0 Likes