Help giving and using entity names in another document

Help giving and using entity names in another document

MTheDesigner
Advocate Advocate
1,849 Views
9 Replies
Message 1 of 10

Help giving and using entity names in another document

MTheDesigner
Advocate
Advocate

Hey all, 

I am making some code that needs named edges for the sake of placing constraints. However, I can't go into each part and name things. I know that the constraints tool is able to name edges and then immediately use them without any conflicting names. I am trying to do basically exactly what the constraints tool does. But i don't know how to go about it.

 

My best attempt as of yet involves finding the part document and then using

oEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Please select your bolt edge")
Dim oEdgeBody As SurfaceBody = oEdge.Parent
Dim oEdgePart As ComponentOccurrence = oEdgeBody.Parent
Dim oEdgeDoc As Document = oEdgePart.Definition.Document
Dim oNamedEntities = iLogicAuto.GetNamedEntities(oEdgeDoc)
Try
	oNamedEntities.SetName(oEdge, "")

 

But i honestly don't knw what to do at this point, I named it "" because i was told this would make inventor pick the name itself, but once the name is made i don't know what it will be, and therefor don't know how to access it. I could make the assumption that it will be the highest number edge, or the last item in the list, but I don't know how inventor handles the names or if it sorts them.

 

0 Likes
1,850 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Hi @MTheDesigner.  I believe that since your goal in wanting to assigning names to these pieces of geometry is to be able to quickly and easily find them again for use in creating assembly constraints later, so you will most likely want to assign each piece of geometry a unique and meaningful name, that will help you specifically identify that entity later, and know exactly which one it is.  Most often folks do this naming process manually, as the models are being designed/created, or if the models are highly reused, they will manually do so after the fact.

 

However, in a case where there are already a vast amount of models already in existence, without any named entities already in them, and you want to be able to automate things like constraints and drawing dimensions/annotations based on those entities, this is most likely going to be a pretty challenging task to set-up.  Sometimes this can be done entirely by code by processing a batch of Inventor model files, if all the models are nearly identical, but you would have to have fairly intimate knowledge of those models, and be able to find and identify the entities through other means first.  For instance, if every model has the same two or three features, in the same order, and those features are all named the same, with the same parameter names, and all in the same orientation in relation to the origin work features, you could identify most entities by what feature they are part of, and in what position they are in, and what type of geometry it is, then assign a logically meaningful name to it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

Maybe it would be a possible way to place the new occurrence in your assembly and if the named entity is not found, you ask the user to select the needed edge? If user select it, a name can be assigned and is there for every further occurrence placement of the same part.

The following iLogic snippet shows a dialog to select the part to insert. After selecting the part will be inserted in the open assembly at root point. It looks if there is a named entity "Edge1". If found, an EdgeProxy will be created and selected. That Proxy should be used for constraining. If Edge1 is not found, it prompts the user to select a circular part edge, assign the name and create a Proxy and select it.

I'm sure this is not 1:1 what you need, but maybe can give you a direction to investigate.

 

	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
    Dim oAsmCompDef As AssemblyComponentDefinition=oAssDoc.ComponentDefinition
    Dim oTG As TransientGeometry= ThisApplication.TransientGeometry
    Dim oMatrix As Matrix = oTG.CreateMatrix
	Dim oFileDlg As FileDialog
	Dim sFileName As String
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Inventor Part Files (*.ipt)|*.ipt|All Files (*.*)|*.*"
    oFileDlg.FilterIndex = 1
    oFileDlg.DialogTitle = "Open File"
    oFileDlg.InitialDirectory = "C:\Temp"
    oFileDlg.CancelError = True

    On Error Resume Next
    oFileDlg.ShowOpen
    If Err.Number<>0 Then
        MsgBox ("File open canceled")
    ElseIf oFileDlg.FileName <> "" Then
        sFilename=oFileDlg.FileName 
    End If

    Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add(sFileName, oMatrix)
	Dim oDoc As Document=oOcc.Definition.Document
	Dim oAttrMgr As AttributeManager = oDoc.AttributeManager
	Dim oObjs As ObjectCollection = oAttrMgr.FindObjects("*", "*", "Edge1")
	Dim oObj As Object
	Dim oEdge As Inventor.Edge
	For Each oObj In oObjs
		If TypeOf oObj Is Inventor.Edge Then
			oEdge = DirectCast(oObj, Edge)
			Exit For
		End If
	Next
	
	If oEdge Is Nothing Then
		Dim oHighlightSet As HighlightSet = oAssDoc.CreateHighlightSet
		oHighlightSet.Color = ThisApplication.TransientObjects.CreateColor(255,0,0)	
	
		oHighlightSet.AddItem(oOcc)
	
		oEdge = DirectCast(ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeCircularFilter, "Select bolt edge on red highlighted Component"), Inventor.Edge)
		oNEs = iLogicVb.Automation.GetNamedEntities(oDoc)
		oNEs.SetName(oEdge, "Edge1")
		
		oHighlightSet.Clear 
		oHighlightSet = Nothing
	End If
	
	Dim oEdgeProxy As Inventor.EdgeProxy
	oOcc.CreateGeometryProxy(oEdge,oEdgeProxy)
	
	oAssDoc.SelectSet.Select(oEdgeProxy)

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 10

