Select a sketchline from top assembly, then go into lwer assembly and select same line again

Select a sketchline from top assembly, then go into lwer assembly and select same line again

Cadkunde.nl
Collaborator Collaborator
175 Views
2 Replies
Message 1 of 3

Select a sketchline from top assembly, then go into lwer assembly and select same line again

Cadkunde.nl
Collaborator
Collaborator

Hello Forum,

 

Ik made this automation that creates a Grid:

Cadkundenl_0-1738934553563.png

Now I want to add a function that allows you to select 2 vertical sketch3d lines

The code will make a diagonal 3d sketchline from first line start point to second line end point

 

I want to have the user select the lines in the top assembly (D0175547.iam in this case)

 

Then after selecting 2 lines, I go to the "#Grid" document, and want to reselect the same 2 lines in context of that document

 

Now that fails.

 

It probably is some 'a workpoint proxy in a higher assembly is not the workpoint in the lower assembly' - kind of thing.

 

I prefer not to check XYZ of the start and endpoints of every line, or something complicated like that.

 

This is the crude code I'm doing this proof of concept with:

 

Dim layoutdocname As String = AddinGlobal.LayoutDoc.FullFileName
Dim oDef As AssemblyComponentDefinition = AddinGlobal.LayoutDoc.ComponentDefinition
Dim BaseOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("#Base")
Dim GridDoc As PartDocument = Nothing
For Each oOcc As ComponentOccurrence In BaseOcc.SubOccurrences
If oOcc.Name = "#Grid" Then
GridDoc = oOcc.Definition.Document
End If
Next

Dim comps As ObjectCollection
Dim comp As Object

comps = AddinGlobal.InventorApp.TransientObjects.CreateObjectCollection
Dim osel As Inventor.SelectSet = AddinGlobal.LayoutDoc.SelectSet
osel.Clear()

While True
comp = AddinGlobal.InventorApp.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveLinearFilter, "Selecteer kolommen")

If IsNothing(comp) Then
Exit Sub
End If
comps.Add(comp)
osel.Select(comp)
If comps.Count = 2 Then Exit While
End While

Dim SketchLine1 As SketchLine3D = comps(1)
Dim SketchLine2 As SketchLine3D = comps(2)

AddinGlobal.InventorApp.Documents.Open(GridDoc.FullFileName, True)
Dim oSketch As Inventor.Sketch3D = GridDoc.ComponentDefinition.Sketches3D(1)
oSketch.Edit()

osel = GridDoc.SelectSet
osel.Clear()

For Each oLine As SketchLine3D In oSketch.SketchLines3D
If oLine Is SketchLine1 Or oLine Is SketchLine2 Then
osel.Select(oLine)
End If
Next

 

 

0 Likes
Accepted solutions (1)
176 Views
2 Replies
Replies (2)
Message 2 of 3

Cadkunde.nl
Collaborator
Collaborator

Hmm i posted too early.

 

With debugging i found something in sketchline3d called 'NativeObject'

 

Cadkundenl_0-1738937002660.png

 

And this seems to work:

 

If oLine Is SketchLine1.nativeobject Or oLine Is SketchLine2.nativeobject Then
osel.Select(oLine)
End If

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Cadkunde.nl.  This reply may be a little late, but should be helpful anyways.  Proxies are definitely one of the most complicated things to understand and deal with while attempting to automate Inventor, and interacting with assemblies.  When using the Pick function while an assembly is active, and selecting anything that is only in your assembly due to components being placed into it, then you will always get a 'top level' proxy object (in the 'context' of the main assembly).  When that proxy object represents something that is down multiple levels within the assembly (not just a top level component of a part), then generally the 'native object' of that proxy object will be another proxy of that object that exists within the context of a sub assembly, instead of the true original object that only exists in the context of the part.  So, one strategy for getting the original geometry object, is to use a 'recursive' routine which first checks if that object is a proxy or not, and if a proxy, accesses its native object, and tests that, and keeps repeating that pattern until something that is not a proxy is obtained.  Below is an example routine like that.  Since a 'proxy' type is always 'derived' from the 'normal' (non-proxy) type, using the TypeOf operator to check if the object's type is the non-proxy type will return True for both types.  Plus, I wanted this type of routine to be the as universal as I could make it, to cover all different types of objects / proxy objects, so I chose to use the TypeName method, and check for the 'proxy' text, which is pretty much always at the end of the type name.  This seemed to work pretty well.

The following is just a simple Boolean function that checks if an object is a proxy.

Public Function IsProxy(oObj As Object) As Boolean
	If oObj Is Nothing Then Exit Function
	If TypeName(oObj).ToUpper.EndsWith("PROXY") Then Return True
	Return False
End Function

But this one is for getting the 'source' (or original) object, and incorporates the same test functionality.

Function GetProxySource(oProxyObj As Object) As Object
	If oProxyObj Is Nothing Then Return Nothing
	If TypeName(oProxyObj).ToUpper.EndsWith("PROXY") = True Then
		Return GetProxySource(oProxyObj.NativeObject)
	Else
		Return oProxyObj
	End If
End Function

Another tactic to get the original object from a proxy object, is to access the parent 'ComponentDefinition' from the proxy object's properties somehow, then the object within that definition be the original, because that is where it was defined.  In this case, one possible proper property path we could follow would be:  SketchLine3DProxy.Parent which would get you the Sketch3D object that owns it.  Then Sketch3D.Parent will get you the PartComponentDefinition which owns that Sketch3D object, and that will be the 'context' in which it was defined.  Then you would step back down the object ladder from that 'definition' to the entity, and test for the one you are looking for.  But the property path changes with different types of proxy objects, so maybe not as universal or user friendly as the function.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)