Get the hyerachy of a picked leaf occurrence in order to constraint a part

Get the hyerachy of a picked leaf occurrence in order to constraint a part

rbertoletti
Enthusiast Enthusiast
428 Views
6 Replies
Message 1 of 7

Get the hyerachy of a picked leaf occurrence in order to constraint a part

rbertoletti
Enthusiast
Enthusiast

Dear all,

i'm trying to figure out how to build the hyerachy of a picked component in order to constraint another part to it.

 

Here's an example:

Picked object name "N2"

Hyerachy to use in the constraint command: "234312-1B", "203U", "N2"

 

The "N2" occurrence exists also in many other different assemblies, so i need to specify the parents of the picked one to constraint it correctly.

 

Thanks in advance

 

0 Likes
429 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant

Hi @rbertoletti,

I'm not sure I fully understand the question, but if by hyerachy you mean the syntax to specify the following:

  • name of the constraint
  • the first selected item
  • the second selected item

then it would be something like this using the iLogic AddInsert function:

 

In this example the name of the constraint is determined by Inventor by supplying an empty string ""

 

Dim oOcc1 As ComponentOccurrence 
Dim oOcc2 As ComponentOccurrence 
oOcc1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select component 1")
oOcc2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select component 2")

Constraints.AddInsert("", oOcc1.Name, "Top Edge", oOcc2.Name, "Bottom Edge", axesOpposed := true, lockRotation := True)

 

Curtis_Waguespack_0-1722433756742.pngCurtis_Waguespack_1-1722433822272.png

 

 

 

 

 

EESignature

Message 3 of 7

rbertoletti
Enthusiast
Enthusiast

Maybe i didn't explained it clearly (sorry i'm italian).
anyway i'm trying to constraint two items but the problem is that the picked object is an occurrence placed in an assembly and also in others.


i think i need to use the "MakePath" command.

 

Let's suppose that i need to constraint a component between the 2 occurrence shown in the pictures below.

 

Occurrence 1:

rbertoletti_0-1722435087507.png

 

Occurrence 2:

rbertoletti_1-1722435153330.png

 

You can see the occurrence is always "N1" but from different sub-assemblies.

 

Let me know if now it's clear

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @rbertoletti.  It all depends on how you plan on creating the constraint.  If using the Inventor API tools, then you will not need to specify the 'ancestry' of the component, or the name of the entity within that component, just the actual entity itself.  However, if using the iLogic API tools, then you must specify 'names' of objects, rather than the actual objects themselves.  And in that case, when it comes to specifying which components are involved, it wants what it calls a  ComponentArgument.  This can either be the simple name of the component (as seen in the model browser), or it can be an Array of Strings which starts with the name of the top level component that represents a sub assembly, then each sub component below that, including the component you are dealing with directly. 

 

Correction:  In my statements above about how to specify the ComponentArgument, when using the iLogic tools, I left out one possible way.  You can also specify a ManagedComponentOccurrence.  To explain what this is...when using the Pick function, you will get the 'normal' Inventor API object as its value, not one of these iLogic specific variations of that type of object.  You get a ManagedComponentOccurrence when using iLogic tools like Components.Item property (aka IManagedComponents.Item property), or Components.Add method (aka IManagedComponents.Add method).

 

Edit:  If you need to create/generate that Array of Strings in a more intuitive way, the Inventor API object that represents an assembly component (ComponentOccurrence) has a property (ComponentOccurrence.OccurrencePath) that will return a ComponentOccurrencesEnumerator, which will contain each ComponentOccurrence in the path of that component, starting with the top level component, and including that original component as its last entry.  That can be used to extract their names from for the Array of Strings you may need.  Below is an example of a custom Function that can be used for that purpose.

 

Function GetComponentPath(oOcc As ComponentOccurrence) As String()
	If oOcc Is Nothing Then Return Nothing
	Dim oOccPathOccs As ComponentOccurrencesEnumerator = oOcc.OccurrencePath
	Dim oOccPath(oOccPathOccs.Count - 1) As String
	For i As Integer = 1 To oOccPathOccs.Count
		oOccPath(i-1) = oOccPathOccs.Item(i).Name
	Next
	Return oOccPath
End Function

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

Curtis_Waguespack
Consultant
Consultant

@rbertoletti, combining the pick with the iLogic constraint methods is going to present a challenge of getting the component path argument passed into the constraint method in the format that it expects.

We might be able to do so using something like what WCrihfield suggests, but I think using the Inventor API method to  create the constraint would be a better approach.

 

The main difference is that the pick selection is an edge and not a component. If selecting edges is acceptable then something like this might work:

 

oEdge1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, 
	"Select edge on component 1")
oEdge2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, 
	"Select edge on component 2")

If oEdge1 Is Nothing  Or oEdge2 Is Nothing  Then Exit Sub

' Create the insert constraint between the parts.
Dim oInsert As InsertConstraint
oInsert = ThisAssembly.Document.ComponentDefinition.Constraints.AddInsertConstraint(oEdge1, 
	oEdge2, True, 0)
 

 

EESignature

Message 6 of 7

rbertoletti
Enthusiast
Enthusiast
But if the Edge name is the same on both occurrence it should not work, right?
0 Likes
Message 7 of 7

rbertoletti
Enthusiast
Enthusiast

Currently the only thing i'm not able to figure out in the constraints is this one in blue.

By using the pick command i should be able to create a constraint like this one.

 

Constraints.AddMate("Mate:1", "TESTPLATE:1", "Z Axis",
                    {"UPPER_HEADER:1", "N4"}, "Face0",
                    e1InferredType := InferredTypeEnum.kNoInference,
                    e2InferredType := InferredTypeEnum.kInferredLine,
                    solutionType := MateConstraintSolutionTypeEnum.kOpposedSolutionType)

 i'm looking to use the pick of the entire occurrence instead of the edge as per is easier to select by the user.

0 Likes