Get Reference key from one occurrence and use it on another occurrence.

Get Reference key from one occurrence and use it on another occurrence.

matt_jlt
Collaborator Collaborator
1,111 Views
4 Replies
Message 1 of 5

Get Reference key from one occurrence and use it on another occurrence.

matt_jlt
Collaborator
Collaborator

Does anyone know if its possible to generate a reference key for a selected edge on an occurrence then use that reference key on another identical occurrence and retrieve the same edge.

 

I understand this can be done by re-assigning a proxy but i was hoping there is a way to achieve it using the reference keys.

 

Thanks, Matt.

0 Likes
1,112 Views
4 Replies
Replies (4)
Message 2 of 5

matt_jlt
Collaborator
Collaborator

Can someone from autodesk confirm if this is possible for me, so i know if i should abandon this workflow?

Thanks, Matt.

0 Likes
Message 3 of 5

g.georgiades
Advocate
Advocate

The documentation on reference keys specifically says it is document dependent so I cannot say for sure as I have not tested it well, especially when reference contexts are involved, but i would hope they persist or be occurrence-independent otherwise saving the keys to a text file would be somewhat pointless?

 

Alternatively, if your application does not require model updates, then transient keys may be an option? I have included a test sample I've recently been exploring for use in an assembly. The user picks a face from a part, then the part is copied a few times, then the same face on each component is selected. My intention is to use this concept as part of a multi-constraint utility.

 

You might be able to set up a test similar to the one I made below for reference keys?

 

Sub main()
	Dim face As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face")
	If face Is Nothing Then Exit Sub

	Dim faceKey As Integer = face.TransientKey

	Dim cptsur As ComponentOccurrence = face.SurfaceBody.containingoccurrence

	Dim cpt As Document = face.SurfaceBody.ComponentDefinition.Document
	Dim objs As New List(Of Face)
	For i = 0 To 4
		Dim nwcpt As ComponentOccurrence = ThisAssembly.Components.Add("", cpt.File.FullFileName,,,,).Occurrence

		Dim mat As Matrix = cptsur.Transformation
		mat.Cell(2, 4) = mat.Cell(2, 4) + i * 2
		nwcpt.Transformation = mat

		Dim obj As Face = nwcpt.SurfaceBodies.Item(1).BindTransientKeyToObject(faceKey) 'assuming type is face
			objs.Add(obj)
	Next i
	objs.ForEach(Sub(s) ThisDoc.Document.SelectSet.Select(s))
End Sub

 

0 Likes
Message 4 of 5

PanWauu
Contributor
Contributor
Hi Matt,
were you able to get this to work?
For me it kind of works for occurences of parts but not occurences of assemblies...
0 Likes
Message 5 of 5

matt_jlt
Collaborator
Collaborator

I didnt end up getting it to work and had to stick with "adjusting proxy context" method, but i didnt see the response from g.georgiades. I did try transient keys but had some issues, possibly the same ones you might be having.


I will have another look at it soon to see if his exact method gives a different result.

Please let me know if you get it working.

Thanks, Matt.

 

For reference, I select an occurrence edge, generate the key and context. Then i copy the occurrence, get the proxy edge using the stored key + context and adjust the proxy to the new occurrence. And repeat that as many times as needed.

0 Likes