Having problem with transform points

Having problem with transform points

rikard.nilsson
Collaborator Collaborator
657 Views
6 Replies
Message 1 of 7

Having problem with transform points

rikard.nilsson
Collaborator
Collaborator

Hi,

 

I'm having some trouble that I want some help with.

In the attached zip-file you will find a rule inside MatrixTest.iam.

If you run that rule you will se that it creates work points in the assembly by reading the position of the work points in the part. I'm using the TransformBy to move the points because the parts are rotated.

 

As you can see in the attached pricture the only points that will be placed ritght is the points frpm Part1:1

The points from Part1:2 is placed wrong.

Why is that and is there someone who has a solution för this problem?

 

Regards

Rikard

0 Likes
Accepted solutions (1)
658 Views
6 Replies
Replies (6)
Message 2 of 7

JamieVJohnson2
Collaborator
Collaborator

Use the geometry proxy system for this, its entire job is to translate geometries for you.  Here is your rule back doing what you want.

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition= oAsmDoc.ComponentDefinition
Dim prodAssyOcc As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName("SubMatrix:1")
Dim prodAssyDef As AssemblyComponentDefinition = prodAssyOcc.Definition
Dim prod1Occ As ComponentOccurrence = prodAssyDef.Occurrences.ItemByName("Part1:1")
'prod1Def  = prod1Occ.Definition

'Dim prelistOfPoints As New List(Of Point)

'For Each item In prod1Def.workpoints
'	If item.Name <> "Center Point" Then
'		prelistOfPoints.Add(item.point)
'	End If
'Next

For Each occ As ComponentOccurrence In prodAssyDef.Occurrences
'	Dim oMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
'	oMatrix = occ.Transformation

'	For Each item In prelistOfPoints
'		item.transformBy(oMatrix)
'		oAsmCompDef.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(item.x, item.y, 0))
'	Next
	For Each wp As WorkPoint In CType(occ.Definition, PartComponentDefinition).WorkPoints
		If wp.Name = "Center Point" Then Continue For
		Dim xPoint As WorkPointProxy = Nothing
		occ.CreateGeometryProxy(wp,xPoint)
		oAsmCompDef.WorkPoints.AddFixed(ThisApplication.TransientGeometry.CreatePoint(xPoint.Point.X, xPoint.Point.Y, 0))
	Next
Next

All occurrences can run CreateGeometryProxy.  CGP takes in the original object (workpoint defined in part), then the new object to place in context of occurrence (xPoint is a WorkPointProxy that is set to nothing until filled.)  Then once the proxy item is filled, you can rely on it to have translated coordinates in the context of the assembly space the occurrence came from.  This concept nests, so if you are using an assembly within an assembly within an assembly, each level can make a proxy of a proxy, until the top level makes a proxy of the original.  you will see that many geometry entities have a ...Proxy class version as well.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 7

rikard.nilsson
Collaborator
Collaborator

Hi!

 

Thanks for the answer. 

But if I’m right, making proxy is not god for performance.

in my ordinary models I have maybe 1500 work points in a part and up to 50 parts. And the creation of the work points in the end is just for showing the error. 

That is why I want to solve it by using Transform and math. 

 

Regards 

Rikard

 

 

0 Likes
Message 4 of 7

JamieVJohnson2
Collaborator
Collaborator

If you perform the math, or Inventor performs the math for you, it still requires processing time.  Also GeometryProxy which I have used much without issue, is more stable as it changes with your model, not relying on your code to keep up.

 

I do understand the 1500 objects issue for sure.  That is why if performance is an issue, then take advantage of Inventor 2019's ability to perform parallel computing, and look at the System.Threading.Task.Parallel.For series of options.  I have been able to get Inventor to perform operations on all 6 cpu cores (Xeon 6 core workstation), and reduce processing time from 5mins to 13 seconds.  I have a post here that can show you how it works (and oddly enough its about geometry proxies!).

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 5 of 7

rikard.nilsson
Collaborator
Collaborator

Thanks again!

Sounds interesting! But I need to keep at 2018. 

 

Du you have any idea why my technique works in the first part and not on the second one?

 

/Rikard

0 Likes
Message 6 of 7

JamieVJohnson2
Collaborator
Collaborator

Without testing to prove, I suspect the issue with the first set of dots working and the second not, is context of when you get the item.point.  It is in the context of the first part, and therefor acts as a proxy to its position.  When the second (and I dare say third, fourth and so on) points are translated, they are still translated with the first point's positions.  Perhaps moving the sub to get the points from the part, into your second loop, and getting it from EACH occurrences definition would accomplish your task.  But not as fast.

 

BTW I did attempt parallel computing in 2018, while some functions worked others did not.  Also, since then I learned better techniques, it is possible that 2018 can handle some parallel computing without spewing out memory errors.  Possible...  Nothing ventured, nothing gained.  But the speed benefit is DEFINITELY worth the learning curve.

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 7 of 7

BrianEkins
Mentor
Mentor
Accepted solution

This is how I would approach it using a matrix.  I think the issue you were probably seeing the workpoints you're "copying" are two levels deep in the assembly so you need to account for the transform of each occurrence leading to that part.  In building my matrix I get the inverse transform of the occurrence containing the workpoints and then the inverse transform of SubMatrix and multiply those together to get the full transform from the part to the top assembly.

 

You could also use proxies but you would need to do something similar to account for the multiple levels.  Basically you would create a proxy relative to the occurrence containing the work points and then use it to create a new proxy relative to SubMatrix.

 

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

Dim prodAssyOcc As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName("SubMatrix:1")
Dim prodAssyDef As AssemblyComponentDefinition = prodAssyOcc.Definition

' Iterate through the occurreces in the "Submatrix" assembly.
For Each occ As ComponentOccurrence In prodAssyDef.Occurrences
    ' Get the component associated with this occurrence.
    Dim prodDef As PartComponentDefinition = occ.Definition
    
    ' Create the transform for this occurrence.
    Dim trans As Matrix = occ.Transformation
    trans.Invert()
    Dim temp As Matrix = prodAssyOcc.Transformation
    temp.Invert()
    trans.TransformBy(temp)
    
    ' Iterate through the workpoints in this part.
    For Each wp As WorkPoint In prodDef.WorkPoints
        If wp.Name <> "Center Point" Then
            ' Get the position of the work point.
            Dim pstn As Point = wp.Point
            
            ' Transform the point.
            pstn.TransformBy(trans)
            
            ' Create a work point in the top assembly
            Call oAsmCompDef.WorkPoints.AddFixed(pstn)
        End If
    Next
Next

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes