×
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

NX VB Journal - Create CenterPoint of an Arc

NX VB Journal - Create CenterPoint of an Arc

NX VB Journal - Create CenterPoint of an Arc

(OP)
Okay, I'm just trying to get NX to put a point at the center of an arc.  Seems simple enough in concept.  But it's not working for me.  Here's my code (ultimately I'm just trying to get the "createpoint" method to work - the rest is just to try it out):

CODE

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Windows.Forms
Imports System.Environment

Module report_selected_object_type_and_subtype

    Sub Main
         Dim s As Session = Session.GetSession()
        Dim ufs As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()
        Dim selobj As NXObject
        Dim arc1 as ibasecurve
        dim workpart as part = s.Parts.Work
        dim cpoint as point = nothing
        dim kk as integer=0
        Dim type As Integer
        Dim subtype As Integer
        Dim lw As ListingWindow = s.ListingWindow

        While select_anything(selobj) = Selection.Response.Ok
            ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
            lw.open()
            lw.writeline(selobj.tostring)
        End While

        arc1=ctype(selobj,ibasecurve)
        cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)        
        cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)
        End Sub

    Function select_anything(ByRef selobj As NXObject) As Selection.Response

        Dim theUI As UI = ui.GetUI
        Dim cursor As Point3d
        Dim typeArray() As Selection.SelectionType = _
            { Selection.SelectionType.curves }

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject("Select anything", _
                "Select anything", _
                Selection.SelectionScope.WorkPart, _
                false, typeArray, selobj, cursor)

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

End Module

If I have an arc on the screen I click on it and the journal completes without errors but I don't get any new points created.  Is there another method I should be using?

Thanks,
Jeff

RE: NX VB Journal - Create CenterPoint of an Arc

(OP)
Oops, nevermind - I moved the first EndWhile after the SetVisibility and it worked!

I knew I shoulda waited until I gave it one more kick at the can!

RE: NX VB Journal - Create CenterPoint of an Arc

If you are creating multiple points, move the point creation code into the while loop.

CODE

        While select_anything(selobj) = Selection.Response.Ok  
 'ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
 'lw.writeline(selobj.tostring)
            arc1=ctype(selobj,ibasecurve)  
            cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)          
            cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)  
              'remove parameters to create dumb point, keep them to create smart point (will follow the arc, but is not a point feature)
              'cpoint.RemoveParameters()

        End While  
If you are only creating 1 point, change the while loop into an if block.

CODE

        If select_anything(selobj) = Selection.Response.Ok  
 'ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
 'lw.writeline(selobj.tostring)
            arc1=ctype(selobj,ibasecurve)  
            cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)          
            cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)  
              'remove parameters to create dumb point, keep them to create smart point (will follow the arc, but is not a point feature)
              'cpoint.RemoveParameters()

        End If  
 

www.nxjournaling.com

RE: NX VB Journal - Create CenterPoint of an Arc

Also bear in mind that your code as is will create a "smart" point object; if the arc is moved it will follow, but it is not a point feature. I know of no way to create such a point in interactive NX, it may confuse other users of your file. If you want to create a "dumb" point, remove the parameters after the point is created (line is commented out in my code above). Alternatively, it would only take a few more lines of code to turn it into an associative point feature (the type that shows up in the part navigator).

www.nxjournaling.com

RE: NX VB Journal - Create CenterPoint of an Arc

Here's an example for the point feature:

CODE

        if select_anything(selobj) = Selection.Response.Ok  
 'ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)
 'lw.writeline(selobj.tostring)
            arc1=ctype(selobj,ibasecurve)  
            cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)          
            cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)  
              'remove parameters to create dumb point, keep them to create smart point (will follow the arc, but is not a point feature)
              'cpoint.RemoveParameters()

              '*** start of code to create point feature
            Dim nullFeatures_Feature As Features.Feature = Nothing  

            Dim pointFeatureBuilder1 As Features.PointFeatureBuilder  
            pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)  

            pointFeatureBuilder1.Point = cpoint  

              'nXObject1 will be a reference to your new point feature
            Dim nXObject1 As NXObject  
            nXObject1 = pointFeatureBuilder1.Commit()  

            pointFeatureBuilder1.Destroy()  
              '*** end of code to create point feature
        End if  
 

www.nxjournaling.com

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