Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 784

Select all faces in an assembly

$
0
0

I'm trying to generate code which will automatically make a bounding body around an object. I have it working for a part by modifying an NX journal of when I did it manually. However, I'm trying to get the code to work on an assembly, but am running into issues. On my previous code, it gets the rules by accessing the features of the work part (which is the Part class).

What should I do to have the rules select a whole assembly?

Attached is my current code for creating the bounding box around a single part:

importmathimport NXOpen
import NXOpen.UF#import NXOpen.UIimport NXOpen.Featuresimport NXOpen.GeometricUtilitiesdef main() : 
 
    theSession  = NXOpen.Session.GetSession()
    theUFSession = NXOpen.UF.UFSession.GetUFSession()
    workPart = theSession.Parts.Work
    displayPart = theSession.Parts.Display
    theUI = NXOpen.UI.GetUI()
    myMsgBox = theUI.NXMessageBox 
    # ----------------------------------------------#   Menu: Insert->Offset/Scale->Bounding Body...# ----------------------------------------------
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible,"Start") 
    toolingBoxBuilder1 = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(NXOpen.Features.ToolingBox.Null) 
    toolingBoxBuilder1.Type= NXOpen.Features.ToolingBoxBuilder.Types.BoundedBlock 
    toolingBoxBuilder1.XValue.SetFormula("10") 
    toolingBoxBuilder1.YValue.SetFormula("10") 
    toolingBoxBuilder1.ZValue.SetFormula("10") 
    toolingBoxBuilder1.OffsetPositiveX.SetFormula("0.5") 
    toolingBoxBuilder1.OffsetNegativeX.SetFormula("0.5") 
    toolingBoxBuilder1.OffsetPositiveY.SetFormula("0.5") 
    toolingBoxBuilder1.OffsetNegativeY.SetFormula("0.5") 
    toolingBoxBuilder1.OffsetPositiveZ.SetFormula("0.5") 
    toolingBoxBuilder1.OffsetNegativeZ.SetFormula("0.5") 
    toolingBoxBuilder1.RadialOffset.SetFormula("0.5") 
    toolingBoxBuilder1.Clearance.SetFormula("0.5") 
    theSession.SetUndoMarkName(markId1,"Bounding Body Dialog") 
    matrix1 = NXOpen.Matrix3x3() 
    matrix1.Xx=1.0
    matrix1.Xy=0.0
    matrix1.Xz=0.0
    matrix1.Yx=0.0
    matrix1.Yy=1.0
    matrix1.Yz=0.0
    matrix1.Zx=0.0
    matrix1.Zy=0.0
    matrix1.Zz=1.0
    position1 = NXOpen.Point3d(0.0,0.0,0.0)
    toolingBoxBuilder1.SetBoxMatrixAndPosition(matrix1, position1) 
 
    #selecting the object
    features1 =[NXOpen.Features.Feature.Null] * 1#extrude1 = workPart.Features.FindObject("EXTRUDE(1)")#extrude1 = workPart.Features.GetFeatures()#features1[0] = extrude1[0]
    features1 = workPart.Features.GetFeatures()
    bodyFeatureRule1 = workPart.ScRuleFactory.CreateRuleBodyFeature(features1,True) 
    scCollector1 = toolingBoxBuilder1.BoundedObject 
    rules1 =[None] * 1 
    rules1[0]= bodyFeatureRule1
    scCollector1.ReplaceRules(rules1,False) 
    selections1 =[NXOpen.NXObject.Null] * 1#selections1[0] = extrude1[0]
    selections1=features1
    print('hi')
    deselections1 =[]
    toolingBoxBuilder1.SetSelectedOccurrences(selections1, deselections1) 
    selectNXObjectList1 = toolingBoxBuilder1.FacetBodies 
    objects1 =[]
    added1 = selectNXObjectList1.Add(objects1) 
    toolingBoxBuilder1.CalculateBoxSize() 
    csysorigin1 = NXOpen.Point3d(0.0,0.0,5.0)
    toolingBoxBuilder1.BoxPosition= csysorigin1
 
    markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible,"Test") 
    theSession.DeleteUndoMark(markId2,None) 
    markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible,"Test") 
    nXObject1 = toolingBoxBuilder1.Commit()#myMsgBox.Show("Test", NXOpen.NXMessageBox.DialogType.Information,nXObject1.JournalIdentifier)
    boundingboxname = nXObject1.JournalIdentifier 
    theSession.DeleteUndoMark(markId3,None) 
    theSession.SetUndoMarkName(markId1,"Test") 
    expression1 = toolingBoxBuilder1.OffsetPositiveZ
    toolingBoxBuilder1.Destroy() 
    theSession.CleanUpFacetedFacesAndEdges()

Viewing all articles
Browse latest Browse all 784

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>