Cancel
Showing results for 
Search instead for 
Did you mean: 

getting component body in assembly

Valued Contributor
Valued Contributor

I have added two components in an assembly file. I can't get the component and its body. how do i replace findObject in the highlighted code to get component and its body. I want to get the circular edges of 2800 mm diameter for concentric constraint.

 

        AddComponentBuilder addComponentBuilder1 = workPart.AssemblyManager.CreateAddComponentBuilder();

        ComponentPositioner componentPositioner1 = workPart.ComponentAssembly.Positioner;

        componentPositioner1.ClearNetwork();

        componentPositioner1.BeginAssemblyConstraints();

        bool allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning;

        ComponentNetwork componentNetwork1 = (ComponentNetwork)componentPositioner1.EstablishNetwork();

        componentNetwork1.DisplayComponent = null;

        componentNetwork1.MoveObjectsState = true;

        addComponentBuilder1.SetComponentAnchor(null);

        addComponentBuilder1.SetInitialLocationType(AddComponentBuilder.LocationType.Snap);

        addComponentBuilder1.SetCount(1);

        addComponentBuilder1.SetScatterOption(true);

        addComponentBuilder1.ReferenceSet = "Use Model";

        addComponentBuilder1.Layer = -1;

        PartLoadStatus partLoadStatus1;
        BasePart basePart1 = theSession.Parts.OpenBase("C:\\Users\\Laptop User\\Desktop\\practice\\cylinder.prt", out partLoadStatus1);
        partLoadStatus1.Dispose();

        PartLoadStatus partLoadStatus2;
        BasePart basePart2 = theSession.Parts.OpenBase("C:\\Users\\Laptop User\\Desktop\\practice\\Dish End.prt", out partLoadStatus2);
        partLoadStatus2.Dispose();

        BasePart[] partstouse1 = new BasePart[2];
        Part part1 = (Part)basePart2;
        partstouse1[0] = part1;
        Part part2 = (Part)basePart1;
        partstouse1[1] = part2;
        addComponentBuilder1.SetPartsToAdd(partstouse1);

        Point3d origin1 = new Point3d(0, 0, 0.0);
        Vector3d vector1 = new Vector3d(1.0, 0.0, 0.0);
        Vector3d vector2 = new Vector3d(0.0, 1.0, 0.0);

        CartesianCoordinateSystem cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(origin1,vector1,vector2);

        Point point3 = workPart.Points.CreatePoint(origin1) ;

        addComponentBuilder1.SetInitialLocationAndOrientation(point3, cartesianCoordinateSystem1);

        NXObject[] movableObjects1 = new NXObject[2];
        Component component1 = (Component)workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT Dish End 1");        movableObjects1[0] = component1;
        Component component2 = (Component)workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT cylinder 1");
        movableObjects1[1] = component2;
        componentNetwork1.SetMovingGroup(movableObjects1);

        componentNetwork1.Solve();

        int nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1);

        componentPositioner1.EndAssemblyConstraints();

        NXObject nXObject1 = addComponentBuilder1.Commit();

        addComponentBuilder1.Destroy();

        componentPositioner1.PrimaryArrangement = null;

        ComponentPositioner componentPositioner2 = workPart.ComponentAssembly.Positioner;

        componentPositioner2.ClearNetwork();

        componentPositioner2.BeginAssemblyConstraints();

        bool allowInterpartPositioning2 = theSession.Preferences.Assemblies.InterpartPositioning;

        ComponentNetwork componentNetwork2 = (ComponentNetwork)componentPositioner2.EstablishNetwork();

        componentNetwork2.DisplayComponent = null;

        componentNetwork2.NetworkArrangementsMode = ComponentNetwork.ArrangementsMode.Existing;

        componentNetwork2.MoveObjectsState = true;

        Constraint constraint1 = componentPositioner2.CreateConstraint(true);

        ComponentConstraint componentConstraint1 = (ComponentConstraint)constraint1;
        componentConstraint1.ConstraintType = Constraint.Type.Concentric;

        Edge edge1 = (Edge)component1.FindObject("PROTO#.Features|REVOLVED(1)|EDGE * 2 * 3 {(1212.4355652982144,0,-699.9999999999998)(0,0,1400.0000000000002)(-1212.435565298214,0,-700.0000000000007) REVOLVED(1)}");
        ConstraintReference constraintReference1 = componentConstraint1.CreateConstraintReference(component1, edge1, false, false, false);

        Component component3 = (Component)nXObject1;
        Edge edge2 = (Edge)component3.FindObject("PROTO#.Features|CYLINDER(1)|EDGE * 2 * 3 {(-699.9999999999998,0,-1212.4355652982144)(1400.0000000000002,0,0)(-700.0000000000007,0,1212.435565298214) CYLINDER(1)}");
        ConstraintReference constraintReference2 = componentConstraint1.CreateConstraintReference(component3, edge2, false, false, false);

        constraintReference2.SetFixHint(true);

        componentNetwork2.Solve();

        int nErrs6 = theSession.UpdateManager.AddToDeleteList(componentNetwork2);

        componentPositioner2.DeleteNonPersistentConstraints();

        componentPositioner2.EndAssemblyConstraints();

        workPart.ModelingViews.WorkView.Orient(View.Canned.Trimetric, View.ScaleAdjustment.Fit);

 

1 REPLY 1

Re: getting component body in assembly

Valued Contributor
Valued Contributor

found solution !!!

 

// to get component
Component component1=addcomponentbuilder.commit();

// to get body from component

Part comProto=(Part) component1.Prototype();
foreach(Body protobody in comProto.Bodies)
{
 protobody.Highlight();
}

 

Now i can iterate required edges and faces.