- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone, I have been working on a project for a couple weeks to create a product configurator that will assemble rows of partially constrained flexible components to din rails. So far, I have been able to accurately determine each occurrences' "Center Point" coordinates through the usage of geometry proxies, and these points are then determined to be between pairs of work planes to delimit the rows. I first considered to determine if the parts are in a row based on if they have a pre-existing constraint to the din rail, but if I remember correctly, I had trouble obtaining the list of occurrences from a constraint or something, but that is beside the point. It works well for the most part, but there is one occurrence I have found so far which returns an inaccurate position (2165062:3). What is confusing about it is that it is within a subassembly with another instance of the same part, which DOES return the correct position. They are both partially constrained to the din rail so they are physically located with the same Y position (manually measuring confirms this). The assembly structure is like this:
WhopJr.iam
+x2:2
-+2165062:3 <---this one is measured inaccurately
-+2165062:4
-+2135099-X2:1
2135099-X2:1 is a label that is just mated to 2165062:3 so it stays attached to it with no other constraints. Its presence doesn't seem to affect anything, as 2165062:3 is read inaccurately whether it is there or not. In other words, the two parts are the same but 2165062:4 doesn't have the label. 2165062:3 is the only one so far I have seen that measures incorrectly, all the other parts shown in the image work fine, so I want to know what is wrong with this specific instance.
Here is the function that finds and returns position. compDef is top level.
Dim recursDepth As Integer = 0
Function TraverseAssembly(compDef As AssemblyComponentDefinition, oOccs As ComponentOccurrences, ByRef componentsBetweenWorkplanes As List(Of Tuple(Of ComponentOccurrence, Double, ComponentOccurrence)), occName As String) As Tuple(Of Double, Double)
Dim oWPProxy As WorkPointProxy
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
If oOcc.Name = occName Then
Dim oWP As WorkPoint
For Each oWP In oOcc.Definition.WorkPoints
If Not UCase(oWP.Name).Contains("CENTER POINT") Then Continue For
Call oOcc.CreateGeometryProxy(oWP, oWPProxy)
Dim yCoord As Double = Round(oWPProxy.Point.Y, 3)
Dim xCoord As Double = Round(oWPProxy.Point.X, 3)
Dim sameParentExists As Boolean = componentsBetweenWorkplanes.Any(Function(t) t.Item1.Name = oOcc.Name AndAlso t.Item2 = Round(xCoord, 3))
If sameParentExists Then
Logger.Debug("Skipping occurrence: " & oOcc.Name & " as it already exists in componentsBetweenWorkplanes")
Continue For
End If
Logger.Debug("Name =: " & oOcc.Name & " | YPos = " & Round(yCoord, 3) & " | XPos = " & Round(xCoord, 3))
recursDepth = 0
Return Tuple.Create(yCoord, xCoord)
Next
ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
' Step into subassembly and return the result if valid
recursDepth += 1
Logger.Debug("TraverseAssembly Recursion depth = " & recursDepth)
Dim subOccPos As Tuple(Of Double, Double) = TraverseAssembly(compDef, oOcc.SubOccurrences, componentsBetweenWorkplanes, occName)
If Not Double.IsNaN(subOccPos.Item1) AndAlso Not Double.IsNaN(subOccPos.Item2) Then
recursDepth = 0
Return subOccPos
End If
End If
Next
' Return NaN if nothing was found
Return Tuple.Create(Double.NaN, Double.NaN)
End Function
The recursDepth logging was used to determine how many recursive calls to TraverseAssembly there was per occurrence. 2165062:4 has 7 recursive calls for some reason and 2165062:3 only has 1. Given that they are both copies of the same part, within the same subassembly, I think this is weird. Previously I also explored that perhaps the Transformation matrices of the occurrences where varied slightly due to floating point errors or something of the sort, but catching this and reassigning the matrices didn't seem to do anything. If anyone thinks that's the correct way to do this let me know. I probably just don't understand how to use them effectively. But those are printed in the debug as well
Here is some debug output(not the whole program is shown)
DEBUG|ROW2_TOP origin.Y = 122.699327699265cm
DEBUG|ROW2_BOT origin.Y = 103.014327699265cm
DEBUG|TraverseAssembly Recursion depth = 1
DEBUG|TraverseAssembly Recursion depth = 2
DEBUG|TraverseAssembly Recursion depth = 3
DEBUG|TraverseAssembly Recursion depth = 4
DEBUG|TraverseAssembly Recursion depth = 5
DEBUG|TraverseAssembly Recursion depth = 6
DEBUG|TraverseAssembly Recursion depth = 7
DEBUG|Transformation Matrix for instance 2165062:4: 1.00000000000001, 1, 1
DEBUG|Adjusted Y-axis scale for occurrence 2165062:4
DEBUG|Transformation Matrix for instance post assignment2165062:4: 1.00000000000001, 1, 1
DEBUG|Name =: 2165062:4 | YPos = 109.219 | XPos = 77.69
DEBUG|TOP: 122.699, BOT: 103.014, OCC: 109.219
DEBUG|PRE ISBETWEENWORKPLANES EVALUATION: Not Double.IsNaN(109.219) : True
DEBUG|PRE ISBETWEENWORKPLANES EVALUATION: occPos > botPosition: True
DEBUG|PRE ISBETWEENWORKPLANES EVALUATION: occPos < topPosition: True
DEBUG|2165062:4 is between ROW2_BOT & ROW2_TOP. -------------------------++++
DEBUG|ROW2_TOP origin.Y = 122.699327699265cm
DEBUG|ROW2_BOT origin.Y = 103.014327699265cm
DEBUG|TraverseAssembly Recursion depth = 1
DEBUG|Transformation Matrix for instance 2165062:3: 1, 0.999999999999996, 1
DEBUG|Adjusted Y-axis scale for occurrence 2165062:3
DEBUG|Transformation Matrix for instance post assignment2165062:3: 1, 0.999999999999996, 1
DEBUG|Name =: 2165062:3 | YPos = 134.619 | XPos = 78.191
DEBUG|TOP: 122.699, BOT: 103.014, OCC: 134.619
DEBUG|PRE ISBETWEENWORKPLANES EVALUATION: Not Double.IsNaN(134.619) : True
DEBUG|PRE ISBETWEENWORKPLANES EVALUATION: occPos > botPosition: True
DEBUG|PRE ISBETWEENWORKPLANES EVALUATION: occPos < topPosition: False
DEBUG|2165062:3 is NOT between ROW2_BOT & ROW2_TOP.----------------------XXXXXX
Solved! Go to Solution.