Getting X, Y or Z-coordinate from argument instead of .X, .Y or .Z

Getting X, Y or Z-coordinate from argument instead of .X, .Y or .Z

J.Pelfrene
Enthusiast Enthusiast
469 Views
4 Replies
Message 1 of 5

Getting X, Y or Z-coordinate from argument instead of .X, .Y or .Z

J.Pelfrene
Enthusiast
Enthusiast

Hi all,

 

Just to know if there is a quicker way around getting the X, Y or Z coordinates by passing an argument.

For example, I now have a function like below for getting the max. material thickness for a 'Feature' structure in a given cardinal direction. The Feature structure essentially contains a FaceCollection of Faces that make up 1 machining feature.

 

    Public Function featureThickInDir(ByVal feat As Feature, ByVal dir As Integer) As Double
        Dim fthick As Double
        Dim thick As Double = 0.01
        If dir = 0 Then
            For Each oFace In feat.Faces
                fthick = oFace.Evaluator.RangeBox.MaxPoint.X - oFace.Evaluator.RangeBox.MinPoint.X
                thick = Math.Max(thick, fthick)
            Next
        ElseIf dir = 1 Then
            For Each oFace In feat.Faces
                fthick = oFace.Evaluator.RangeBox.MaxPoint.Y - oFace.Evaluator.RangeBox.MinPoint.Y
                thick = Math.Max(thick, fthick)
            Next
        ElseIf dir = 2 Then
            For Each oFace In feat.Faces
                fthick = oFace.Evaluator.RangeBox.MaxPoint.Z - oFace.Evaluator.RangeBox.MinPoint.Z
                thick = Math.Max(thick, fthick)
            Next
        Else
            Debug.Print("Utilities.featureThickInDir: not a valid direction")
        End If
    Return thick
    End Function

 

In short: is there a way to avoid the if-loop here and pass the 'dir' integer directly to the point?

 

And also thanks to this forum and especially the tutorials of @BrianEkins that got me started! 

 

Cheers.

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

dalton98
Collaborator
Collaborator

This is another way to go about it..

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oSurfBody As SurfaceBody
oSurfBody = oDoc.ComponentDefinition.SurfaceBodies.Item(1)

Dim maxthick As Integer = 0.001
Dim oFace1 As Inventor.Face
For Each oFace1 In oSurfBody.Faces
	Dim oFace2 As Inventor.Face
	For Each oFace2 In oSurfBody.Faces
		Try
		thick = ThisApplication.MeasureTools.GetMinimumDistance(oFace1, oFace2)
		If thick > maxthick
			maxthick = thick
		End If
		Catch
		End Try
	Next
Next
MessageBox.Show(maxthick)

 

0 Likes
Message 3 of 5

J.Pelfrene
Enthusiast
Enthusiast

Hey thanks,

 

That's a nice way for getting a max. distance between faces in the body. 

But my question is more that instead of something like this: 

 

Dim ycoord As Double = pointCoord(pt, 1)

Function pointCoord(pt As Point, dir As Integer) As Double
    If dir = 0 Then
        Return pt.X
    ElseIf dir = 1 Then
        Return pt.Y
    ElseIf dir = 2 Then
        Return pt.Z
    End If
End Function

 

 

Is there no way to get that coordinate something like:

 

Dim ycoord As Double = pt.coord(1)

 

 

The question seems pointless for getting the 'ycoord' here. But in my plugin I try to recognize the machining features in parts, for which the direction of drilling, milling, ... can be in X, Y or Z-dir. And I need to get the right one based on a parameter. So passing that parameter as an argument would be much less code and faster than with auxiliary functions such as above.

 

Thanks!

0 Likes
Message 4 of 5

basautomationservices
Advocate
Advocate
Accepted solution

You could do this:

 

 

Function pointCoord(pt as Point, i as integer) as double

Dim dbl = New Double() {}
pt.GetPointData(dbl)

if (dbl.Count - 1) > i then
   return dbl(i)
else
   return 0
end if

end function

 

You could make it into an extension so you can call it as: pt.Coord(i). I dont know how this works with iLogic though.

 

 

 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 5 of 5

J.Pelfrene
Enthusiast
Enthusiast

Thanks!

I guess it's the GetPointData function I was looking for.

0 Likes