Version: Inventor Professional 2020.2
Question: Is the depth property of an assembly hole feature implemented in the API? Or am I running into some other issue?
I am running into an error when I try to get the depth of an assembly hole feature (ie. a hole feature that is in the assembly and not in a part). It appears that this section of code has not yet been implemented. Below is the error message.
Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))
Below is a screenshot of an example assembly with hole features in the assembly.
Below is a code snippet that will try to get the depth of the hole features in the assembly.
Sub Main() Dim assembly As AssemblyDocument = ThisDoc.Document For Each hole As HoleFeature In assembly.ComponentDefinition.Features.HoleFeatures MessageBox.Show(hole.Depth) 'Crashes here. Next hole End Sub
I did a little searching before and this might be related to this issue, but I am not sure.
Solved! Go to Solution.
Solved by ianteneth. Go to Solution.
Solved by chandra.shekar.g. Go to Solution.
Please provide non confidential file to test the behavior?
Thanks and regards,
Remembe that within the () of a MessageBox.Show(), it is expecting a certain order of things within.
The first section is usually "String" type data.
You may have to define this value as a string before it will show up like you want.
Try this:
Sub Main() Dim assembly As AssemblyDocument = ThisDoc.Document For Each hole As HoleFeature In assembly.ComponentDefinition.Features.HoleFeatures
Dim oDepth As String
oDepth = hole.Depth.ToString MessageBox..Show(oDepth,"Hole Depth") Next hole End Sub
Wesley Crihfield
(Not an Autodesk Employee)
Remember that within the () of a MessageBox.Show(), it is expecting a certain order of things within.
The first section is usually a "String" type data (message). And the second section is the 'Title' (also String).
You may have to define this value as a string before it will show up like you want with the MessageBox.
Try This:
Sub Main() Dim assembly As AssemblyDocument = ThisDoc.Document For Each hole As HoleFeature In assembly.ComponentDefinition.Features.HoleFeatures Dim oDepth As String oDepth = hole.Depth.ToString MessageBox.Show(oDepth,"Hole Depth") Next hole End Sub
Wesley Crihfield
(Not an Autodesk Employee)
@WCrihfieldThanks for the feedback! I have modified the code to show that the Messagebox.Show() method is not causing the error. This code yields the same error as I mentioned before.
@chandra.shekar.gI have attached a zipped folder containing an example assembly for you to test.
Sub Main() Dim assembly As AssemblyDocument = ThisDoc.Document For Each hole As HoleFeature In assembly.ComponentDefinition.Features.HoleFeatures Dim holeDepth = hole.Depth 'Crashes here. Next hole End Sub
either do:
holeDepth = hole.Depth
or:
Dim holeDepth As Double
holeDepth = hole.Depth
If using "Dim" it is expecting you to define its type, not its value.
Wesley Crihfield
(Not an Autodesk Employee)
@WCrihfield I updated the code to your recommendations (See below). It still crashes in the same way. I don't think the issue is the the variable instantiation. Thanks anyways!
And also, I forgot to mention that this issue was originally discovered in the C# api. So it is not limited to iLogic.
Sub Main() Dim assembly As AssemblyDocument = ThisDoc.Document For Each hole As HoleFeature In assembly.ComponentDefinition.Features.HoleFeatures Dim holeDepth As Double holeDepth = hole.Depth ' Crashes here Next hole End Sub
To address this issue, a change request (INVGEN - 35947 - Depth of hole feature in Assembly document throws exception) is created with engineering team.
Thanks and regards,
Good question. Although retrieving the Depth of a hole that goes through multiple parts in an assembly file currently creates an error, as stated above. Within a normal part file, you can create a hole feature, set to Through All, and when you retrieve its depth by iLogic, it returns a number equal to the thickness of the part (when both starting face & ending face are flat).
Though it is often forgotten that when features are created within a Part file, then attempting to access & use those features to support further processing within the assembly file, you almost always will need to create & work with a 'proxy' of that feature. That way you're not modifying the original part, but instead are working with a copy/representation of that feature, created within the Assembly.
Wesley Crihfield
(Not an Autodesk Employee)
This has reportedly been fixed in the 2021.1 update. I haven't tested it yet.
Can't find what you're looking for? Ask the community or share your knowledge.