MTheDesigner
Advocate
Advocate

I just want to be able to work the same way the normal constraints tool works. When I use the constraints tool it is able to identify an edge on a part and use it, regardless of if it has been named before. I have some hints that they are naming the edge and then using it with images like this.

MTheDesigner_0-1648136349178.png

I know that I never named these edges, I also know that only the ones with constraints have names. 

I also know that the other side of these constraints have been used thousands of times without being named. 

To be fair, it looks like the multi use parts got names like "edge0" and "proxy edge: 3" but either way, inventor still constrains them together. It knows if something has a name or not. it creates a name if it doesn't and it uses that name in its constraint description. So I know this is possible. I just don't know what I need to do to achieve it.

0 Likes
Message 5 of 10

MTheDesigner
Advocate
Advocate

@Anonymous Hey, Thanks for replying.

You are definitely onto something with the proxy edges, this will allow me to place constraints on unnamed edges that are selected by the user.

 

You have solved half my problem to be sure.(The using of unnamed selected edges for batch placement)

 

But the whole point of this code is to save the user time. I don't want them to have to add a bolt, click both edges and hit accept for every bolt the need to place. Some of our assemblies require 1000's of bolts and so that eats up a lot of time.

I want to be able to only have to place one bolt and select one edge on that bolt. The user will still have to select the other edges that the bolt attaches to. but it would be a massive time saver to be able to place batches of 20-30 at a time.

 

When we select an edge on a bolt, inventor has to have some information, a way to identify it without a name, it has to highlight it without highlighting anything else. So it must have an identifier of some kind. The part names are the same, the references within the bolt assembly are the same, so presumably if I am placing the same bolt assembly every time it should have the same identifying information and just a different parent occurrence. I just want to select the same edge on every occurrence that my code places. jsut the ones where we already have the assembly and edge selection information.

0 Likes
Message 6 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

I think my code will do that

 

On the first time the bolt occurrence is placed in your assembly:

The name "Edge1" doesn't exist. The user is prompted to select the edge on the bolt. This edge become the name "Edge1". As an alternativ, you can create an iMate on these edge too and use that iMate. With this iMate or the name Edge1 you have an unique identifier in your part to get the right edge for constraining.

The user then needs to select the second edge (on a hole plate?) to complete the first constrain.

The inserted bolt is changed (named entity/iMate created) and will need to be saved. So the user need write access. The bolt can not be saved in content center or a library path or in Vault without checkout.

 

On all further placements of bolt:

The name "Edge1" exist. The edge can be found using AttributeManager. No user interaction needed at this point. The user needs to select the second edge to complete the constraint.

 

ToDo:

The whole placement could be done in a loop, so the user selects one time the edge of the bolt and then only one per one edge on the hole plate to place the next occurrences and contrain them.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 7 of 10

MTheDesigner
Advocate
Advocate
Ok, I see what you mean, unfortunately these bolt assemblies need to be library parts. They have been used for years, I can't risk changing them because I can't risk breaking years worth of assemblies
0 Likes
Message 8 of 10

WCrihfield
Mentor
Mentor

You might not need to use NamedEntieies or ReferenceKey system in this situation to accomplish a routine like this, if we are just talking about one component being placed a bunch of times, using the same edge on that component.  You could just run a rule, the rule will either ask you to select a component edge or get the already selected component edge from the Document's SelectSet, to use as the first side of the series of constraints, and just store that EdgeProxy in a temporary variable.  Then the rule can do a loop of creating constraints, and in each constraint it already knows the first Edge to use, then just asks you to select what you want to constrain it to each time.  Doesn't sound too difficult to code something like that.  This routine would not require saving anything back to the component's document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 10

MTheDesigner
Advocate
Advocate

@WCrihfieldHow could I identify the edge to be selected? Sure I can create an edge proxy, but the constraint requires an entity name, the EdgeProxy doesn't have a name, and I don't know how I can give it one. I know that it has the AttributeSet.Add("Name") but it seems to return a new set and not rename the proxy attribute.

 

0 Likes
Message 10 of 10

JelteDeJong
Mentor
Mentor

Some time ago I wrote 4 blog posts about adding names to faces in an assembly. Maybe they are any help to you:

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes