Feature Recognition in batch mode

Hi there,
I’m trying to set up something like a feature recognition algorithm that works in batch mode.

Therefore my idea would be to first access all the faces and edges of an existing part and get their measurements and orientations. Like this I could develop a program that’s telling me if I had a for instance a cylinder or a cuboid.

So, is there a way to select the faces of a random part and get their measurements in a batch mode application?
As I’m new to NXOpen and I have limited programming experience I’d be very thankful to get some help with this!

Thx!

Once you have a reference to a part object, you have access to the .Bodies collection. This is a collection of both sheet and solid bodies. Once you have a reference to a body, you can use the .GetFaces and/or .GetEdges method to get references to all the faces and/or edges. There are many functions to get information about faces and edges such as: AskFaceType, AskFaceData, AskFaceProps, etc etc.

Thank you very much, that helped a lot!

Hello everyone,

I already got great support the last time and I hope you can also help me with my current problem.
I am still working on a program that is analyzing arbitrary geometries. In this context I have been looking for ways to solve these 2 problems:

1.) Finding out whether a cylindrical face faces towards the inner side of a tube or whether it faces outwards.
I already found out that the axis vector given by the AskFaceData function seems to have a specific direction for each of the 2 possibilities but I’m not sure if that is of any help.

2.) I’m also looking for a way to determine if a surface forms a convex or a concave angle with an adjacent face. (Any surface of a cube for example would only have convex adjacent faces). In this context I’ve been wondering if normal vectors of faces always point towards the outside of the body and if they could be of any use.

Thanks in advance for your help,
Julian

Surface normals are the answer to both of your questions. If you are dealing with a solid body, all the face normals will point away from the body (never into the enclosed volume of the body). The AskFaceData direction will return the axis of the cylindrical face, which is not what you are looking for. The function AskFaceProps will return the normal vector at a given point on the face. Given this information, you can test whether the vector points toward the centerline of the cylindrical face (a hole) or away from the centerline (a boss).

AskFaceProps can also help with question #2; compare the normal vector of a point on or near the edge of face1 vs face2, the angle between the vectors will tell you if it is concave or convex.

If you are dealing with a bunch of sheet bodies rather than a solid, then all bets are off - the normals can point in any direction. If this is the case, I'd suggest sewing the sheet bodies of interest into a solid before interrogating the model.

Hello again and thanks for the information!

I think I am a very small step away from what I’m trying to do. So one (hopefully ;-) ) last problem:

I am now able to get the correct normal vectors of my faces. But measuring the angle between them always returns me a value between 0 and 180 degrees, which is not sufficient to detect concavity / convexity.
So, I have been trying to determine the correct angle with
theUFSession.Vec3.AngleBetween(vector1, vector2, Vector.Cross(vector1, vector2), angle) but with the cross product I always mathematically determine an angle smaller than 180 degrees between vector1 and vector2.

Before trying to set up some constraints for making this function work – is there may be a more simple way to do this?
I guess I need a function that takes into account information about the directions of the 2 vectors or something like that...!

As always, thank you very much in advance!

Nevermind, I found a nice way of solving my problem using an additional vector connecting my 2 normalvectors...
Whoever might be interested in that can look it up here:
http://www.grasshopper3d.com/forum/topics/convex-or-concave-angle-betwee...
Cheers

Glad to hear that you got it sorted and thanks for posting the link, that's a useful solution.

Hey,

I was wondering if there's a smart way of analyzing (getting lengths, angles, adjacent edges, ect.) a 2-dimensional projection of a body? Should this best be done in drafting mode or can the "project curve" operation be of any use?
Of course later on I want embed that in my nxopen code as well but for the moment I still need to figure out how to do that at all.

Thanks,
Julian

I'm not entirely sure what you are after; but yes, it is possible to project the edges to a plane of your choosing and analyze the resulting curves...

