10 Replies Latest reply on May 5, 2016 6:41 AM by Suresh Vijayan

    i Can't able to select the plane of a part  for matting

    Suresh Vijayan

      Hi All,

       

      I  cant able to select the plane using selectBYID2  for mating,Used code is below Kindly help me to solve this problem

       

      ######################################################################################################################

       

       

              Dim TemplateName As String = "C:\Documents and Settings\All Users\Application Data\SolidWorks\SolidWorks 2012\templates\Assembly.asmdot"

              Dim swAssy As AssemblyDoc

              Dim ShaftFilePath As String = "C:\Documents and Settings\3dcad0723\Desktop\New Folder\EditedShaft.SLDPRT"

              Dim CouplingFilePath As String = "C:\Documents and Settings\3dcad0723\Desktop\New Folder\EditedCoupling.SLDPRT"

              'Dim DocExt As ModelDocExtension

       

       

              'Opening the parts Before Assembly

              SwApp.OpenDoc6(ShaftFilePath, 1, 0, "", iErrors, iWarnings)

              SwApp.OpenDoc6(CouplingFilePath, 1, 0, "", iErrors, iWarnings)

              'Opening the New Assembly

              swModel = SwApp.NewDocument(TemplateName, 0, 0, 0)

              swAssy = SwApp.ActiveDoc

       

       

       

       

              'Adding Component (Shaft part)

              swAssy.AddComponent(ShaftFilePath, 0, 0, 0)

       

       

              'Adding Component (Coupling Part) Three Times

              swAssy.AddComponent(CouplingFilePath, 0.2, 0, 0)

              swAssy.AddComponent(CouplingFilePath, 0.5, 0.2, 0)

              swAssy.AddComponent(CouplingFilePath, 0.8, 0.4, 0)

       

       

       

       

              'Mating Components

              swModel.ClearSelection2(True)

              'Selecting Planes Of all Components

              swModel.Extension.SelectByID2("Plane3@EditedShaft-1@Assem1", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

              swModel.Extension.SelectByID2("Plane2@EditedCoupling-3@Assem1", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

       

       

              '.Extension.SelectByID2("Plane3@EditedShaft-1@Assem1", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

              'boolstatus = Part.Extension.SelectByID2("Plane2@EditedCoupling-3@Assem1", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

       

       

              'AddMating

              swAssy.AddMate3(0, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, iErrors)

       

      ##########################################################################################################################################

       

      Thanks in Advance

       

      SureshKumar

        • Re: i Can't able to select the plane of a part  for matting
          Glenn Schroeder

          I believe you got this in the wrong section of the Forum.  I'd suggest you move it to the API section (there's a "Move" link at to right) instead.  The people that can help will be more likely to see it there.

           

          • Re: i Can't able to select the plane of a part  for matting
            Artem Taturevych

            You are trying to select the entity by the hardcoded name.

             

            So your component should be named EditedCoupling-3 (i.e. 3rd instance) and the top assembly name should be Assem1 which I assume may not be the case depending of how many assemblies you have already opened in this session. You need to use different techniques to select the plane. Here is the sample which may help:

             

            Dim shaftComp as SldWorks.Component2

            Dim couplingComp as SldWorks.Component2

             

            Set shaftComp  = swAssy.AddComponent(ShaftFilePath, 0, 0, 0)

             

            swAssy.AddComponent(CouplingFilePath, 0.2, 0, 0)

            swAssy.AddComponent(CouplingFilePath, 0.5, 0.2, 0)

            Set couplingComp  = swAssy.AddComponent(CouplingFilePath, 0.8, 0.4, 0)

              

            'Mating Components

            swModel.ClearSelection2(True)

             

            'Selecting Planes Of all Components

            shaftComp.FeatureByName("Plane3").Select2 False, 0

            shaftComp.FeatureByName("Plane2").Select2 True, 0

             

            swModel.Extension.SelectByID2("Plane3@EditedShaft-1@Assem1", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

            swModel.Extension.SelectByID2("Plane2@EditedCoupling-3@Assem1", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

             

            Thanks,Artem

              • Re: i Can't able to select the plane of a part  for matting
                Suresh Vijayan

                Hi Artem,

                 

                thanks for quick support

                 

                I used your code in my project but it shows Errors on Declaring the Component2..

                For Your information im working in VB.net,i am new to VB.net and also i m not having any idea about other languages,

                So Kindly Guide me to solve this Issue

                i have attached  below the image of what errors rising while i implementing your code

                 

                ErrorScreenShot.bmp

                #########################################################################################################

                        Dim TemplateName As String = "C:\Documents and Settings\All Users\Application Data\SolidWorks\SolidWorks 2012\templates\Assembly.asmdot"

                        Dim swAssy As AssemblyDoc

                        Dim ShaftFilePath As String = "C:\Documents and Settings\3dcad0723\Desktop\New Folder\EditedShaft.SLDPRT"

                        Dim CouplingFilePath As String = "C:\Documents and Settings\3dcad0723\Desktop\New Folder\EditedCoupling.SLDPRT"

                        Dim shaftComp As Component2

                        Dim CouplingComp As Component2

                        'Dim DocExt As ModelDocExtension

                 

                        'Opening the New Assembly

                        swModel = SwApp.NewDocument(TemplateName, 0, 0, 0)

                        swModel.SaveAs("AssemblySimple.sldasm")

                 

                        'Opening the parts Before Assembly

                        SwApp.OpenDoc6(ShaftFilePath, 1, 0, "", iErrors, iWarnings)

                        SwApp.OpenDoc6(CouplingFilePath, 1, 0, "", iErrors, iWarnings)

                 

                        swAssy = SwApp.ActivateDoc("AssemblySimple.sldasm")

                        swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayOrigins, True)

                 

                        'Adding Component (Shaft part)

                        shaftComp = swAssy.AddComponent(ShaftFilePath, 0, 0, 0)

                 

                        'Adding Component (Coupling Part) Three Times

                        CouplingComp = swAssy.AddComponent(CouplingFilePath, 0.2, 0, 0)

                        CouplingComp = swAssy.AddComponent(CouplingFilePath, 0.5, 0.2, 0)

                        CouplingComp = swAssy.AddComponent(CouplingFilePath, 0.8, 0.4, 0)

                        swModel.ClearSelection2(True)

                 

                        'Selecting Planes Of all Components

                 

                        shaftComp.FeatureByName("Plane3").Select2(False, 0)

                        CouplingComp.FeatureByName("Plane2").Select2(True, 0)

                 

                        'AddMating

                        swAssy.AddMate3(0, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, iErrors)

                ############################################################################################################

                 

                 

                Thanks & Regards

                Suresh