Adding a workplane to a Part programatically

Top  Previous  Next

You need to get the list of workplanes and add to that. Here are the standard workplanes which are contained in all parts:



As an example here I add a workplane which is offset from the YZ Plane by 2.3. Here is what we will do graphicaly:





   // Get the list of workplanes in the part...

   CComPtr<WorkPlanes> pWorkPlanesList ;

   pPartCompDef->get_WorkPlanes (&pWorkPlanesList) ;

   if (FAILED(hRes) || (pWorkPlanesList == nullptr)) {

       return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not get work planes list") ;


   TRACE (L"There are %d workplanes\n",pWorkPlanesList->Count) ;


   // Get the YZ Plane work plane (Index 1)...

   CComPtr<WorkPlane> pWorkPlane ;

   hRes = pWorkPlanesList->get_Item (CComVariant(1),&pWorkPlane) ;

   if (FAILED(hRes) || (pWorkPlane == nullptr)) {

       return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not get standard workplane") ;



   // Just for fun print the name of the 1st standard workplane...

   CComBSTR bstrWrkplaneName ;

   pWorkPlane->get_Name(&bstrWrkplaneName) ;

   TRACE (L"pWorkPlane(1) is called <%s>\n",bstrWrkplaneName) ;


   // Create a workplane parallel to the standard YZ Plane...

   CComPtr<WorkPlane> pOffsetWorkPlane ;

   hRes = pWorkPlanesList->AddByPlaneAndOffset (_variant_t((IDispatch *)pWorkPlane), // "starting" plane

                                                CComVariant(2.3),    // how much to offset

                                                VARIANT_FALSE,       // See note below

                                                &pOffsetWorkPlane) ; // Return value

   if (FAILED(hRes) || (pOffsetWorkPlane == nullptr)) {

       return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not add workplane with offset") ;



   // For fun, again, get the name of the new workplane...

   hRes = pOffsetWorkPlane->get_Name (&bstrWrkplaneName) ;

   if (FAILED(hRes)) {

       return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not get name of offset workplane") ;


   TRACE (L"Offset WorkPlane was called <%s>\n",bstrWrkplaneName) ;


   // Change the name of the workplane...

   pOffsetWorkPlane->put_Name (CComBSTR (L"Parallel_Smith")) ;



Note: This line in the call to AddByPlaneAndOffset...


      VARIANT_FALSE,       // See note below


...basically sets whether the plane is visible to the user. The parameter is called Construction and if true then is just for the program to construct things and will not be visible to the user.




Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)