×
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

C# Programming

C# Programming

C# Programming

(OP)
Hello Guys,
Below is the code for two cylinder in C#. Please tell how to UNITE this 2 cylinder



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NXOpen;

namespace cylinderbuilder
{
public class Class1
{
public static void Main()
{
Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;

NXOpen.Features.CylinderBuilder cylinderbuilder;
cylinderbuilder = workPart.Features.CreateCylinderBuilder(null);

// Specify the cylinder definition type(AxisDiameterAndHeight)
cylinderbuilder.Type = NXOpen.Features.CylinderBuilder.Types.AxisDiameterAndHeight;

// Define the Cylinder Axis
Point3d origin = new Point3d(0, 0, 0);
Vector3d vector = new Vector3d(1, 0, 0);
Direction direction;
direction = workPart.Directions.CreateDirection(origin, vector, SmartObject.UpdateOption.WithinModeling);
Axis axis;
axis = cylinderbuilder.Axis;
axis.Direction = direction;

// Define Cylinder Diameter
string diamString = "100";
cylinderbuilder.Diameter.RightHandSide = diamString;

// Define Cylinder Height
string heightString = "20";
cylinderbuilder.Height.RightHandSide = heightString;

// Define the boolean option (Create, unite, etc.)
cylinderbuilder.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

// Destroy the builder to free memory
NXObject cylinder = cylinderbuilder.Commit();
cylinderbuilder.Destroy();


// Another Cylinder
NXOpen.Features.CylinderBuilder cylinderbuilder1;
cylinderbuilder1 = workPart.Features.CreateCylinderBuilder(null);

// Specify the cylinder definition type(AxisDiameterAndHeight)
cylinderbuilder1.Type = NXOpen.Features.CylinderBuilder.Types.AxisDiameterAndHeight;

// Define the Cylinder Axis
Point3d origin1 = new Point3d(20, 0, 0);
Vector3d vector1 = new Vector3d(1, 0, 0);
Direction direction1;
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling);
Axis axis1;
axis1 = cylinderbuilder1.Axis;
axis1.Direction = direction1;

// Define Cylinder Diameter
string diamString1 = "110";
cylinderbuilder1.Diameter.RightHandSide = diamString1;

// Define Cylinder Height
string heightString1 = "30";
cylinderbuilder1.Height.RightHandSide = heightString1;

// Define the boolean option (Create, unite, etc.)
cylinderbuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

// Destroy the builder to free memory
NXObject cylinder1 = cylinderbuilder1.Commit();
cylinderbuilder1.Destroy();
}
public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
}
}

RE: C# Programming

Hi,

Change the following line

// Define the boolean option (Create, unite, etc.)
cylinderbuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

To

// Define the boolean option (Create, unite, etc.)
cylinderbuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.unite;

Regards

Regards
Didier Psaltopoulos
http://www.psi-cad.fr

RE: C# Programming

(OP)
Hello Didier Psaltopoulos Sir,
Thank for your help.
I tried this as you wrote that change that line.
But I didn't get unite those cylinderbuilder.
If you have any other please kindly share.
Kishor

RE: C# Programming

Hi,

I am using VB and I am not a C# expert Unfortunatly.

Regards
Didier Psaltopoulos
http://www.psi-cad.fr

RE: C# Programming

Didier mean to change only for
The second cylinder.

If you done this and fail.

Try record a journal for the unit
Of two cylinders.

RE: C# Programming

(OP)
Hello Didier Psaltopoulos Sir,
If possible and you have code for uniting 2 cylinder in VB.
you could possibly share it for understanding purpose.
Because C# and VB is somewhat similar.
I know basic knowledge of VB also.

Thank You

RE: C# Programming

(OP)
Hello Didier Psaltopoulos Sir,
Here is code in VB for hole generation but it is getting ERROR.
Please suggest where to modified this code.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF




Module HOle
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim ufs As UFSession = UFSession.GetUFSession()
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Public Sub Main(ByVal args() As String)

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

'How to make body select??
Dim body1 As NXOpen.Body
body1 = SelectSolid()

