3 Replies Latest reply on Feb 7, 2013 2:49 AM by Artem Taturevych

    How do I use IDrawingDoc::CreateRelativeView ?

    Joshua Grant

      This question has been asked before, but unfortunately had no responses: https://forum.solidworks.com/message/23031

       

      The CreateRelativeView method is documented here

      http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IDrawingDoc~CreateRelativeView.html

       

      How do I specify the 2 faces required for the relative view? Trying to use the method now does nothing and returns a null object.

        • Re: How do I use IDrawingDoc::CreateRelativeView ?
          Artem Taturevych

          The preconditions to make this method work is to have two selections for the part you like to create view for with the marks 1 and 2 for first and second reference correspondingly.

          I have created sample macro for you which selects two faces by name (RMB on face and Face Properties. But you can get the face with any other manner) and inserts relative view.

           

          For test:

           

          1) Extract the files I have attached

          2) Open the macro in edit mode and specify the path to the part file I have attached

          3) Open/Create the drawing and run the macro. The relative view is created.

          __________________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: How do I use IDrawingDoc::CreateRelativeView ?
              Joshua Grant

              Artem, I can't thank you enough for this! How did you work this out? I couldn't find this documented anywhere.

               

              For anyone else struggling to use this method, the solution is as follows (C#):

               

              1. Activate the part model using ISldWorks::ActivateDoc3:

                solidWorks.ActivateDoc3(modelPath, false, 0, 0);

              2. Select the two faces using the IEntity::SelectByMark method, one with a mark of 1, and the other with a mark of 2. Note: if you have IFace2 objects, they can be cast to IEntity to access this select method:

                backFaceEntity.SelectByMark(false, 1);
                topFaceEntity.SelectByMark(true, 2);

              3. Activate the drawing document:

                solidWorks.ActivateDoc3(drawingModelDoc.GetTitle(), false, 0, 0);

              4. Create the relative view using IDrawingDoc::CreateRelativeView:

                int back = (int)swRelativeViewCreationDirection_e.swRelativeViewCreationDirection_BACK;
                int top = (int)swRelativeViewCreationDirection_e.swRelativeViewCreationDirection_TOP;
                IView drawingView = drawing.CreateRelativeView(modelPath, 0, 0, back, top);

              5. Limit the drawing view to a specific body via the IView::Bodies property

                drawingView.Bodies = new IBody2[] { bodyFeature };