Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Extract Curves Off Solid or Sheet

Status
Not open for further replies.

kr7530

Automotive
Aug 9, 2011
130
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
 
Replies continue below

Recommended for you

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
 
Frank,

Thank you, I will give that a try.

Kevin
 
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
 
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
 
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
 
The following code should get you started.

Code:
[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] System.Collections.Generic  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  

[COLOR=blue]Module[/color] extract_edges  

    [COLOR=blue]Sub[/color] Main()  

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

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

        [COLOR=green]'extract curves from edges of collected bodies[/color]
        [COLOR=blue]For Each[/color] tempBody [COLOR=blue]As[/color] Body [COLOR=blue]In[/color] bodyList  
            [COLOR=blue]Dim[/color] myEdges() [COLOR=blue]As[/color] Edge [COLOR=blue]=[/color] tempBody.GetEdges  
            [COLOR=blue]For Each[/color] tempCurve [COLOR=blue]As[/color] Edge [COLOR=blue]In[/color] myEdges  

                [COLOR=blue]Dim[/color] newCurveTag [COLOR=blue]As[/color] Tag  
                theUfSession.Modl.CreateCurveFromEdge(tempCurve.Tag, newCurveTag)  
                [COLOR=blue]Dim[/color] newCurve [COLOR=blue]As[/color] Curve [COLOR=blue]=[/color] Utilities.NXObjectManager.Get(newCurveTag)  

                [COLOR=blue]If[/color] tempBody.Layer [COLOR=blue]=[/color] 7 [COLOR=blue]Then[/color]  
                    layer7Curves.Add(newCurve)  
                End [COLOR=blue]If[/color]  

                [COLOR=blue]If[/color] tempBody.Layer [COLOR=blue]=[/color] 9 [COLOR=blue]Then[/color]  
                    layer9Curves.Add(newCurve)  
                End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  

        [COLOR=blue]Next[/color]  

        [COLOR=blue]Dim[/color] displayModification1 [COLOR=blue]As[/color] DisplayModification  
        displayModification1 [COLOR=blue]=[/color] theSession.DisplayManager.NewDisplayModification()  

        [COLOR=green]'format curves from bodies on layer 7[/color]
        displayModification1.NewColor [COLOR=blue]=[/color] 4  
        displayModification1.NewFont [COLOR=blue]=[/color] DisplayableObject.ObjectFont.Phantom  
        displayModification1.NewLayer [COLOR=blue]=[/color] 5  
        displayModification1.Apply(layer7Curves.ToArray)  

        [COLOR=green]'format curves from bodies on layer 9[/color]
        displayModification1.NewColor [COLOR=blue]=[/color] 1  
        displayModification1.NewFont [COLOR=blue]=[/color] DisplayableObject.ObjectFont.Phantom  
        displayModification1.NewLayer [COLOR=blue]=[/color] 5  
        displayModification1.Apply(layer9Curves.ToArray)  

        displayModification1.Dispose()  


    End [COLOR=blue]Sub[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
Thanks cowski! I must admit I have a lot to learn.
Kevin
 
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 :-(.

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
'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=359434[/URL]
'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
 
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
 
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
 
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
 
Hey cowski, thank you for the good news. Now it works! :)

Best regards,
Polynom2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor