Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

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: 

Get Hole Direction As A Vector

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
ianteneth
1711 Views, 7 Replies

Get Hole Direction As A Vector

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?

7 REPLIES 7
Message 2 of 8
ianteneth
in reply to: ianteneth

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.

image.jpg

 

Message 3 of 8
JhoelForshav
in reply to: ianteneth

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


Message 4 of 8
ianteneth
in reply to: JhoelForshav

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.Capture2.JPG

 

Capture.JPG

 

 

 

Message 5 of 8
JhoelForshav
in reply to: ianteneth

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 thatSmiley Very Happy

 

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!

Message 6 of 8
ianteneth
in reply to: ianteneth

 

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.

 

Annotation 2019-05-09 202433.jpg

 

 

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?

 

Annotation 2019-05-09 202402.jpg

 

 

Message 7 of 8
JhoelForshav
in reply to: ianteneth

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 🙂

 

 

Message 8 of 8
JhoelForshav
in reply to: JhoelForshav

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 🙂

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

Post to forums  

Autodesk Design & Make Report