Get Workpoint Location in Context of Parent Assembly

Get Workpoint Location in Context of Parent Assembly

Anonymous
Not applicable
1,276 Views
4 Replies
Message 1 of 5

Get Workpoint Location in Context of Parent Assembly

Anonymous
Not applicable
Hello,
I'm looking for help getting a part's workpoint location in context of some higher assembly. For instance, I have:

Root Assembly (center is 0,0,0)
--Assembly1 (center is 10,10,0 in relation to root)
----Part1 (center at 50,50,0 in relation to root)

In my example above, I want to get the center point of Part1 as if Assembly1 was the root assembly (this should give 40,40,0). The trick is that Assembly1 could be rotated inside its parent assembly (found it out the hard way when I realized my method was returning a negative number when it should have been positive), so it's not as easy as getting the global coordinates for Assembly1 and Part1 and subtracting Assembly1 coordinates from Part1 coordinates (basically moving the Assembly1 center point to the global center).
I thought my approach with proxies might work, but it hasn't proved too useful (maybe it's just that I'm not real familiar with how to use them).

{code}
Sub ProxyTest()
Dim doc As AssemblyDocument
Set doc = ThisApplication.ActiveDocument

Dim occAssy1 As ComponentOccurrence
Set occAssy1 = doc.ComponentDefinition.Occurrences(1)
Dim occAssy1Part1 As ComponentOccurrence
Set occAssy1Part1 = occAssy1.SubOccurrences(1)

Dim prxyAssy1Part1 As ComponentOccurrenceProxy
Set prxyAssy1Part1 = occAssy1Part1

Dim wpX As WorkPoint
Set wpX = prxyAssy1Part1.Definition.WorkPoints(1) 'Center Point

Dim prxyWP As WorkPointProxy
Call prxyAssy1Part1.CreateGeometryProxy(wpX, prxyWP)

Debug.Print prxyWP.Point.x, prxyWP.Point.Y, prxyWP.Point.Z

End Sub
{code}

Thanks for any help!
0 Likes
1,277 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
You can use proxies for this. Below is a sample that demonstrates it. I
created the sample assembly you specified and tested it with it. Before
running the program I selected Part1 in the browser.

Public Sub GetLocation()
Dim selectedOcc As ComponentOccurrenceProxy
Set selectedOcc = ThisApplication.ActiveDocument.SelectSet.Item(1)

Dim position As Vector
Set position = selectedOcc.Transformation.Translation
Debug.Print position.X & ", " & position.Y & ", " & position.Z

' Get the assembly this occurrence is immediately within.
Dim parentOcc As ComponentOccurrence
Set parentOcc = selectedOcc.ParentOccurrence

' Get the component definition of the parent occurrence.
Dim parentDef As AssemblyComponentDefinition
Set parentDef = parentOcc.Definition

' Trim the proxy path to the parent.
Dim trimmedOcc As ComponentOccurrence
Set trimmedOcc = parentDef.AdjustProxyContext(selectedOcc)

Set position = trimmedOcc.Transformation.Translation
Debug.Print position.X & ", " & position.Y & ", " & position.Z
End Sub


A proxy is an object that encapsulates a path down to the actual object. In
the case of your assembly, the ComponentProxy exists at the top-level but
consists of the path (each occurrence) as it traverses down to the actual
occurrence. In this case it's a single level path (Assembly1:1\Part1). The
AdjustProxyContext just edits the path by trimming it so the proxy will now
be in context to an assembly somewhere along the path. I know this may seem
complicated and it is difficult to describe in words but it's not as bad as
it seems. It's a good topic for a future blog article.
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Message 3 of 5

Anonymous
Not applicable
Hi Brian,

Your reply helped tremendously. I wasn't very familiar with proxy objects so I had no idea about adjusting it. That was just what I needed.

Thanks!
0 Likes
Message 4 of 5

rschader
Advocate
Advocate

Brian (or anyone knowledgeable),

 

I am trying to do something similar with workpoints and proxy's, but I am starting from a selected centermark on a drawing. I currently use

 

    Dim oWP As WorkPointProxy
    Set oWP = oCM.ModelWorkFeature

where oCM is passed as a CenterMark. This seems to automatically give me the correct XYZ coordinates in the context of the top level assembly, which is what I have used for a couple years now. However, now I find that I need the option to adjust (trim?) that WorkPointProxy down one level in the hierarchy. I am looking for the simplest method to get there, and hopefully using either Inventor 2009 or 2010 compatible code. Have any suggestions?

 

Bob

0 Likes
Message 5 of 5

rschader
Advocate
Advocate

Nevermind. I figured it out.

0 Likes