IBRepFeaturePrism_DG exception

Technical discussions
Post Reply
Rene20
Posts: 1
Joined: Thu Mar 19, 2020 1:29 am

IBRepFeaturePrism_DG exception

Post by Rene20 »

Hello
I am having a problem with IBRepFeaturePrism_DG. I need to 'drill' a semi-circular hole in a flat face of a solid. I got it working by copying code from Solids example. It uses IBRepFeaturePrism_DG.Perform(length). I need to make it more generic. Perform1(IBRepShape_DG shapeUntil) sounds close. I need it to cut through the whole solid. But I am getting an exception on a call to Perform1().
I would be grateful for a bit of help.
Thanks

Prashant Kande
Posts: 121
Joined: Mon Apr 04, 2016 4:55 am

Re: IBRepFeaturePrism_DG exception

Post by Prashant Kande »

Hi Rene20
We intend to add bunch of tests to the C# samples code where we do basic calls to all methods. It should be out in a few weeks. Here is the related modification of Solids sample:

Code: Select all

        private IModel_DG m_iModel;
        private IObjectGenerator_DG m_iGener;
        private IStdShape_DG m_iStdShape;
        private IBRepBuilder_DG m_iBuilder;
        private IView_DG m_iView;
        
       private void BuildPrismAdd(bool extrusion)
        {
            // Extrusion
            IEntity_DG iEntityBox = m_iStdShape.Box(400, 250, 300);

            IBRepGeometry_DG iBrepGeom = iEntityBox.GetGeometry() as IBRepGeometry_DG;

            IBRepShape_DG iShape = iBrepGeom.GetShape();

            IBRepSolid_DG iSolid = iShape as IBRepSolid_DG;
            IBRepShell_DG iShell = iSolid.GetOuterShell(false);

            // Get nicely oriented face with normal (0,0,1) or (1,0,0) 
            IBRepFace_DG iFace = iShell.GetFace(extrusion ? 5 : 1);

            IUVSurface_DG surface = iFace.GetSurface();

            IBRepFace_DG iFacePrism = m_iBuilder.CreateFace6(surface);

            //BuildWire(iFacePrism, extrusion);
            IBRepWire_DG wire = iFacePrism.AddNewWire();

            // Edge down along front vertical right box edge
            IBRepVertex_DG iVtx0 = m_iGener.Create("BRepVertex_DG") as IBRepVertex_DG;
            iVtx0.SetPosition(400, 200, 300);
            wire.AddVertex(iVtx0);
            IBRepVertex_DG iVtx1 = m_iGener.Create("BRepVertex_DG") as IBRepVertex_DG;
            iVtx1.SetPosition(400, 100, 300);
            IBRepEdge_DG edge0 = wire.AddVertex(iVtx1);
            IBRepVertex_DG iVtx2 = m_iGener.Create("BRepVertex_DG") as IBRepVertex_DG;
            iVtx2.SetPosition(400, 100, 200);
            wire.AddVertex(iVtx2);
            wire.CloseWire();

            IBRepFeaturePrism_DG iMakePrism = m_iGener.Create("BRepFeaturePrism_DG") as IBRepFeaturePrism_DG;

            IBRepShape_DG iShapePrism = iFacePrism as IBRepShape_DG;

            VectDg normal = GetSurfaceNormal(surface);	//GetFaceNormal(iFace, normal);	should work too

            if (!extrusion)
                normal.SwapDirection();

            iMakePrism.Init(iBrepGeom, iShapePrism, iFace, normal, extrusion);

            IBRepFace_DG iFaceZMax = iShell.GetFace(5);
            VectDg nZ = iFaceZMax.GetNormalAtRatios(new Dg_2D(0.5, 0.5));

            iMakePrism.Add(edge0, iFaceZMax);

            int idTest = 6;

            if (idTest == 0)
            {
                iMakePrism.Perform(200);
            }
            else if (idTest == 1)
            {

                IBRepFace_DG iFaceZMin = iShell.GetFace(0);
                VectDg n0 = iFaceZMin.GetNormalAtRatios(new Dg_2D(0.5, 0.5));

                iMakePrism.Perform1(iFaceZMin as IBRepShape_DG);
            }
            else if (idTest == 2)
            {

                IBRepFace_DG iFaceXMin = iShell.GetFace(0);
                VectDg n0 = iFaceXMin.GetNormalAtRatios(new Dg_2D(0.5, 0.5));	// Check the correct face in debugger
                IBRepFace_DG iFaceXMax = iShell.GetFace(1);
                VectDg n1 = iFaceXMax.GetNormalAtRatios(new Dg_2D(0.5, 0.5));

                iMakePrism.Perform2(iFaceXMax as IBRepShape_DG, iFaceXMin as IBRepShape_DG);
            }
            else if (idTest == 3)
            {
                iMakePrism.PerformUntilEnd();
            }
            else if (idTest == 4)
            {
                IBRepFace_DG iFaceZMin = iShell.GetFace(0);
                iMakePrism.PerformFromEnd(iFaceZMin as IBRepShape_DG);
            }
            else if (idTest == 5)
            {
                iMakePrism.PerformThruAll();
            }
            else if (idTest == 6)
            {
                IBRepFace_DG iFaceZMin = iShell.GetFace(0);
                iMakePrism.PerformUntilHeight(iFaceZMin as IBRepShape_DG, 200);
            }

            m_iModel.AddEntity(iEntityBox);
        }
Try each case. idTest=1 or 5 sounds like what you need.
Cheers

Prashant Kande
Posts: 121
Joined: Mon Apr 04, 2016 4:55 am

Re: IBRepFeaturePrism_DG exception

Post by Prashant Kande »

Rene,
We have added the tests I mentioned in today's 5002 update. See Samples\NET\C#\Tests\ in the installation directory.
They are "as it is" not very tidy. Commented out staff mostly works also. These are basic manual tests to check calls to all methods not used in samples go where they are supposed to an do basic work.
The code should be good for searching for an example of all method calls.
Regards

Post Reply