Co-ordinates of a named workpoint (in component) relative to assembly origin

Co-ordinates of a named workpoint (in component) relative to assembly origin

gcoombridge
Advisor Advisor
1,553 Views
5 Replies
Message 1 of 6

Co-ordinates of a named workpoint (in component) relative to assembly origin

gcoombridge
Advisor
Advisor

Hi All,

 

I'm after a way to extract the co-ordinates of one (or many) named work points in a part from within the assembly environment and to compare them to the assembly origin. I.e. I want the co-ordinates relative to the assembly zero. This is for returning the positions of items in a layout.

 

I've found several posts that provide this from within a part. This code works fine:

 

Dim oDoc As Document

oDoc = ThisApplication.ActiveDocument

 

CoOrd = oDoc.ComponentDefinition.WorkPoints("Test Point")

CoOrd_X = CoOrd.Point.X * 10

CoOrd_Y = CoOrd.Point.Y * 10

CoOrd_Z = CoOrd.Point.Z * 10

 

CoOrdX= Round(CoOrd_X, 0)

CoOrdY= Round(CoOrd_Y, 0)

CoOrdZ= Round(CoOrd_Z, 0)

 

I am thinking there will just be something in the syntax to delve into the component level...? I assumed I could add the part names and instance prior the work point name string but this does not work.

As a secondary question why does this code return centimeters? (Hence the *10 multiplier)

 

Thanks!

 

Glenn

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Accepted solutions (2)
1,554 Views
5 Replies
Replies (5)
Message 2 of 6

JaneFan
Autodesk
Autodesk
Accepted solution

Hey @gcoombridge

 

Here is the way to navigate to component level of assembly: 

SyntaxEditor Code Snippet

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oOccDef As ComponentDefinition
oOccDef = oDoc.ComponentDefinition.Occurrences.ItemByName("ComponentName").Definition

Dim oWP As WorkPoint
oWP = oOccDef.WorkPoints("Test Point")

 If you are running code in iLogic editor, the simpler way to get component level is using Components object exposed in iLogic that the oOccDef line can be replaced with this: 

SyntaxEditor Code Snippet

oOccDef = Components("ComponentName").Occurrence.Definition

 




Jane Fan
Inventor/Fusion QA Engineer
Message 3 of 6

gcoombridge
Advisor
Advisor

Perfect! Thanks Jane

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 4 of 6

gcoombridge
Advisor
Advisor

Hi @JaneFan,

 

Just looking at this again it is returning the distance from the origin of the part not the assembly. Sorry my post was pretty unclear. As an addition to this can you advise how I would produce the distance from the named point and the assembly origin?

 

I thought about adding the distance between the assembly origin and part origin to the result above but this would be invalid with a part rotation.


Thanks for your help!

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
0 Likes
Message 5 of 6

JaneFan
Autodesk
Autodesk
Accepted solution

Do you need get the position in assembly coordinate system of the work point in component level? If so, we need get a proxy of the work point in assembly coordinate system: 

SyntaxEditor Code Snippet

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
    
Dim oOcc As ComponentOccurrence
oOcc = oDoc.ComponentDefinition.Occurrences.ItemByName("Part1:1")
    
Dim oOccDef As ComponentDefinition
oOccDef = oOcc.Definition
    
Dim oWP As WorkPoint
oWP = oOccDef.WorkPoints("Test")
MsgBox("x: " + oWP.Point.X.ToString() + ", y: " + oWP.Point.Y.ToString() + ", z: " + oWP.Point.Z.ToString() )
Dim oWPProxy As WorkPointProxy
Call oOcc.CreateGeometryProxy(oWP, oWPProxy)
MsgBox("x: " + oWPProxy.Point.X.ToString() + ", y: " + oWPProxy.Point.Y.ToString() + ", z: " + oWPProxy.Point.Z.ToString() )

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 6 of 6

mallorn
Advocate
Advocate

hello @JaneFan !

I was trying to follow your example, but my Working point is deeper in assembly tree and I have to go through "reference path" to "get" the occurrence.

 

I'm still getting the coordinates to the local component origin...

oCompDef.Occurrences.ItemByName(TempRefChain(0))
Dim stepOcc As ComponentOccurrence = flightOcc.Definition.Occurrences.ItemByName(TempRefChain(1))
Dim endPlateOcc As ComponentOccurrence = stepOcc.Definition.Occurrences.ItemByName("stepEndplate")

 

 

 

Function GetRotation(oCompDef As ComponentDefinition, prefix As String, viewRepWithPrefix As String)
Dim angle As Double = 0
Dim ref As String = Right(viewRepWithPrefix, viewRepWithPrefix.Length-prefix.Length)
Dim TempRefChain() As String = ref.Split(".")
Dim flightOcc As ComponentOccurrence = oCompDef.Occurrences.ItemByName(TempRefChain(0))
Dim stepOcc As ComponentOccurrence = flightOcc.Definition.Occurrences.ItemByName(TempRefChain(1))
Dim endPlateOcc As ComponentOccurrence = stepOcc.Definition.Occurrences.ItemByName("stepEndplate")
		
Dim point0, point1 As WorkPoint
Dim wp As WorkPoint
		
For Each wp In endPlateOcc.Definition.WorkPoints
	If wp.Name = "Center Point" Then
		Logger.Trace(wp.Name & ": " & wp.Point.X & "|" & wp.Point.Y & "|" & wp.Point.Z)
		point0 = wp
	ElseIf wp.Name = "outCenterPoint" Then
		Logger.Trace(wp.Name & ": " & wp.Point.X & "|" & wp.Point.Y & "|" & wp.Point.Z)
		point1 = wp
	End If
Next wp
		
Dim point0Proxy, point1Proxy As WorkPointProxy
Call endPlateOcc.CreateGeometryProxy(point0, point0Proxy)
Call endPlateOcc.CreateGeometryProxy(point1, point1Proxy)
Logger.Trace("point0Proxy: " & point0Proxy.Point.X & "|" & point0Proxy.Point.Y & "|" & point0Proxy.Point.Z)
Logger.Trace("point1Proxy: " & point1Proxy.Point.X & "|" & point1Proxy.Point.Y & "|" & point1Proxy.Point.Z)
End Function

 

 

My Proxy points return the same coordinates, as WorkPoints (and they shouldn't, as they are not the same according to main Assembly), here is an output example for my files with different values of point1 coordinates :

 

 

	TRACE|creating view stepView|flight:1.step:1
	TRACE|Center Point: 0|0|0
	TRACE|outCenterPoint: 0|-96,515|0
	TRACE|point0Proxy: 0|0|0
	TRACE|point1Proxy: 0|-96,515|0
	TRACE|creating view stepView|flight:1.step:9
	TRACE|Center Point: 0|0|0
	TRACE|outCenterPoint: 0|-96,515|0
	TRACE|point0Proxy: 0|0|0
	TRACE|point1Proxy: 0|-96,515|0
	TRACE|creating view stepView|flight:2.step:1
	TRACE|Center Point: 0|0|0
	TRACE|outCenterPoint: 0|-96,515|0
	TRACE|point0Proxy: 0|0|0
	TRACE|point1Proxy: 0|-96,515|0

 

 

 

-------------------------
Tomasz Malinowski
0 Likes