Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Connect objects associative

Status
Not open for further replies.

YviKyvi

Mechanical
Feb 3, 2020
12
Hey guys,
I build a Bounding Box depending on the user's input. When I do it in the NX GUI the toolingbox has the selected parent objects in the information window, but with the one i created in NX Open, there are no parents visible.
Do you know how I can fix that? I am working with the Blocksytler to let the user select the objects. (see code snippet below)

After that i want to create a CSYS that's in the middle of the bounding box. And that is associatively connected. Do oyu know how?

The aim is to change or move the body, on which the bounding box is built on and the bounding box should change and move with it too, and also the CSYS.

Code:
Public Function CreateBoundingCylinder(ByVal selectionObj As BlockStyler.SelectObject, ByVal vectorAxis As BlockStyler.SpecifyVector) As Features.ToolingBox
        workPart = theSession.Parts.Work

        Dim nullNXOpen_Features_ToolingBox As NXOpen.Features.ToolingBox = Nothing
        Dim toolingBoxBuilder1 As NXOpen.Features.ToolingBoxBuilder = Nothing
        toolingBoxBuilder1 = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(nullNXOpen_Features_ToolingBox)

        toolingBoxBuilder1.Type = NXOpen.Features.ToolingBoxBuilder.Types.BoundedCylinder 'weitere Auswahlmöglichkeiten: CenterAndLengths, BoundedBlock

        Dim selectedObjects As NXOpen.TaggedObject() = selectionObj.GetSelectedObjects
        Dim numObjects As Integer = selectedObjects.Length - 1

        'Alle Parts müssen geladen werden, dass die Toolingbox erstellt werdne kann
        For j As Integer = 0 To numObjects
            Dim theObject As NXOpen.NXObject = selectedObjects(j)
            Dim thePart As Part = theObject.Prototype.OwningPart
            thePart.LoadThisPartFully()
        Next

        Dim bodyDR1(numObjects) As NXOpen.BodyDumbRule
        Dim bodyDumbRule1 As NXOpen.BodyDumbRule = Nothing
        Dim bodies1(0) As NXOpen.Body

        Dim faceDR1(numObjects) As NXOpen.FaceDumbRule
        Dim faceDumbRule1 As NXOpen.FaceDumbRule = Nothing
        Dim faces1(0) As NXOpen.Face

        Dim edgeDR1(numObjects) As NXOpen.EdgeDumbRule
        Dim edgeDumbRule1 As NXOpen.EdgeDumbRule = Nothing
        Dim edges1(0) As NXOpen.Edge

        Dim rules1(numObjects) As NXOpen.SelectionIntentRule

        For k As Integer = 0 To numObjects

            If selectedObjects(k).GetType.ToString = "NXOpen.Body" Then 'Body
                Dim theBody As NXOpen.Body = CType(selectedObjects(k), NXOpen.Body)

                bodies1(0) = theBody
                rules1(k) = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1)

            ElseIf selectedObjects(k).GetType.ToString = "NXOpen.Face" Then ' Face
                Dim theFace As NXOpen.Face = CType(selectedObjects(k), NXOpen.Face)

                faces1(0) = theFace
                rules1(k) = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)

            Else 'Edge
                Dim theEdge As NXOpen.Edge = CType(selectedObjects(k), NXOpen.Edge)
                edges1(0) = theEdge
                rules1(k) = workPart.ScRuleFactory.CreateRuleEdgeDumb(edges1)

            End If

        Next k

        Dim origin1 As NXOpen.Point3d = Nothing 'der Punkt ist nicht wichtig für die toolingBox Erzeugung, muss aber für die direction angelegt werden
        Dim vector1 As NXOpen.Vector3d = vectorAxis.Vector 'wird auch im BlockStyler ausgewählt
        Dim direction1 As NXOpen.Direction = Nothing
        direction1 = workPart.Directions.CreateDirection(origin1, vector1, NXOpen.SmartObject.UpdateOption.WithinModeling)

        toolingBoxBuilder1.AxisVector = direction1

        Dim unit1 As NXOpen.Unit = Nothing
        unit1 = toolingBoxBuilder1.ZValue.Units

        Dim expression1 As NXOpen.Expression = Nothing
        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

        Dim scCollector1 As NXOpen.ScCollector = Nothing
        scCollector1 = toolingBoxBuilder1.BoundedObject

        scCollector1.ReplaceRules(rules1, False)

        Dim selections1(0) As NXOpen.NXObject

        If selectedObjects(numObjects).GetType.ToString = "NXOpen.Body" Then 'Body
            Dim lastBody As NXOpen.Body = CType(selectedObjects(numObjects), NXOpen.Body)
            selections1(0) = lastBody

        ElseIf selectedObjects(numObjects).GetType.ToString = "NXOpen.Face" Then ' Face
            Dim lastFace As NXOpen.Face = CType(selectedObjects(numObjects), NXOpen.Face)
            selections1(0) = lastFace

        Else 'Edge
            Dim lastEdge As NXOpen.Edge = CType(selectedObjects(numObjects), NXOpen.Edge)
            selections1(0) = lastEdge
        End If

        Dim deselections1(-1) As NXOpen.NXObject
        toolingBoxBuilder1.SetSelectedOccurrences(selections1, deselections1)

        Dim selectNXObjectList1 As NXOpen.SelectNXObjectList = Nothing
        selectNXObjectList1 = toolingBoxBuilder1.FacetBodies

        Dim objects1(-1) As NXOpen.NXObject
        Dim added1 As Boolean = Nothing
        added1 = selectNXObjectList1.Add(objects1)


        toolingBoxBuilder1.CalculateBoxSize()
        toolingBoxBuilder1.ShowDimension() = True

        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = toolingBoxBuilder1.Commit()

        Dim expression2 As NXOpen.Expression = toolingBoxBuilder1.OffsetPositiveZ

        'work with the box that's created by the toolingboxBuilder
        boundedBody = toolingBoxBuilder1.GetObject

        'listOfBoundedFaces = boundedBody.GetFaces() 'returns the faces created by the feature

        Dim toolingBoxFeature As NXOpen.Features.BodyFeature = CType(boundedBody, NXOpen.Features.BodyFeature)
        Dim toolingBoxBodies() As NXOpen.Body = toolingBoxFeature.GetBodies() 'sammelt die Körper, die durch das Feature erzeugt wurden. Hier nur einer.

        'DimensionOutput(toolingBoxBodies(0))

        'legt eine Änderung der Darstellung eines DisplayableObjects an
        Dim displayModification1 As NXOpen.DisplayModification = Nothing
        displayModification1 = theSession.DisplayManager.NewDisplayModification()

        displayModification1.ApplyToAllFaces = True
        displayModification1.ApplyToOwningParts = False
        displayModification1.NewTranslucency = 40 '0 entspricht komplett undurchsichtig und 100 entspricht komplett durchsichtig

        Dim obj1(0) As NXOpen.DisplayableObject 'hier wird das Objekt angelegt, auf das die Änderung angewandt werden soll
        Dim boxBody As NXOpen.Body = CType(toolingBoxBodies(0), Body)

        obj1(0) = boxBody
        displayModification1.Apply(obj1)
        displayModification1.Dispose()
        toolingBoxBuilder1.Destroy()

        workPart.Expressions.Delete(expression1)
    End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor