Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NXOpen.tag cannot be converted to NXOpen.Face

Status
Not open for further replies.

EngProgrammer

Aerospace
Joined
Jan 14, 2015
Messages
150
Location
US
Dear Forum,

I am using NXOpen function theUfSession.Modl.CreateRevolved(objarray, {"0", "360"}, origin, vect, FeatureSigns.Nullsign, features) to create a revolved sheet body from a line in the xy-plane. Next I want to extract the face of this revolved and pass it into another function to create intersection of curves. How do I cast an NXOpen tag into an NXOpen face?

Thanks in advance.
 
You have to use TaggedObjectManager to get the NXOpen TaggedObject, then cast that to your object type. Something like:
Code:
TaggedObject to = theSession.taggedObjectManager().get(yourTag);
Face yourFace = (Face)to;

Graham Inchley, Systems Developer, Sandvik Coromant. HP EliteBook 8760w, Win7, 8GB. Developing in: Java | C | C# | KF
Production: NX6.0.5.3 MP5
Testing: NX8.5.3.3 MP4 64bit | NX9.0.2.5
 
My programming language is VB.NET and NX9.

I am using the following function theUfSession.Modl.CreateRevolved(objarray, {"0", "360"}, origin, vect, FeatureSigns.Nullsign, features). The revolved surface is getting created but I am having problems casting the features(0) into a face. I've journaled the activity of taking the revolved sheet body and intersecting it with another sheet body to try and finding the casting.

Here's the snippet from the journal:

Dim bodyFeature1 As Features.BodyFeature = CType(workPart.Features.FindObject("REVOLVED(13)"), Features.BodyFeature)

Dim face5 As Face = CType(bodyFeature1.FindObject("FACE 67700 {(0,0,34) REVOLVED(13)}"), Face)
 
With your current methodology, you can get a reference to the revolve feature with the function given by grinch33. Once you have a reference to the revolve feature, you can use the .GetFaces method of the revolve feature to get references to the faces.

It might be a bit easier if you create the revolve with a RevolveBuilder; this will give you a reference to the newly created revolve feature without messing about with tags.

www.nxjournaling.com
 
I have a solution. Here's what I ended up doing. Here's the code snippet below. I ended up changing the revolved surface from 0 to 360 to 0 to 180. Therefore, hopefully ending up with one face from the revolved. I first had to get the feature name for some reason I don't completely understand. However, if someone hs an alternate method I would definitely be interested in alternatives. Thank you.

theUfSession.Modl.CreateRevolved(objarray, {"0", "180"}, origin, vect, FeatureSigns.Nullsign, features)

Dim featName As String = Nothing
theUfSession.Modl.AskFeatName(features(0), featName)

Dim bodyFeature1 As Features.BodyFeature = CType(workPart.Features.FindObject(featName), Features.BodyFeature)
Dim hoop() As Face = bodyFeature1.GetFaces()

Dim TestIntersect As Features.IntersectionCurve
TestIntersect = Nothing

For iii As Integer = 0 To hoop.Count - 1
Try
TestIntersect = createIntersectionCurves(Airfoil, hoop(iii))
Exit For
Catch ex As Exception
If iii.Equals(hoop.Count - 1) Then
'Throw New Exception("Failed to Find Intersect of Radial Hoop with Airfoil")
Return Nothing
End If
End Try
Next
 
The code below will revolve a line about the X axis and report some information about the resulting face.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim workPart As Part = theSession.Parts.Work

    Sub Main()

        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "NXJ journal"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        'create line to use in revolve feature
        Dim revolveLine As Line
        revolveLine = workPart.Curves.CreateLine(New Point3d(0, 25, 0), New Point3d(25, 25, 0))

        'revolve about absolute X vector
        Dim thePoint As Point = workPart.Points.CreatePoint(New Point3d(0, 0, 0))
        Dim theDirection As Direction = workPart.Directions.CreateDirection(thePoint.Coordinates, New Vector3d(1, 0, 0), SmartObject.UpdateOption.WithinModeling)
        Dim axis1 As Axis
        axis1 = workPart.Axes.CreateAxis(thePoint, theDirection, SmartObject.UpdateOption.WithinModeling)

        'create the revolve builder
        Dim revolveBuilder1 As Features.RevolveBuilder
        revolveBuilder1 = workPart.Features.CreateRevolveBuilder(Nothing)

        revolveBuilder1.Limits.StartExtend.Value.RightHandSide = "0"
        revolveBuilder1.Limits.EndExtend.Value.RightHandSide = "360"
        revolveBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
        revolveBuilder1.Tolerance = 0.001
        revolveBuilder1.FeatureOptions.BodyType = GeometricUtilities.FeatureOptions.BodyStyle.Sheet
        revolveBuilder1.Axis = axis1

        'create section for revolve builder
        Dim section1 As Section
        section1 = workPart.Sections.CreateSection(0.00095, 0.001, 0.5)
        section1.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)
        section1.AllowSelfIntersection(False)

        Dim curves1(0) As IBaseCurve
        curves1(0) = revolveLine

        'create curve rule
        Dim curveDumbRule1 As CurveDumbRule
        curveDumbRule1 = workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves1)

        'create selection intent rule
        Dim rules1(0) As SelectionIntentRule
        rules1(0) = curveDumbRule1
        Dim nullNXObject As NXObject = Nothing

        'add our input line to the section
        section1.AddToSection(rules1, revolveLine, nullNXObject, nullNXObject, revolveLine.StartPoint, Section.Mode.Create, False)

        revolveBuilder1.Section = section1
        'revolveBuilder1.ParentFeatureInternal = False

        Dim feature1 As Features.BodyFeature
        feature1 = revolveBuilder1.CommitFeature()

        revolveBuilder1.Destroy()

        'report the feature faces
        lw.WriteLine(feature1.GetFeatureName & " contains: " & feature1.GetFaces.Length.ToString & " faces")
        Dim theFaces() As Face = feature1.GetFaces()
        For i As Integer = 0 To theFaces.Length - 1
            lw.WriteLine("  face " & i.ToString & " color: " & theFaces(i).Color)
            lw.WriteLine("  face " & i.ToString & " layer: " & theFaces(i).Layer)
            lw.WriteLine("  face " & i.ToString & " area: " & FaceArea(theFaces(i)).ToString & " square inches")
            lw.WriteLine("")
        Next

        lw.Close()

    End Sub

    Function FaceArea(ByVal inputFace As Face) As Double

        Dim theFaceArea As Double

        Dim measureFaceBuilder1 As MeasureFaceBuilder
        measureFaceBuilder1 = workPart.MeasureManager.CreateMeasureFaceBuilder(Nothing)

        Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("SquareInch"), Unit)
        Dim unit2 As Unit = CType(workPart.UnitCollection.FindObject("Inch"), Unit)

        Dim objects1(0) As IParameterizedSurface
        Dim measureFaces1 As MeasureFaces
        Dim added1 As Boolean

        measureFaceBuilder1.FaceObjects.Clear()
        added1 = measureFaceBuilder1.FaceObjects.Add(inputFace)
        objects1(0) = inputFace
        measureFaces1 = workPart.MeasureManager.NewFaceProperties(unit1, unit2, 0.999, objects1)

        theFaceArea = measureFaces1.Area

        measureFaces1.Dispose()
        measureFaceBuilder1.FaceObjects.Clear()
        measureFaceBuilder1.Destroy()

        Return theFaceArea

    End Function

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top