What I am after is projecting a body to three perpendicular planes. Analyzing these three projections would then give me the possibility to simply categorize the body in for example "long" or "flat" bodies. (I need this categorization for questions related to a part's manufacturability). Therefore the most convenient way would be to get only the projections of the silhouette.

I hope you got the idea of what I'm trying to acheive... any hints for that?

Do your planes align with views - either canned or custom? If so, see CreateShadowCurves() and CreateShadowOutline().

If an estimate is good enough for what you are doing, you can query the dimensions of the object's bounding box. I'd consider this a conservative estimate since the bounding box will always be as large or larger than the object.

I used to use the "shadow outline" command in interactive NX to help the tooling engineers estimate press size for the injection molded parts we were designing. It worked, but the resulting curves always required some hand cleanup before they were truly usable.

Thank you both for your answers.

My planes do align with views so CreateShadowCurves() and CreateShadowOutline() seem a good idea. However as I am interested in a completely automated process "some hand cleanup" is a criterion for exclusion.
Nevertheless I wanted to see what these functions exactly do but unfortunately I wasn't able to implement them correclty (I mentioned before that my visual basic and nxopen skills are rather basic...).

Instead I have been playing with the extract curve -> shadow outline function in Siemens NX and I was wondering if this is doing the same thing as the CreateShadowOutline() - function in NXOpen? If that is the case then for sure the "cleaning up" would be not feasible in my process. If it is not the case, maybe you could explain the difference to me and/or help me with the implementation of CreateShadowCurves() / CreateShadowOutline()?

Your other suggestion of using the object's bounding box is a good idea but for my purpose it's a little bit too vague.

Julian

I made a little detour which should solve my problem. having created 3 orthogonal faces I now use the extrude function on every face of my workpart and subtract the intersections from the 3 faces. This is actually the same as a projection and like this I can easily analyze the holes in these faces.
Thank you anyways for your ideas.
Julian

hey m trying to extract all data from the part such as featuretype,featurename,featuredimesions etc. i successfully extracted featuretype & featurename but dont know how to extract dimensions. please help...........

The Feature object has a .GetExpressions method that might prove useful.

i checked for .GetExpressions but Feature object isn't showing .GetExpressions. How should i obtain that one?

What type of feature are you dealing with and what type of dimensions do you hope to get out of it?

m dealing with EdgeBlend Feature & i want to get the radii of blending out of it

If you pass in the EdgeBlend feature to an EdgeBlendBuilder object, you can query all the blend information through the builder object.

I was sucessful to iterate all features.
I then iterated over it for each feature.
I am validating if the feature is of type blend and then I am trying to get the radius.
At code level I am not sure what I am missing but I am stuck at this point.
Can you please help me in further getting all the details of the edge blend as such as "Radius" etc.


Sub Main()
Dim thesesseion As Session = Session.GetSession
Dim workpart As Part = thesesseion.Parts.Work
Dim lw As ListingWindow = thesesseion.ListingWindow
lw.Open()
Dim featArray() As Feature = workpart.Features.GetFeatures()
For Each myFeature As Feature In featArray
If myFeature.FeatureType = "BLEND" Then
Dim blendFeature As EdgeBlend = myFeature
Dim edgeBuilder As EdgeBlendBuilder
edgeBuilder = workpart.Features.CreateEdgeBlendBuilder(myFeature)

lw.WriteLine("Radius" + "Some radius is what I expect")
End If

Next
lw.Close()

End Sub

The following journal will report the blend radius of each blend feature. Variable radius blends and conic shaped blends are not taken into consideration (the radius reported for a conic blend may be the center or boundary radius, depending on the blend definition type).

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each myFeature As Features.Feature In workPart.Features

If TypeOf (myFeature) Is NXOpen.Features.EdgeBlend Then
lw.WriteLine(myFeature.GetFeatureName)
Dim blendFeature As Features.EdgeBlend = myFeature
Dim edgeBuilder As Features.EdgeBlendBuilder
edgeBuilder = workPart.Features.CreateEdgeBlendBuilder(myFeature)
Dim numChainSets As Integer
numChainSets = edgeBuilder.GetNumberOfValidChainsets
lw.WriteLine("number of chain sets: " & numChainSets.ToString)

For i As Integer = 0 To numChainSets - 1
Dim myCollector As ScCollector
Dim radiusExpression As Expression
Dim isValid As Boolean
edgeBuilder.GetChainsetAndStatus(i, myCollector, radiusExpression, isValid)
lw.WriteLine("chainset " & i.ToString & ":")
lw.WriteLine(" isValid: " & isValid.ToString)
lw.WriteLine(" radius: " & radiusExpression.RightHandSide)
Next

End If

Next

lw.Close()

End Sub

End Module

Hey the code worked great .......... Thanks buddy.