Look for equal values in list

Look for equal values in list

Anonymous
Not applicable
362 Views
2 Replies
Message 1 of 3

Look for equal values in list

Anonymous
Not applicable

Hello,

 

I'm currently working on a rule that counts the number of bends in an inventor part. When a bend line is divided by a cut, the rule counts the bend twice. In the picture below, the upper bend will be count twice by the rule, but in production will be set in one go. To filter this error out, I made a second rule that looks for the start and endpoint coordinates of every bend line (rule below). When the coordinates are known, I let the rule calculate the formula of each bend line. The formulas are momentarily exported to Excel because I couldn't get an arraylist to work in the loop. I want to know if it is possible to place the formulas in an array or multivaluelist. The formulas can be numbers only but also a combination of characters and numbers, for example X365.

 

Now the big problem. To see if two or more bends are on the same line, I have to compare all the formulas with each other. When two or more formulas are equal, they are on the same line. Is it possible to compare multiple values in Ilogic?

 

Regards,

 

Eric

 

'[ edit these variables as needed
sSketchName = "Flat Pattern Sketch"
sHoleName = "Locator Holes"
oOffset = 0.100 in'defines offset from edge of flat pattern
oDiameter = 0.125 in 'defines hole diameter
']	

'  a reference to the active document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

'verify document type is sheet metal
If oPartDoc.ComponentDefinition.Type <> 150995200 Then
	MessageBox.Show("File is not a sheet metal part.", "iLogic")
	Exit Sub
End If

Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

' Check to make sure a flat pattern is open.
If Not TypeOf ThisApplication.ActiveEditObject Is FlatPattern Then
	Try
		If oCompDef.HasFlatPattern = False Then
			oCompDef.Unfold
		Else
			oCompDef.FlatPattern.Edit
		End If
	Catch
		MessageBox.Show("Error editting the flat pattern.", "iLogic")

	End Try
End If

'  a reference to the active flat pattern.
Dim oFlatPattern As FlatPattern
oFlatPattern = ThisApplication.ActiveEditObject

'clean up existing holes
Dim oHole As HoleFeature
For Each oHole In oFlatPattern.Features.HoleFeatures
	oHole.Delete
Next
 
Dim oFace As Face
'oFace = oFlatPattern.BottomFace
oFace = oFlatPattern.TopFace

Dim oSketch As PlanarSketch

'clean up existing sketch
For Each oSketch In oFlatPattern.Sketches
	If oSketch.Name = sSketchName Then
		oSketch.Delete
	End If
Next

' Create a new sketch.  The second argument specifies to include/not include
' the edges of the face in the sketch.
oSketch = oFlatPattern.Sketches.Add(oFace, False)

' Change the name.
oSketch.Name = sSketchName

' Create a new object collection for the hole center points.
oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry	
	
Dim oPoint As Point2d
Dim oEdge As Edge


Dim oEdges As Edges

' Get all Bend UP edges
'where true = top face
oEdges = _
oFlatPattern.GetEdgesOfType( _
FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True) 'true = top face

'GoExcel.Open("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1")
'
''Define Range
'oRowStart = 1
'oRowEnd = 1000
'Dim count As Double
'For count = oRowStart To oRowEnd
'' If it's blank count it
'If String.IsNullOrEmpty(GoExcel.CellValue("A" & count)) Then
'i = i + 1
'End If
'Next
'' Next empty row is max rows minus blank rows plus one
'oEmptyRow = oRowEnd - i + 1