Dim itargetBodies(0) As NXOpen.Body
itargetBodies(0) = body1

If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

CreateHole(0, 0, itargetBodies)
CreateHole(15, 0, itargetBodies)
CreateHole(30, 0, itargetBodies)

End Sub


Sub CreateHole(xcoord As Double, ycoord As Double, targetBodies As NXOpen.Body())

Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

Dim datumCsysBuilder1 As NXOpen.Features.DatumCsysBuilder
datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature)

Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem
cartesianCoordinateSystem1 = workPart.WCS.CoordinateSystem

'Define origin

Dim orPt As Point3d
orPt.X = xcoord
orPt.Y = ycoord
orPt.Z = 0
'New origin for CSYS
cartesianCoordinateSystem1.Origin = WCS2Abs(orPt)

datumCsysBuilder1.Csys = cartesianCoordinateSystem1

datumCsysBuilder1.DisplayScaleFactor = 0.5

Dim nXObject1 As NXOpen.NXObject
nXObject1 = datumCsysBuilder1.Commit()

Dim datumCsys2 As NXOpen.Features.DatumCsys = CType(nXObject1, NXOpen.Features.DatumCsys)

'Need to select datum origin.

Dim point1 As NXOpen.Point = CType(datumCsys2.FindObject("POINT 1"), NXOpen.Point)

'Dim point1 As NXOpen.Point = CType(datumCsys2.Location, NXOpen.Point)

datumCsysBuilder1.Destroy()

'Create Hole Part
Dim nullNXOpen_Features_HolePackage As NXOpen.Features.HolePackage = Nothing

Dim holePackageBuilder1 As NXOpen.Features.HolePackageBuilder
holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(nullNXOpen_Features_HolePackage)

'Point

Dim points1(0) As NXOpen.Point
points1(0) = point1
Dim curveDumbRule1 As NXOpen.CurveDumbRule
curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(points1)


Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = curveDumbRule1
Dim nullNXOpen_NXObject As NXOpen.NXObject = Nothing

Dim helpPoint1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)


With holePackageBuilder1

.HolePosition.AllowSelfIntersection(True)
.HolePosition.AddToSection(rules1, nullNXOpen_NXObject, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, False)
.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract
.BooleanOperation.SetTargetBodies(targetBodies)

End With

'Hole Type 6
With holePackageBuilder1

.GeneralHoleForm = Features.HolePackageBuilder.HoleForms.Simple
.HoleDepthLimitOption = Features.HolePackageBuilder.HoleDepthLimitOptions.ThroughBody
.GeneralSimpleHoleDiameter.RightHandSide = "6"
.GeneralSimpleHoleDepth.RightHandSide = "12"
.Tolerance = 0.001

End With

'Commit Hole
Dim nXObject2 As NXOpen.NXObject
nXObject2 = holePackageBuilder1.Commit()

holePackageBuilder1.Destroy()


End Sub




Function SelectSolid() As Body

Dim ui As UI = ui.GetUI
Dim message As String = "Select solid body"
Dim title As String = "Selection"

Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = True

Dim selectionAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific

Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

Dim selectedObject As NXObject = Nothing
Dim cursor As Point3d

ui.SelectionManager.SelectObject(message, title, scope, selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObject, cursor)

Dim solid As Body = CType(selectedObject, Body)

If solid Is Nothing Then
Return Nothing
End If

Return solid

End Function


Function Abs2WCS(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, _
UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)

Abs2WCS.X = pt2(0)
Abs2WCS.Y = pt2(1)
Abs2WCS.Z = pt2(2)

End Function

Function WCS2Abs(ByVal inPt As Point3d) As Point3d
Dim pt1(2), pt2(2) As Double

pt1(0) = inPt.X
pt1(1) = inPt.Y
pt1(2) = inPt.Z

ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt1, _
UFConstants.UF_CSYS_ROOT_COORDS, pt2)

WCS2Abs.X = pt2(0)
WCS2Abs.Y = pt2(1)
WCS2Abs.Z = pt2(2)

End Function


Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

Thank You


End Module

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! Already a Member? Login


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close