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 JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

theUFsession.Modl.CreateCurveFromEdge

Status
Not open for further replies.

EngProgrammer

Aerospace
Joined
Jan 14, 2015
Messages
150
Location
US
I am using the subject function to extract the edges from a face of a solid body. Here's the snippet of code:

Code:
For Each thisEdge As Edge In largestFace.GetEdges
            Dim newCurve As NXOpen.Tag = NXOpen.Tag.Null
            theUFsession.Modl.CreateCurveFromEdge(thisEdge.Tag, newCurve)
        Next

It works great; however, it is returning the tag of the line. Next I want to take that line and put it on a specific layer.

so, I developed this code from journaling:

Code:
    Private Sub MoveToLayer(ByVal iLayer As Integer, ByVal obj As NXObject)

        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()

        displayModification1.ApplyToAllFaces = False

        displayModification1.ApplyToOwningParts = False

        displayModification1.NewWidth = DisplayableObject.ObjectWidth.Two

        displayModification1.NewLayer = iLayer

        'Dim objects1(0) As DisplayableObject
        'Dim line1 As Line = CType(workPart.Lines.FindObject("ENTITY 3 24 1"), Line)

        'objects1(0) = line1
        displayModification1.Apply({obj})

        displayModification1.Dispose()

    End Sub

I need to convert the tag of the line into an nxobject. How do I do that?

 
The DisplayModification object only operates on objects of type DisplayableObject. You'll have to get the curve object with the NXObjectManager and cast it to a displayable object. If you are using "Option Strict Off", you can let the compiler do the conversion for you:

Code:
Dim newCurveObj as DisplayableObject = Utilities.NXObjectManager.Get(newCurve)

www.nxjournaling.com
 
Isn't that sloppy coding. I was looking for a way to cast a tag into an line or NXobject.
 
EngProgrammer said:
Isn't that sloppy coding.

That's a matter of opinion. Personally, I don't have a problem with it; especially in cases such as yours. We know that the CreateCurveFromEdge function will return the tag of a curve object. We can do the conversions ourselves, or we can let the compiler do it; I see no advantage to doing it manually.


EngProgrammer said:
I was looking for a way to cast a tag into an line or NXobject.

A tag is just an integer value. The only feasible way to get an object from a tag is through the NXObjectManager. The NXObjectManager.Get() method will return a TaggedObject. So, if you like to do the conversions yourself, you could do something like this (no error checking in the following example):

Code:
Dim newTaggedObj As TaggedObject = Utilities.NXObjectManager.Get(thetag)
Dim newDisplayableObj As DisplayableObject = nothing
newDisplayableObj = CType(newTaggedObj, DisplayableObject)

www.nxjournaling.com
 
Still having problems moving the line to a layer. It seems like it moves it but when I turn on that layer there is nothing.
Code:
'  Find Largest Face from the Face Areas 
        For Each thisEdge As Edge In largestFace.GetEdges
            Dim newCurve As NXOpen.Tag = NXOpen.Tag.Null
            Dim newCurveObj As DisplayableObject
            theUFsession.Modl.CreateCurveFromEdge(thisEdge.Tag, newCurve)
            newCurveObj = Utilities.NXObjectManager.Get(newCurve)
            newCurveObj.Layer = 99
        Next
 
Try calling newCurveObj.RedisplayObject() after assigning the new layer. If that doesn't do the job, I'd try saving all the new curves into a list (or array) and using a DisplayModification object to move them all to the new layer.

www.nxjournaling.com
 
For comparison, here's how you do it using SNAP functions:

Code:
Public Class MyProgram

    Public Shared Sub Main()

      ' Example object for illustration
      Dim widget = Snap.Create.Widget

      ' Cycle through  edges, creating curves
      For Each edge In widget.Edges
         Dim curve = edge.ToCurve
         curve.Layer = 200
      Next

    End Sub

End Class

If you don't have access to SNAP, you can simplify your code by calling NXOpen.UF.UFObj.SetLayer, rather than using the DisplayModification approach. This SetLayer function receives a Tag as input, so things are easy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top