Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Can someone help me with this code snippet

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
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()
 
Replies continue below

Recommended for you

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor