Retrieving Properties of an Entity

Retrieving Properties of an Entity

williama_mann
Participant Participant
322 Views
4 Replies
Message 1 of 5

Retrieving Properties of an Entity

williama_mann
Participant
Participant

Hi All!

 

So, I don't know how long "Named Entities" has been a thing in Inventor (I've only recently been updated 2024... still behind) but man, oh man do I wish Inventor had this sooner... or that I'd realized it sooner.

 

Here's my fit and function and I'm just not familiar enough with entities to know how to do it yet.

 

I've got an edge in my model identified as an entity and is named "SharedEdge". I'd like to utilize the length of that edge in an ilogic rule. So I would imagine something like:

 

Dim EdgeLength As Double = <insert stuff I don't know yet>

 

If anyone could let me know what that needs to look like, that would be amazing.

 

Thank you in advance!

-Will Mann

0 Likes
Accepted solutions (1)
323 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @williama_mann.  Below is a simple iLogic rule example that will attempt to find and get that named edge, and get determine its length, then show you that length in a pop-up message dialog.  There are multiple ways to get to those 'NamedEntities', but this is the simplest/easiest, when it works for the situation.  These can be a Face, Edge, or Vertex type objects.  It works by creating what are known as Attributes in those objects when you use the user interface tools to assign names to them.  Then this type of code, and multiple other methods, can find it because of those Attributes, which have specific names, and a value containing the name you supplied.

 

Dim oNEs As NamedEntities = ThisDoc.NamedEntities
Dim oMyNamedEdge As Edge = oNEs.TryGetEntity("SharedEdge")
If oMyNamedEdge Is Nothing Then
	MsgBox("Could Not Find Named Edge In 'This Document'!", vbCritical, "Named Edge Not Found")
	Exit Sub
End If

Dim oEval As CurveEvaluator = oMyNamedEdge.Evaluator
Dim oMinP, oMaxP, oLength As Double
'sets the values of those first two variables
oEval.GetParamExtents(oMinP, oMaxP)
'uses those first two values, and sets value of last variable
oEval.GetLengthAtParam(oMinP, oMaxP, oLength)
MsgBox("Edge Named 'SharedEdge' Length = " & oLength.ToString, vbInformation, "Named Edge Length")

 

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

 

Edit:  And by the way, they have been available using the uniquely iLogic object named 'NamedEntities' since around 2019.1 version of Inventor, I believe.  However, the method used behind the scenes to assign names to things, and find them again, has sort of been around much longer than that, but was not that easy or convenient to use, and there was no user interface tool for it back then.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

williama_mann
Participant
Participant

Thanks a ton Wesley!

Message 4 of 5

williama_mann
Participant
Participant

So I may have spoken a tad too soon. The code looks like it would get me the expected result however, there is one thing I'm seeing that I'd like to get your input on.

 

I'm using this to help determine the length of a 3d curve that's the multiplication of 2 arcs on perpendicular planes. So far, the code works just fine except that it seems to be one design iteration behind at all times. For example, if the initial curve length was 24, when I update the model (and features start to fail), I'll check the curve using Measure in the model and the curve may read out a length of 30 after the update, but the code will still produce 24 even if I run it after having updated everything else in the model. Then if I update the model parameters again, the code will produce 30 for the length, but by that point, the curve length is something else... say 40 for example.

 

It seems like the code executes before the model updates. So basically the code runs while out-of-date parameters are still dictating the geometry. Then after the model changes due to the parameter updates, the code spits out the old number (and in my case, tries to apply it to other model parameters).

 

I combed through the Event Triggers and tried a few to see if that could help but so far, no dice.

 

Any thoughts?

 

Thanks in advance!

William Mann

 

 

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Hi @williama_mann.  This is an odd sounding situation, so a little difficult to imagine.  There are a few possibilities that come to mind though.  Perhaps the first would be including an extra 'check' early in the code, before getting the entity or measuring it.  This would be checking the Document.RequiresUpdate property's value.  That is a ReadOnly property with a Boolean type value that gets set automatically by native Inventor processes when certain things happen to the document.  It does not necessarily cover everything possible, but is a good one to keep in mind.  If we check its value early in the code, and find its Value to be True, then we can update the document (using either Document.Update or Document.Update2 method) at that point, before accessing the entity or measuring it.  I have also seen situations where the 'RequiresUpdate' property apparently did not know that something had changed, and so the Update method did not do its thing, because it did not believe it was necessary.  In cases like that, we can use either the Document.Rebuild or Document.Rebuild2 method, which is supposed to ignore whether 'RequiresUpdate is true or not, and forces an update anyways.

 

