Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieving a named edge for use in Rectangular Pattern

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
nick.seman
621 Views, 8 Replies

Retrieving a named edge for use in Rectangular Pattern

Hello:

 

I am having difficulty figuring out how to do this:

 

Within a rule, I would like to select a named edge and use it as the basis for the Rectangular Pattern command.  Looking at other posts on this forum I have been able to iterate through the features and verify that the named edge exists but I do not know how to identify that named edge for use in another command such as the Retangular Pattern command.  If you could provide some general direction I would appreaciate it.

 

Thanks;

Nick Seman

 

8 REPLIES 8
Message 2 of 9
JelteDeJong
in reply to: nick.seman

I'm a bit short in time therefore I did not test this code. But the general idea should be clear. But you need to use the attribute manager to get the edge:

 

Dim attSetName As String = "iLogicEntityNameSet"
Dim attName As String = "iLogicProxyEntityName"
Dim nameOfTheEdge = "MyEdgeName" ' <- Change this

Dim doc As Document = ThisDoc.Document
Dim attribMgr As AttributeManager = doc.AttributeManager
Dim foundEntities As ObjectCollection = attribMgr.FindObjects(attSetName, attName, nameOfTheEdge)

'assuming there is 1 edege with that name
Dim edge As Edge = foundEntities.Item(1)

 

Moreover, attributes can be found here: Introduction to Attributes

Attributes are not part of the normal user interface. but you can make them visible with this addin "Nifty Attributes"

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

Message 3 of 9
WCrihfield
in reply to: nick.seman

Hi @nick.seman.  I don't know what version of Inventor you may be using, but I think it was around the 2019 version that they added the 'NamedEntities' Interface into the iLogic AddIn, and added the ability to right-click on Faces, Edges, & Vertices in the model window of a Part, and select 'Assign Name...'.  When using that system to assign names to entities in the Part environment, it basically attaches an AttributeSet, and Attribute to the object you selected, then puts the name you typed in as the Attribute's Value.  If getting that named edge within an iLogic rule, there is a simpler way to work with them by code, that was not available before that point in Inventor's history.  Below is another example of retrieving a reference to a named entity by code, using that newer system.

Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(ThisDoc.Document)
Dim oNE As Object = oNEs.TryGetEntity("Entity's Name")

I think the method being used in that second line is a newer version which will not throw an error if the named entity is not found.  If your version of Inventor does not have that method available, you may have to use the example below instead.  That example below may throw an error if the entity is not found, so you may have to use that method within the Try part of a Try...Catch block of code to avoid the potential error.

Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(ThisDoc.Document)
Dim oNE As Object = oNEs.FindEntity("Entity's Name")

And if you have a version of Inventor prior to 2019, you will have to use a code similar to the first example shown by Jelte above, but I think names of the AttributeSet & Attribute may need to match what you specified when you created them.  When using the newer NamedEntities system, the AttributeSet is always named "iLogicEntityNameSet", and the Attribute name is always "iLogicEntityName", and the value of the Attribute will be the name you specified for the entity.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 9
nick.seman
in reply to: JelteDeJong

Thank you for your help!  This solution and the other solution both allow me to do what I was trying to do.

 

Nick

Message 5 of 9
nick.seman
in reply to: WCrihfield

Thank you for your help!  As I responded to JelteDeJong, I was able to apply both solutions to achieve what I was trying to do. 

 

Thanks again!

 

Nick

Message 6 of 9
nick.seman
in reply to: nick.seman

@WCrihfield -  A follow up question if I may:

 

I am having success using your assistance within part files however I now need to access a named edge while in an assembly file.  Reading your response to a question on 12-14-2021 to arnoldQ3YQQ you stated:

 

>>> Another way is like this:   (which allows you to specify a Document for it to target)

oNEs = iLogicVb.Automation.GetNamedEntities(oDoc)

<<<<

 

Try as I might, I am unable to accomplish identifying a named edge in an external part file.  I am sure that it is due to my inexperience in writing code - if you could (again) point me in the general direction I would greatly appreciate it.

 

Thanks;

Nick Seman

Message 7 of 9
WCrihfield
in reply to: nick.seman

Hi @nick.seman.  As you may be aware, that NamedEntities system only works in PartDocuments right now, because the part environment is the only one which allows you to use the 'Assign Name...' tool right now.  But, you can use it to retrieve named entities from other parts within an assembly, if you supply that line with the correct PartDocument object for the assembly component as input.  However, the geometry you retrieve will still be within the context of that PartDocument's 3D coordinate space, not within the 3D coordinate space of the assembly...yet.  If you want to work with that geometry in the context of an assembly, you will need to get the 'proxy' of that geometry, using the CreateGeometryProxy method of the assembly component that is currently representing that part.  The 'proxy' version of that geometry that you get from that method will now be in the context of that component's parent assembly, not necessarily the 'top level' assembly yet, if the component was down in a sub-assembly.  If the component was in a sub-assembly, you will next need to get the component representing that sub-assembly, and use its CreateGeometryProxy method to get a reference to the proxy of that proxy in its parent context, and so on, until the proxy is in the context of the top level assembly.  Then you can use that proxy object for things like measurements, constraints, and other uses that are within the context of the main assembly.

 

Below is an old example I had readily available for you to look over.  It gets a named face from within multiple top level components, then gets the proxies of those faces, which are then in the context of the top level assembly, then uses those face proxies to create face to face flush constraints in the assembly.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	Dim oFaceProxys As New List(Of FaceProxy)
	For Each oOcc As ComponentOccurrence In oOccs
		'if it does not represent a Part, then skip to next oOcc
		If oOcc.ReferencedDocumentDescriptor.ReferencedDocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
		Dim oOccDoc As PartDocument = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
		oNEs = iLogicVb.Automation.GetNamedEntities(oOccDoc)
		'if this name is not found within, then skip to next oOcc
		If Not oNEs.NameExists("GSTop") Then Continue For
		Dim oFace As Face
		'make sure it found something, and that it is a Face,
		'before assigning it as the value of a Face Type variable, to avoid potential error
		oObj = oNEs.TryGetEntity("GSTop")
		If oObj IsNot Nothing AndAlso TypeOf oObj Is Face Then
			oFace = oObj
		End If
		If oFace Is Nothing Then Continue For
		Dim oFaceProxy As FaceProxy
		'set the value of our oFaceProxy variable using the method below
		'this proxy object is retrieved from within the context of the component's parent assembly's 3D coordinate space
		oOcc.CreateGeometryProxy(oFace, oFaceProxy)
		oFaceProxys.Add(oFaceProxy)
	Next
	Dim oConsts As AssemblyConstraints = oADef.Constraints
	'the FaceProxy's must be a 'planar face' (flat) or this won't work
	Dim oFirstFP As FaceProxy = oFaceProxys.First
	For Each oFP In oFaceProxys
		If oFP IsNot oFirstFP Then
			oFlush = oConsts.AddFlushConstraint(oFirstFP, oFP, 0)
		End If
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 9
nick.seman
in reply to: WCrihfield

Thank you again for your help.  I was able to accomplish what I needed to do based on your help.

 

Nick

Message 9 of 9
nick.seman
in reply to: nick.seman

@WCrihfield - Curious - how would this work in a Part file with a derived part file attached?  I tried deriving a part file containing a solid with named edges and two named work points.  I do not select them in the Derived Part dialog box - just attach the part and select nothing as I do not want the geometry in the new file.

 

With the following code I am able to get the edge and the nodes.  I then create new WorkPoints in the current part drawing based on those in the derived drawing.

 

Dim oRefPart = oDerivedPartComps.Item(i).ReferencedDocumentDescriptor.ReferencedDocument
oNEs = iLogicVb.Automation.GetNamedEntities(oRefPart)
Dim oNEEdge1 As Object = oNEs.TryGetEntity("Edge_01")
Dim oNENode1 As Object = oNEs.TryGetEntity("Node_01")
Dim oNENode2 As Object = oNEs.TryGetEntity("Node_02")

Dim dWP As Point = oNENode1.Point
Dim ptX As Double = dWP.X / 2.54
Dim ptY As Double = dWP.Y / 2.54
Dim ptZ As Double = dWP.Z / 2.54
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
Dim oWP As Point = tg.CreatePoint(ptX, ptY, ptZ)
Dim WPs As WorkPoints = oDoc.ComponentDefinition.WorkPoints
Dim wp as WorkPoint = WPs.AddFixed(oWP)

Ultimately what I want to do is to create a rectangular array of the new work point along the named edge - but I cannot seem to use the edge geometry to plug into the following as "oEdge":

oRecFeat = oPCD.Features.RectangularPatternFeatures.Add(oBjCol, oEdge, False, qtypattern, DistPrompt1, PatternSpacingTypeEnum.kDefault)

  I have tried to create an edge proxy however I have not been successful - which leads me to ask the question as to whether I can even create a rectangular array in the part drawing without having an actual edge as the basis in the same drawing (?).  I appreciate any guidance you may provide.

 

(In case you are wondering what I am trying to do overall - I need to place reference workpoints and identify named edges in a base part drawing.  I then will access those in another part drawing, create matching work points and then create rectangular arrays of those work points.  (I do not want the arrays in the base part file).  I will then place the second part file into an assembly file.  Finally, I will be placing adaptive geometry relative/constrained to the workpoint arrays.)

 

Thanks;

Nick

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report