14 Replies Latest reply on May 7, 2013 5:10 AM by Matthias Burkhart

    SolidWorks API. Assign Material to selected Part

    Matthias Burkhart

      Hello,

       

      i plan to write an add in to assign a material to a selected part.

      so far I can set material to the whole PartDoc ( see c# code)

       

         var myModel = (ModelDoc2)mSWApplication.ActiveDoc;

            

                  if (myModel != null)

                  {

                      var myPart = (PartDoc)myModel;

                      if (myPart != null)

                      {

                          var myMatVisProps = myPart.GetMaterialVisualProperties();

                          if(materialTreeView.SelectedNode!=null)

                              myPart.SetMaterialPropertyName2("Standard", "C:/ProgramData/SolidWorks/SolidWorks 2012/Benutzerdefinierte Materialien/MyBiblio.sldmat", materialTreeView.SelectedNode.Text);

                             

                          else

                              MessageBox.Show("No Material found");               

                      }

                  }

       

      Now I try to assign the material only to the selected part (by the user) but I dont know how to get the selected part by the api.

      Can somebody help me?

       

      Thank you