3 Replies Latest reply on Jul 1, 2015 2:33 PM by Todd Carpenter

    SelectByID2 Name

    Todd Carpenter

      I have an add-in I'm working on trying to get the names within an assembly to edit a dimension.  When I record a macro, I can get the dimensions name, but I want my add-in to allow the user to select the dimension and then display it to the user.  Here's a portion of the recorded macro:


      boolstatus = swDoc.Extension.SelectByID2("D1@STOCK@Base Cylinder-1@L_S/Rear Cover-1@Base Cylinder", "DIMENSION", -0.13610586623579712, 0.064932066534194435, 0.047917612974635 false, 0, null, 0);

      What I can't seem to figure out is how to get the selected object to return that entire name.


      I've tried GetNameForSelection, FullName and just name and all I can get is "D1@STOCK"


      Anyone know how to do this?



        • Re: SelectByID2 Name
          Keith Rice

          I want my add-in to allow the user to select the dimension and then display it to the user


          If the user has already selected the dimension, why do you need to select it using IModelDocExtension::SelectByID2? Or maybe you mean something different by "display it to user". It's not clear what you mean by this.


          Anyway, the exact string for selecting a dimension in an assembly with IModelDocExtension::SelectByID2 is:


          <string returned by IDisplayDimension::GetNameForSelection>@<string returned by IComponent2::GetSelectByIDString>



          SolidWorks API Training

            • Re: SelectByID2 Name
              Todd Carpenter

              Hi Keith,


              Thanks for getting back to me, sorry, I wasn't very clear.  We do 3D Automation where users can write rules to drive 3D Models, and the rules writer needs to know the correct dimension name for the rules to interact with correct dimension.  So I'm trying to write an add-in to help them collect that information.  So when I say I want the user to select the dimension, and then display the name to the user - I see my brain got ahead of my lousy typing...


              So I want them to select the dimension and  a dialog box will display the dimension name (from above): D1@STOCK@Base Cylinder-1@L_S/Rear Cover-1@Base Cylinder


              This way, they can just copy an paste into the rule. 


              However, when I try to get the component of the dimension - it always fails with this error:


              Unable to cast COM object of type 'System.__ComObject' to interface type 'SolidWorks.Interop.sldworks.IEntity'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{83A33D65-27C5-11CE-BFD4-00400513BB57}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).


              Not sure what I'm missing - here's my code:


                          IDimension iDim2 = (IDimension)iDim.GetDimension2(0);

                          IEntity iEnt = (IEntity)swSelMgr.GetSelectedObject6(1, -1);

                          Debug.Print("iEnt is: " + iEnt.GetType());

                          IComponent2 iComp = (IComponent2)iEnt.GetComponent();