×
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

Can someone help me with this code snippet

Can someone help me with this code snippet

Can someone help me with this code snippet

(OP)
Hi

Please can someone help in converting this python code to vb

Thank you very much

CODE -->

def datum_plane(self, datum_origin, datum_normals, datum_corners):
        
        self.theLw.WriteLine('\n')
        self.theLw.WriteLine("Datum Plane function")

        
        for i in range(len(datum_corners)):
            datumPlaneBuilder = workPart.Features.CreateDatumPlaneBuilder(NXOpen.Features.Feature.Null)
            self.theLw.WriteLine('\n')
            self.theLw.WriteLine('\n')
            self.theLw.WriteLine('\n')

            #returns an NX.Open Plane object, from DatumPlaneBuilder class
            plane = datumPlaneBuilder.GetPlane()
            geom = []
            plane.SetGeometry(geom)
            plane.SetUpdateOption(NXOpen.SmartObject.UpdateOption.WithinModeling)

            #using dist from plane to origin and a surface normal to create the plane
            plane.SetMethod(NXOpen.PlaneTypes.MethodType.Coefficients)
            
            origin = NXOpen.Point3d(datum_origin[i][0], datum_origin[i][1], datum_origin[i][2])
            
            plane.Origin = origin

            #a, b, c coefficients
            normal = NXOpen.Vector3d(datum_normals[i][0], datum_normals[i][1], datum_normals[i][2])
            plane.Normal = normal
            plane.Evaluate()

            datumPlaneBuilder.ResizeDuringUpdate=False
            
            datum_feat=datumPlaneBuilder.CommitFeature()
            
            #need to get journal Identifier of datum plane and pass it as an object
            self.theLw.WriteLine("Datum feature is "+str(datum_feat.JournalIdentifier))
            
            #create instance of resize plane
            resizePlaneBuilder = workPart.Features.CreateResizePlaneBuilder(NXOpen.Features.Feature.Null)   
            datum_object = workPart.Datums.FindObject(str(datum_feat.JournalIdentifier))
            resizePlaneBuilder.Plane.Value = datum_object

            resizePlaneBuilder.ResizeDuringUpdate = False
    
            corner_pts = [None] * 4 
            
            #multiplying by a scale factor just moves the planes further out
            # to adjust size, recalculate your corner points
            corner_pts[0] = NXOpen.Point3d(datum_corners[i][0][0],datum_corners[i][0][1],datum_corners[i][0][2])
            corner_pts[1] = NXOpen.Point3d(datum_corners[i][1][0],datum_corners[i][1][1],datum_corners[i][1][2])
            corner_pts[2] = NXOpen.Point3d(datum_corners[i][3][0],datum_corners[i][3][1],datum_corners[i][3][2])
            corner_pts[3] = NXOpen.Point3d(datum_corners[i][2][0],datum_corners[i][2][1],datum_corners[i][2][2])
            resizePlaneBuilder.SetCornerPoints(corner_pts)
    
            resizePlaneBuilder.Commit()
            resizePlaneBuilder.Destroy()

            datumPlaneBuilder.Destroy() 

RE: Can someone help me with this code snippet

(OP)
Hi

I followed the above example (found on the enternet) and I get an ERROR

can someone help whats wrong.

Thanks in advanced

CODE -->

Option Strict Off  
Imports System  
Imports System.IO  
Imports System.Windows.Forms  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpenUI  
Imports Microsoft.VisualBasic
Imports System.Environment

Imports NXOpen.Features

Module create_pattern_sketch_from_list_and_file_options

 Sub Main

  Dim theSession As Session = Session.GetSession()
  Dim workPart As Part = theSession.Parts.Work
  Dim displayPart As Part = theSession.Parts.Display
  Dim ufs As UFSession = UFSession.GetUFSession()

  Dim wcs_origin As Point3d = workPart.WCS.Origin
  Dim wcs_matrix3x3 As Matrix3x3 = workPart.WCS.CoordinateSystem.Orientation.Element
  Dim featdatum_tag As Tag
  Dim featdatum_obj As NXObject

  Dim xyplane As DatumPlane
  xyplane = workPart.Datums.CreateFixedDatumPlane(wcs_origin,wcs_matrix3x3)
  xyplane.SetName("_XY_")
  ufs.Modl.AskObjectFeat(xyplane.Tag,featdatum_tag)
  featdatum_obj = NXOpen.Utilities.NXObjectManager.Get(featdatum_tag)
  Dim xy_PlaneFeat As Features.DatumPlaneFeature = CType(featdatum_obj,Features.DatumPlaneFeature)
  xy_PlaneFeat.SetName("_XY_")

   Dim nullFeature As NXOpen.Features.Feature = Nothing
   Dim resizePlaneBuilder1 As Features.ResizePlaneBuilder
   resizePlaneBuilder1 = workPart.Features.CreateResizePlaneBuilder(nullFeature)
   resizePlaneBuilder.Plane.Value = xy_PlaneFeat
   resizePlaneBuilder1.ResizeDuringUpdate = False

   Dim corners As Point3d() = {New Point3d(-4.0, -4.0, 0.0),New Point3d(4.0, -4.0, 0.0), _
                                      New Point3d(4.0, 4.0, 0.0),New Point3d(-4.0, 4.0, 0.0)}

   resizePlaneBuilder1.SetCornerPoints(corners)
    
   resizePlaneBuilder1.Commit()
   resizePlaneBuilder1.Destroy()

 End Sub

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!


Resources