×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Extract Curves Off Solid or Sheet

Extract Curves Off Solid or Sheet

Extract Curves Off Solid or Sheet

(OP)
I am getting back into writing some journals and I am struggling with extracting edge curves off a solid or sheet. I can't seem to record it or find any examples.
Some background info, I have new data on layer 1 and old data on layer 2 and would like to extract curves off both and place those curves on layer 3. The curves extracted from layer 1 to be colored red and curves from layer 2 to be blue. Layers 1 and 2 could be multiple skins or solids.
We currently have a macro that works in 7.5 but is failing in 8.0. I was hoping to rewrite it in .vb to ease transitions to newer versions.

Any help would be greatly appreciated.
Thanks,
Kevin

RE: Extract Curves Off Solid or Sheet

To extract face edges you need to use the wrapper function.

Public Sub CreateCurveFromEdge ( _
edge_id As Tag, _
<OutAttribute> ByRef ugcrv_id As Tag _
)

Frank Swinkels

RE: Extract Curves Off Solid or Sheet

(OP)
Frank,

Thank you, I will give that a try.

Kevin

RE: Extract Curves Off Solid or Sheet

(OP)
Any suggestions as to the best way to have .vb make my selections for me? Below is a couple of methods I was looking at trying to use. I like the idea of using the mask filters but i am unsure how to incorporate them into either of the below methods.
____________
ufs.Obj.CycleObjsInPart(workPart.Tag(), UFConstants.UF_solid_type, tmpTag)
If tmpTag > NXOpen.Tag.Null Then
If ufs.Assem.IsOccurrence(tmpTag) = False Then
ufs.Obj.AskTypeAndSubtype(tmpTag, type, subtype)
If subtype = UFConstants.UF_solid_face_subtype Then
Dim thisFace As Face = NXObjectManager.Get(tmpTag)
____________
layerObjects = workPart.Layers.GetAllObjectsOnLayer(7)
If layerObjects.Length > 0 Then
____________
My current program:

Option Strict Off
Imports System
Imports NXOpen
Imports System.Collections
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Imports NXOpen.Features


Module Extract_Edges_Of_Solid_or_Sheet
Sub Main

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow()
Dim obj() As NXObject
Dim workPart As Part = theSession.Parts.Work
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim ufs As UFSession = UFSession.GetUFSession()

If select_edges(obj) = Selection.Response.Cancel Then
Exit Sub
End If
For Each tmpEdge As NXObject In obj
Dim thisEdge As NXOpen.Tag = tmpEdge.Tag
Dim tmpEdgeLayer As DisplayableObject
tmpEdgeLayer = CType(NXObjectManager.Get(thisEdge), DisplayableObject)
Dim newCurve As NXOpen.Tag = NXOpen.Tag.Null
If tmpEdgeLayer.Layer = 7 Then
ufs.Modl.CreateCurveFromEdge(thisEdge, newCurve)
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
displayModification1.NewColor = 4
displayModification1.NewFont = DisplayableObject.ObjectFont.Phantom
displayModification1.NewLayer = 5
Dim object1(0) As DisplayableObject
object1(0) = CType(NXObjectManager.Get(newCurve), DisplayableObject)
displayModification1.Apply(object1)
displayModification1.Dispose()
Else If tmpEdgeLayer.Layer = 9 Then
ufs.Modl.CreateCurveFromEdge(thisEdge, newCurve)
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
displayModification1.NewColor = 1
displayModification1.NewFont = DisplayableObject.ObjectFont.Phantom
displayModification1.NewLayer = 5
Dim object1(0) As DisplayableObject
object1(0) = CType(NXObjectManager.Get(newCurve), DisplayableObject)
displayModification1.Apply(object1)
displayModification1.Dispose()
Else

End If

Next




End Sub

Function select_edges(ByRef obj() As NXObject)

Dim ui As UI = ui.GetUI()
Dim message As String = "Select a circular object"
Dim title As String = "Selection"
Dim selectionMask_array(0) As Selection.MaskTriple

selectionMask_array(0).Type = UFConstants.UF_solid_type
selectionMask_array(0).Subtype = UFConstants.UF_solid_edge_subtype
selectionMask_array(0).SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE



Dim resp As Selection.Response = _
ui.SelectionManager.SelectObjects(message, title, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, selectionMask_array, obj)

If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.Ok Then
return Selection.Response.Ok
Else
return Selection.Response.Cancel
End If

End Function


End Module


Thanks,
Kevin

RE: Extract Curves Off Solid or Sheet

Do you want the user to select the body(ies) and/or edges or do you want the journal to automatically select them?

If automatically, what filter should the journal use (e.g. all solid bodies on layer 2)?

