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!

NX VB Journal - Create CenterPoint of an Arc 1

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
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
 
Replies continue below

Recommended for you

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!
 
If you are creating multiple points, move the point creation code into the while loop.
Code:
        [COLOR=blue]While[/color] select_anything(selobj) [COLOR=blue]=[/color] Selection.Response.Ok  
 [COLOR=green]'ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)[/color]
 [COLOR=green]'lw.writeline(selobj.tostring)[/color]
			arc1=ctype(selobj,ibasecurve)  
			cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)          
			cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)  
			  [COLOR=green]'[COLOR=green]remove parameters to create dumb point, keep them to create smart point (will follow the arc, but is not a point feature)[/color][/color]
			  [COLOR=green]'cpoint.[COLOR=green]RemoveParameters()[/color][/color]

        End [COLOR=blue]While[/color]
If you are only creating 1 point, change the while loop into an if block.
Code:
        [COLOR=blue]If[/color] select_anything(selobj) [COLOR=blue]=[/color] Selection.Response.Ok  
 [COLOR=green]'ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)[/color]
 [COLOR=green]'lw.writeline(selobj.tostring)[/color]
			arc1=ctype(selobj,ibasecurve)  
			cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)          
			cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)  
			  [COLOR=green]'[COLOR=green]remove parameters to create dumb point, keep them to create smart point (will follow the arc, but is not a point feature)[/color][/color]
			  [COLOR=green]'cpoint.[COLOR=green]RemoveParameters()[/color][/color]

        End [COLOR=blue]If[/color]


 
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).

 
Here's an example for the point feature:
Code:
        [COLOR=blue]if[/color] select_anything(selobj) [COLOR=blue]=[/color] Selection.Response.Ok  
 [COLOR=green]'ufs.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)[/color]
 [COLOR=green]'lw.writeline(selobj.tostring)[/color]
			arc1=ctype(selobj,ibasecurve)  
			cpoint=workpart.points.createpoint(arc1,smartobject.updateoption.withinmodeling)          
			cpoint.SetVisibility(SmartObject.VisibilityOption.Visible)  
			  [COLOR=green]'[COLOR=green]remove parameters to create dumb point, keep them to create smart point (will follow the arc, but is not a point feature)[/color][/color]
			  [COLOR=green]'cpoint.[COLOR=green]RemoveParameters()[/color][/color]

			  [COLOR=green]'*** start of code to create point feature[/color]
			Dim nullFeatures_Feature [COLOR=blue]As[/color] Features.Feature [COLOR=blue]=[/color] [COLOR=blue]Nothing[/color]  

			Dim pointFeatureBuilder1 [COLOR=blue]As[/color] Features.PointFeatureBuilder  
			pointFeatureBuilder1 [COLOR=blue]=[/color] workPart.BaseFeatures.CreatePointFeatureBuilder(nullFeatures_Feature)  

			pointFeatureBuilder1.Point [COLOR=blue]=[/color] cpoint  

			  [COLOR=green]'nXObject1 will be a reference to your new point feature[/color]
			Dim nXObject1 [COLOR=blue]As[/color] NXObject  
			nXObject1 [COLOR=blue]=[/color] pointFeatureBuilder1.Commit()  

			pointFeatureBuilder1.Destroy()  
			  [COLOR=green]'*** end of code to create point feature[/color]
        End [COLOR=blue]if[/color]


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor