10 Replies Latest reply on Feb 6, 2013 5:49 PM by Aj Jones

    API Will Not Mate Components (It Did Before Until Today)

    Aj Jones

      I have an API in VB.Net.  It has been running fine, and randomly today it doesn't work correctly.  The components all insert into the assembly it is designed to make with no errors, but they do not all mate correctly.

       

      The only thing that has changed with the the components (parts and assemblies) is that I moved then to another folder on my desktop.

      The program hasn't changed at all.

       

      All the program does is inserts the assembly, mates the components to another component, repeat.

      All of the assemblies get inserted fine, so the directory path is correct for all of them.

       

      I have an subassembly (970402513) that is inserted with a part(970278432) within it that mates its planes to another subassembly in the overall assembly, and it does not when the code runs.  I opened up the subassembly, and the part(970278432) does not have a "+" next to it for some reason.  I don't know if this is the problem, but the program selects planes from this part, and they are not showing when I open the subassembly.

       

      Pic.jpg

       

      No references are broken for any of the part or anything, so I am lost as to what is going on.

       

      Thanks!

        • Re: API Will Not Mate Components (It Did Before Until Today)
          Keith Rice

          AJ,

           

          IAssemblyDoc::AddMate3 returns the error in the last argument. Find out what that is and then look in swAddMateError_e enumeration.

           

          Anyway, your components shouldn't have a + next to them because this would mean they are over-defined, and that would prevent adding additional mates. (You seemed to be implying that 970278432 ought to have a + next to it.) Here are the symbols:

           

          ( - ) under defined

          ( + ) over defined

          ( f ) fixed

          ( ? ) not solved

           

          Your components need to be under-defined if you want to successfully add mates.

           

          Keith

          Video Tutorials for the SolidWorks API

            • Re: API Will Not Mate Components (It Did Before Until Today)
              Aj Jones

              Keith,

               

              Thanks for the quick reply!  The error I am getting is a "0" Unknown error after the AddMate3 is done.

               

              The "+" I was reffering to was not the mate symbols, but the actual drop down of the part that should be showing the planes

               

              1-29-2013 3-33-42 PM.jpg

               

              Thanks!

              • Re: API Will Not Mate Components (It Did Before Until Today)
                Aj Jones

                It must be something to do with my computer. I published the program on our network and got another associate to install it and run it and it worked perfectly.  I've restarted my computer and it still messes up. 

                  • Re: API Will Not Mate Components (It Did Before Until Today)
                    Artem Taturevych

                    How do you find/select the plane of component? If you are using the model doc of underlying component to find the plane then you should convert the pointer to assembly context: Component2::GetCorrespondingEntity.

                     

                    Make sure that your planes preselected at the assembly level. Note, if select method returns 'True' it may mean that the feature is selected in model context not assembly context.

                    __________________________

                    Regards,

                    Artem Taturevych

                    Application Engineer at Intercad

                    http://intercad.com.au/

                    Tel: +61 2 9454 4444

                      • Re: API Will Not Mate Components (It Did Before Until Today)
                        Aj Jones

                        Here is the code for this section.  I have an overall assembly already with some sub assemblies within it.  Here there is another subassembly inserted, and one of the parts within this subassembly mates to a part within another subassembly.  The right planes from both mate up.  I don't know why it is working on other computers but not mine now, when it did the other day.

                         

                        'OPENING THE COMPONENT ASSEMBLY

                        swApp.OpenDoc6("Component.SLDASM", 2, 0, "", errors, warnings)

                        'REACTIVATING THE OVERALL ASSEMBLY

                        swModel = swApp.ActivateDoc2(AssemblyTitle, True, errors)

                        swAssy = swModel

                        'INSERTING THE COMPONENT INTO THE ASSEMBLY

                        swComponent = swAssy.AddComponent5("Component.SLDASM", 0, "", False, "", 0, 0, 0)

                        boolstatus = swComponent.Select4(True, Data, False)

                        'MAKING THE COMPONENT UNFIXED

                        swModel.UnfixComponent()

                        Part = swApp.ActiveDoc

                        swDoc = CType(swApp.ActiveDoc, ModelDoc2)

                        'SELECTING THE SPHERE'S PLANES WITHIN THE COMPONENT ASSEMBLY THAT WAS JUST INSERTED

                        boolstatus = swDoc.Extension.SelectByID2("Right Plane@Component-1@" & AssemblyTitle & "/" & SphereNum & "-2@" & Component,"PLANE", 0, 0, 0, True, 0, Nothing, 0)

                        'SELECTING THE SPHERE'S PLANES WITHIN COMPONENT2 ASSEMBLY THAT IS ALREADY IN THE OVERALL ASSEMBLY

                        boolstatus = Part.Extension.SelectByID2("Right Plane@Component2-1@" & AssemblyTitle & "/" & SphereNum & "-2@" & Component2, "PLANE", 0, 0, 0, True, 0, Nothing, 0)

                        'MATING THE TWO PLANES FROM THE SPHERES' PLANES SELECTED

                        myMate = Part.AddMate3(0, 0, False, 0, 0, 0, 1, 1, 0, 0, 0, False, longstatus2)

                        Part.ClearSelection2(True)

                        Part.EditRebuild3()

                         

                        Thanks!

                          • Re: API Will Not Mate Components (It Did Before Until Today)
                            Artem Taturevych

                            The lines in red are very risky. Depending on the situation the instance id of the component may be different. If you know the name of the plane (and you know this) it would be much better to get the plane directly from the component and select it. Something like that:

                             

                            Dim swPlane as SldWorks.Feature

                            Set swPlane = swComponent .FeatureByName("Right Plane")

                            swPlane.Select2 False, 0

                             

                            'OPENING THE COMPONENT ASSEMBLY

                            swApp.OpenDoc6("Component.SLDASM", 2, 0, "", errors, warnings)

                            'REACTIVATING THE OVERALL ASSEMBLY

                            swModel = swApp.ActivateDoc2(AssemblyTitle, True, errors)

                            swAssy = swModel

                            'INSERTING THE COMPONENT INTO THE ASSEMBLY

                            swComponent = swAssy.AddComponent5("Component.SLDASM", 0, "", False, "", 0, 0, 0)

                            boolstatus = swComponent.Select4(True, Data, False)

                            'MAKING THE COMPONENT UNFIXED

                            swModel.UnfixComponent()

                            Part = swApp.ActiveDoc

                            swDoc = CType(swApp.ActiveDoc, ModelDoc2)

                            'SELECTING THE SPHERE'S PLANES WITHIN THE COMPONENT ASSEMBLY THAT WAS JUST INSERTED

                            boolstatus = swDoc.Extension.SelectByID2("Right Plane@Component-1@" & AssemblyTitle & "/" & SphereNum & "-2@" & Component,"PLANE", 0, 0, 0, True, 0, Nothing, 0)

                            'SELECTING THE SPHERE'S PLANES WITHIN COMPONENT2 ASSEMBLY THAT IS ALREADY IN THE OVERALL ASSEMBLY

                            boolstatus = Part.Extension.SelectByID2("Right Plane@Component2-1@" & AssemblyTitle & "/" & SphereNum & "-2@" & Component2, "PLANE", 0, 0, 0, True, 0, Nothing, 0)

                            'MATING THE TWO PLANES FROM THE SPHERES' PLANES SELECTED

                            myMate = Part.AddMate3(0, 0, False, 0, 0, 0, 1, 1, 0, 0, 0, False, longstatus2)

                            Part.ClearSelection2(True)

                            Part.EditRebuild3()

                             

                            __________________________

                            Regards,

                            Artem Taturevych

                            Application Engineer at Intercad

                            http://intercad.com.au/

                            Tel: +61 2 9454 4444

                              • Re: API Will Not Mate Components (It Did Before Until Today)
                                Aj Jones

                                For this particular program the instance ID doesn't change for the assembly.  However I don't know how you can select the plane of the component in the subassembly within the assembly without knowing the instance id of the part? 

                                 

                                Here is how the assembly is setup for the two planes I am trying to select:

                                 

                                Overall Assembly

                                - Front Plane

                                - Top Plane

                                - Right Plane

                                     - Subassembly-1

                                          - Front Plane

                                          - Top Plane

                                          - Right Plane

                                          - Component Part-1

                                               - Front Plane

                                               - Top Plane

                                               - Right Plane (This is what I want to select)

                                     - Subassembly-2

                                          - Front Plane

                                          - Top Plane

                                          - Right Plane

                                          -Component Part-1

                                               - Front Plane

                                               - Top Plane

                                               -Right Plane (This is the other plane I want to select)

                                 

                                Thank you for all of your help!