www.nxjournaling.com

RE: Extract Curves Off Solid or Sheet

(OP)
I would like the journal to select edges of all solids and skins on layers 7 and 9.

This works as filters when manually selecting:
selectionMask_array(0).Type = UFConstants.UF_solid_type
selectionMask_array(0).Subtype = UFConstants.UF_solid_edge_subtype
selectionMask_array(0).SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE

Kevin

RE: Extract Curves Off Solid or Sheet

The following code should get you started.

CODE

Option Strict Off  
Imports System  
Imports System.Collections.Generic  
Imports NXOpen  
Imports NXOpen.UF  

Module extract_edges  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim theUfSession As UFSession = UFSession.GetUFSession  
        Dim workPart As Part = theSession.Parts.Work  
        Dim bodyList As New List(Of Body)  
        Dim layer7Curves As New List(Of Curve)  
        Dim layer9Curves As New List(Of Curve)  

        'collect bodies on layers 7 and 9
        For Each tempBody As Body In workPart.Bodies  
            If tempBody.Layer = 7 OrElse tempBody.Layer = 9 Then  
                bodyList.Add(tempBody)  
            End If  
        Next  

        'extract curves from edges of collected bodies
        For Each tempBody As Body In bodyList  
            Dim myEdges() As Edge = tempBody.GetEdges  
            For Each tempCurve As Edge In myEdges  

                Dim newCurveTag As Tag  
                theUfSession.Modl.CreateCurveFromEdge(tempCurve.Tag, newCurveTag)  
                Dim newCurve As Curve = Utilities.NXObjectManager.Get(newCurveTag)  

                If tempBody.Layer = 7 Then  
                    layer7Curves.Add(newCurve)  
                End If  

                If tempBody.Layer = 9 Then  
                    layer9Curves.Add(newCurve)  
                End If  
            Next  

        Next  

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

        'format curves from bodies on layer 7
        displayModification1.NewColor = 4  
        displayModification1.NewFont = DisplayableObject.ObjectFont.Phantom  
        displayModification1.NewLayer = 5  
        displayModification1.Apply(layer7Curves.ToArray)  

        'format curves from bodies on layer 9
        displayModification1.NewColor = 1  
        displayModification1.NewFont = DisplayableObject.ObjectFont.Phantom  
        displayModification1.NewLayer = 5  
        displayModification1.Apply(layer9Curves.ToArray)  

        displayModification1.Dispose()  


    End Sub  

End Module 

www.nxjournaling.com

RE: Extract Curves Off Solid or Sheet

(OP)
Thanks cowski! I must admit I have a lot to learn.
Kevin

RE: Extract Curves Off Solid or Sheet

Hello!

Sorry for using the old thread again but I think I am not that off-topic.