For Each oEdge In oEdges
    Dim line As SketchLine = oSketch.AddByProjectingEntity(oEdge)
    oHoleCenters.Add(oSketch.SketchPoints.Add(line.StartSketchPoint.Geometry, True))

	MessageBox.Show(line.StartSketchPoint.Geometry.X  &", "&  line.StartSketchPoint.Geometry.Y , "Coordinaten startpoint")

    oHoleCenters.Add(oSketch.SketchPoints.Add(line.EndSketchPoint.Geometry, True))

	MessageBox.Show(line.EndSketchPoint.Geometry.X  &", "&  line.EndSketchPoint.Geometry.Y , "Coordinaten endpoint")
	
		GoExcel.Open("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1")
		
		'index row 1 through 10000
		For rowPN = 1 To 10000
			'find first empty cell in column A
			If (GoExcel.CellValue("A" & rowPN) = IsNullOrEmpty) Then
			'If (GoExcel.CellValue("A" & rowPN) = IsNotNumeric  AndAlso IsNotZero) Then
			Laatste = rowPN
			Exit For
			End If
		Next
	
	'Tel 0.001 op bij de daadwerkelijke waarde van om deze te kunnen exporteren naar Excel. Wanneer a 0 is, 
	'ziet Excel dit als een lege cel en dus wordt deze overschreven wanneer een nieuwe a naar Excel wordt geexproteerd	
	Dim a = (line.EndSketchPoint.Geometry.Y-line.StartSketchPoint.Geometry.Y)/(line.EndSketchPoint.Geometry.X-line.StartSketchPoint.Geometry.X)
	
	MessageBox.Show(a, "Waarde a")
	
		If a > Infinity Or a < -Infinity Then
		
		GoExcel.CellValue("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1", "A" & Laatste) = "X"
		GoExcel.CellValue("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1", "B" & Laatste) = line.StartSketchPoint.Geometry.X
		
		MessageBox.Show(Laatste, "Cellvalue a=Infinity")
		
		ElseIf a = 0 Then
		
		GoExcel.CellValue("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1", "A" & Laatste) = "Y"
		GoExcel.CellValue("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1", "B" & Laatste) = line.StartSketchPoint.Geometry.Y
		
		MessageBox.Show(Laatste, "Cellvalue a=0")
		
		Else
		
		GoExcel.CellValue("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1", "A" & Laatste) = a
		
		MessageBox.Show(Laatste, "Cellvalue a=else")
	
		
		Dim b = (line.StartSketchPoint.Geometry.Y-(a*line.StartSketchPoint.Geometry.X))
		
		MessageBox.Show(b, "Waarde b")
		
		GoExcel.CellValue("N:\Drawings\Engineering Productie Tooling\Algemeen\Excel sheets uit Inventor\Test aantal buigingen.xlsx", "Sheet1", "B" & Laatste) = b
	
	End If
	
	GoExcel.Save
	GoExcel.Close

	
'	LineEquation = a*line.StartSketchPoint.Geometry.X+b
'	
'	MessageBox.Show(LineEquation, "Vergelijking lijn")	

    line.Delete()
	

	
Next	
' Get all Bend Down edges
'where true = top face
oEdges = _
oFlatPattern.GetEdgesOfType( _
FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True) 

For Each oEdge In oEdges
    Dim line As SketchLine = oSketch.AddByProjectingEntity(oEdge)
    oHoleCenters.Add(oSketch.SketchPoints.Add(line.StartSketchPoint.Geometry, True))

	MessageBox.Show(line.StartSketchPoint.Geometry.X  &", "&  line.StartSketchPoint.Geometry.Y , "iLogic3")

    oHoleCenters.Add(oSketch.SketchPoints.Add(line.EndSketchPoint.Geometry, True))

	MessageBox.Show(line.EndSketchPoint.Geometry.X  &", "&  line.EndSketchPoint.Geometry.Y , "iLogic3")

    line.Delete()
Next

Voorbeeld bends.PNG

0 Likes
363 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Could you use a collection to keep track of your formulas?

 

Dim MyCollection As ObjectCollection
MyCollection = ThisApplication.TransientObjects.CreateObjectCollection

 

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hello yosso22,

 

When I put all the information in a collection, how can I access this collection and how can I compare the formulas that are in it with each other?

 

Regards,

 

Eric

0 Likes