Another thought that comes to mind is that the 'units' of measurement involved here may not be understood.  You may already know this, but most numerical values we get by code from Inventor API code, and even some from uniquely iLogic code, is usually always in what is known as 'database units'.  Database units are an unchangeable constant that are dictated by the software, not by any user accessible settings, and are always metric, instead of imperial.  The database units for length or distance is always centimeters, no matter what your document units are set to.  On the other hand, when using the user interface's Measure tool, with its convenient dialog, that will default to 'document units', but that dialog will also offer the ability to switch the units you want to see, or offer dual units.  Document units are specified within the Document Settings (Tools Tab - Options Panel), on the Units tab.

In my example code, the first two lines are mostly using uniquely iLogic API code, because 'ThisDoc', and 'NamedEntities' objects are defined by the iLogic add-in, but the rest of the lines are primarily using Inventor API code with some general vb.net code elements mixed in.  So, the measurement portion of the task is returning the value in database units (centimeters).

 

There is the possibility that something very difficult to explain is happening here.  Things like edges, and faces are considered BRep entities (Boundary Representation), and can be somewhat temporary or unstable.  This is because if you add more features to the model, and one of those features changes a pre-existing edge or face in any way, then a 'new' edge or face may be created to replace the previously existing one.  This can make it very difficult, or maybe even impossible to find or retrieve the pre-existing entities, without doing something like rewinding the feature tree (modeling history).  Assigning attributes to entities like these is one strategy commonly used to help us find entities like that later, but I don't recall if it works 100% of the time, in 100% of all possible situations.  This is why assigning names to entities within a model is usually the very last thing done before saving, creating a drawing for it, or using it in an assembly.  But I'm not sure if this 'behavior' has anything to do with the current issue.

 

Below is a slightly different version of my earlier code.  In this one, I am getting the Document object first.  If it is not a Part, then it will exit the rule, because it is only available in parts, as far as I know.  Then it checks that property, and updates the part, if needed.  I also put a line of code in there using the rebuild method, but left that commented out for now.  If the property check and update line does not fix the odd situation you are experiencing, then try uncommenting (delete the leading apostrophe) the line for rebuilding the document next.  Then, I am showing another uniquely iLogic way of getting the 'NamedEntities' from a specific Document object.  Then the measurement is done the same.  Then I added some code to automatically convert the units of the measured result to document units, if they are different units than the database units, before the final feedback message.

 

 

'get 'current' document, and try to Cast it to the PartDocument Type, without error
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
'if it was not a PartDocument, then no value was set to the variable in previous line
If oPDoc Is Nothing Then Return 'Return exits the routine
'check if Document needs an update, and if so, do it
If oPDoc.RequiresUpdate Then oPDoc.Update2(True)
'possibly 'Rebuild' the model, if needed
'oPDoc.Rebuild2(True)
'another way to get 'NamedEntities' which lets you specify the Document to get it from
Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
Dim sEntityName As String = "SharedEdge"
Dim oMyNamedEdge As Edge = oNEs.TryGetEntity(sEntityName)
If oMyNamedEdge Is Nothing Then
	MsgBox("Could Not Find Named Entity In Specified Document!", vbCritical, "Named Entity Not Found")
	Exit Sub
End If
'get the evaluator for this specific entity
Dim oEval As CurveEvaluator = oMyNamedEdge.Evaluator
'declare the variables we will need to use
Dim oMinP, oMaxP, oLength As Double
'sets the values of those first two variables
oEval.GetParamExtents(oMinP, oMaxP)
'uses those first two values, and sets value of last variable
oEval.GetLengthAtParam(oMinP, oMaxP, oLength)
'Get Document Units, then convert units of measurement, if different
Dim UOM As UnitsOfMeasure = oPDoc.UnitsOfMeasure
If UOM.LengthUnits <> UnitsTypeEnum.kDatabaseLengthUnits Then
	oLength = UOM.ConvertUnits(oLength, UnitsTypeEnum.kDatabaseLengthUnits, UOM.LengthUnits)
End If
'notify user of results
MsgBox("Length of Edge Named '" & sEntityName & "' = " & oLength.ToString, vbInformation, "Named Edge Length")

 

 

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)

0 Likes