I have got a question relating to kr7530’s post on 11 Feb 14 13:27 (post #4). The modification of the code I am currently working on simply creates a spline after the selection of a specific edge and moves it to the layer of desire, see below.

Is there any chance to force the spline to be displayed in the Part Navigator (currently it is NOT listed), like as “Spline 794”? The spline is needed for further manipulations. Probably there is some kind of command missing similar to this:
Spline -> “.IsAssociative = True”

If you select a spline, open the Studio Spline window and go to settings there appears a checkbox called “Make Associative”. Therefore it must be possible to code it too, but I cannot find it sad.

CODE -->

Option Strict Off
Imports System
Imports NXOpen
Imports System.Collections
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Imports NXOpen.Features

'RAW Source
'http://www.eng-tips.com/viewthread.cfm?qid=359434
'11 Feb 14 13:27 

Module Extract_Edges_Of_Solid_or_Sheet_MOD
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        Dim lw As ListingWindow = theSession.ListingWindow()
        Dim obj() As NXObject
        Dim workPart As Part = theSession.Parts.Work
        Dim theUFSession As UFSession = UFSession.GetUFSession()
        Dim ufs As UFSession = UFSession.GetUFSession()

        If select_edges(obj) = Selection.Response.Cancel Then
            Exit Sub
        End If


        For Each tmpEdge As NXObject In obj

            Dim thisEdge As NXOpen.Tag = tmpEdge.Tag
            Dim newCurve As NXOpen.Tag = NXOpen.Tag.Null

            ufs.Modl.CreateCurveFromEdge(thisEdge, newCurve)
            Dim displayModification1 As DisplayModification
            displayModification1 = theSession.DisplayManager.NewDisplayModification()
            displayModification1.ApplyToAllFaces = True
            displayModification1.ApplyToOwningParts = False
            displayModification1.NewColor = 4
            displayModification1.NewFont = DisplayableObject.ObjectFont.Phantom
            displayModification1.NewLayer = 5   'layer of desire
            Dim object1(0) As DisplayableObject
            object1(0) = CType(NXObjectManager.Get(newCurve), DisplayableObject)
            displayModification1.Apply(object1)
            displayModification1.Dispose()

        Next

    End Sub

    Function select_edges(ByRef obj() As NXObject)

        Dim ui As UI = ui.GetUI()
        Dim message As String = "Select Edge"
        Dim title As String = "Selection"
        Dim selectionMask_array(0) As Selection.MaskTriple

        selectionMask_array(0).Type = UFConstants.UF_solid_type
        selectionMask_array(0).Subtype = UFConstants.UF_solid_edge_subtype
        selectionMask_array(0).SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE

        Dim resp As Selection.Response = _
        ui.SelectionManager.SelectObjects(message, title, _
        Selection.SelectionScope.AnyInAssembly, _
        Selection.SelectionAction.ClearAndEnableSpecific, _
        False, False, selectionMask_array, obj)

        If resp = Selection.Response.ObjectSelected Or _
        resp = Selection.Response.ObjectSelectedByName Or _
        resp = Selection.Response.Ok Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

End Module 

Best regards,
Polynom2000

RE: Extract Curves Off Solid or Sheet

The spline does not need to be a feature in the part navigator to be able to edit it later. However, if you so desire, you can use a StudioSplineBuilderEx object to convert your spline to a feature. Start the journal recorder, double click your spline object, in the studio spline dialog box, check the "associative" option and OK the dialog. Stop the journal recorder and examine the resulting code.

The resulting spline will be associative to the underlying data, not to the edge that you picked (this is true of both the spline object or the spline feature). If you need to have the spline associated to the edge, try using a composite curve feature instead of extracting the edge.

One thing to keep in mind is not every curve created by your journal will be a spline; the resulting curve will inherit the underlying edge type (it may be a line or arc). You should test to see what type of curve you have before trying to convert it to a spline feature.

www.nxjournaling.com

RE: Extract Curves Off Solid or Sheet

The reason I asked for the associative option is that I need the exact name of the created spline. Afterwards the Point Set function should use the new spline and put 10 points on this line. Later I need those points for other manipulations.
Currently I don’t know what name I have to paste instead of "SPLINE(780)" in order to refer to the new spline. Below is some fractional code of the Point Set function which refers to a spline (associative = true, also visible in the Part Navigator).

CODE -->

Dim studioSpline1 As Features.StudioSpline = CType(workPart.Features.FindObject("SPLINE(780)"), Features.StudioSpline) 

I have recorded a journal, double clicked the spline, checked the "associative" option and examined the resulting code. There appears some StudioSplineBuilderEx feature but there is some problem: Instead of FindObject(~NewSplineCreated) spline1 refers to some strange entity which differs during time and other circumstances.

CODE -->

Dim spline1 As Spline = CType(workPart.Splines.FindObject("ENTITY 9 1 1"), Spline)
Dim studioSplineBuilderEx1 As Features.StudioSplineBuilderEx
studioSplineBuilderEx1 = workPart.Features.CreateStudioSplineBuilderEx(spline1) 


I am looking for something similar to the code above (example just shows Wave Linker). This code snippet should be located close to the “spline builder”. For later purposes you can reuse the string “Object_Want_to_use_later”.

CODE -->

Dim Object_Want_to_use_later As String

nXObject1 = CType(nXObject1_1, NXObject)
nXObject1 = waveLinkBuilder1.Commit()

Object_Want_to_use_later = nXObject1.JournalIdentifier 

It seems that object1(0).JournalIdentifier does not work properly, because it ALWAYS returns “ENTITY 9 1 1” which is in fact NOT true. I have created multiple splines with the code of my previous post (30 Jul 14 7:13) and executed a simple Point Set Journal with the following FindObject input: "ENTITY 9 1 1", "ENTITY 9 2 1", "ENTITY 9 3 1". The modified entity number works pretty well – I am confused why object1(0).JournalIdentifier does not work in this context.

Any idea how to get (always) the correct name of the spline just created so that it can be used as input for the Point Set function?

Best regards,
Polynom2000

RE: Extract Curves Off Solid or Sheet

Good news: you don't need the name of the object to use it; you already have a reference to the object - its tag. You can use the object manager to return an object given the tag.

CODE

Dim myCurve as Curve
myCurve = Utilities.NXObjectManager.Get(curveTag) 

www.nxjournaling.com

RE: Extract Curves Off Solid or Sheet

Hey cowski, thank you for the good news. Now it works! smile

Best regards,
Polynom2000

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources