Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Question: How can I get a unit vector representing the direction of a hole from the centerpoint through the center axis in the direction that it is extruded?
I am on Inventor Professional 2019.4 writing a C# application. I am trying to translate a point from the centerpoint (Hole.HoleCenterPoints) of a hole to the midpoint (half of the hole depth) of a hole. Therefore I need to get a unit vector that starts at the centerpoint of a hole and goes in the direction that the hole is extruded in. One of my current methods involves the following code:
vector = hole.Sketch.PlanarEntityGeometry.Normal;
This code technically works as it gets a vector normal to the sketch that the hole centerpoint is drawn on. However, the direction of this vector isn't related to the extruded or extent direction of the hole. And this code is specifically for when the underlying geometry of the hole is based on the SketchPoint object.
I looked into the extent property of the hole (Hole.Extent) and accidentally found a direction property (Hole.Extent.Direction). However, this is not accessible in the API and I am not certain it will give me the information I need. The holes can be through holes so I cannot do anything fancy with the end face property (Hole.EndFaces). These holes can also be at any orientation. Anyone have any ideas?
Solved! Go to Solution.
Solved by JhoelForshav. Go to Solution.
Here is some additional information in case it helps someone.
Clarify Translate Method:
This method is used to translate (move) the centerpoint along the axis of the hole using the hole direction vector.
holeCenterPoint.TranslateBy(unknownVector);
Add Image:
In this image you can see the centerpoint (Hole Center Point), the midpoint (New Translated Point [Mid Point]), and the hole direction vector (Unknown Vector). Unknown Vector is the unit vector that I am looking for.
Hi @ianteneth
I think the extentdirection is relative to the sketchplane for the point/points defining your hole feature. Therefore i believe that if the direction is negative you need to flip the vector... Maybe something like this would work?
Dim oDoc As PartDocument = ThisDoc.Document Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition Dim hole As HoleFeature = oCompDef.Features.HoleFeatures.Item(1) Dim oTG As TransientGeometry = ThisApplication.TransientGeometry 'Get the normal for the sketchplane Dim vector As UnitVector = hole.Sketch.PlanarEntityGeometry.Normal Dim holeDir As PartFeatureExtentDirectionEnum If hole.Extent.Direction = PartFeatureExtentDirectionEnum.kNegativeExtentDirection 'If hole extent direction is negative then flip the normal Dim oMatrix = oTG.CreateMatrix oMatrix.Invert vector.TransformBy(oMatrix) End If
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Hi! Thanks for the reply! I tested your code snippet quickly and it works in iLogic. If I can test this in my C# application I think it will do what I need. However, as you can see in the images below, neither Inventor's iLogic editor nor the Inventor API help shows Direction as a property of the HoleFeature.Extent object. I am not sure why iLogic can still run the code if the Direction property isn't public on the API though? Maybe this is an API issue?
The first image show code in the iLogic editor. The second image is from the Inventor API help section that ships with Inventor. These images are from Inventor 2020.
I think it might be because there are several different Extent types and therefore you can only see the properties that exists in all of them before defining which extent type your specific extent object is... Or something like that
Maybe all these types does not have a property for direction is what im trying to say.
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-457EF0A2-A2F6-4C82-8E9C-4907C5AC7E5A
Anyway, I'm glad to hear the code works and I'm keeping my fingers crossed that you'll get it to work with C# aswell.
Good luck on your project!
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Thanks to @JhoelForshav for helping me get the Extent object working in C#!
Now that I finally can determine the hole direction vector I am confused by what I get. Below is a code snippet that will display the normal vector of the sketch as well as the extent direction type of the hole.
Sub Main() Dim part As Inventor.PartDocument = ThisDoc.Document Dim hole As Inventor.HoleFeature = part.ComponentDefinition.Features.HoleFeatures(1) Dim axis As Inventor.UnitVector = hole.Sketch.PlanarEntityGeometry.Normal Dim direction As String = "Negative (Opposite sketch normal)"
If hole.Extent.Direction = PartFeatureExtentDirectionEnum.kPositiveExtentDirection Then direction = "Positive (Same as sketch normal)" end if MessageBox.Show("Hole Extent: " & direction _ & vbNewLine & "Sketch Normal Vector: X:" & axis.X & " Y:" & axis.Y _ & " Z:" & axis.Z) End Sub
The results of this (for the simple cube part below) can be seen in the image below. We can see that the sketch normal vector and the hole extent direction vector are in the same direction per the API documentation because the direction type is kPositiveExtentDirection. And that the sketch normal vector is in the direction of Positive Y.
However, as you can see in this screenshot below, it appears that the hole extent direction vector is opposite of the sketch normal vector. The hole extent direction appears to go to the left (Negative Y-axis). Where as we already saw that the sketch normal vector is in the direction of Positive Y-axis (right).
Did I confuse my axes and signs or should the direction type for this hole be kNegativeExtentDirection?
Hi @ianteneth
Actually, it turns out i had two things wrong.
1. To flip a vector you should scale it by -1, the way i did it in the code wrote earlier doesnt work.
2. Positive direction is apparently the opposite direction of the PlanarEntityGeometry.Normal...
See attached ipt and run the ilogic code in it. Try flipping the direction of the hole feature and run it again. I think you'll get the idea then 🙂
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
I saw that I've a comment in the ilogic code in the attached ipt saying something like "if the direction is negative, flip the vector". Just thought i should mention it because it can be confusing. The code flips the vector if the direction is positive as it should be. Just forgot to change the comment 🙂
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Can't find what you're looking for? Ask the community or share your knowledge.