4 Replies Latest reply on Aug 6, 2018 6:13 AM by Learn Help

    How make a constraints between two parts

    Learn Help

      hello,

      i tried to add part into assembly parts and assembled it with it, so , i found how to add part , but, i had same problem when i tried to assembled it.

      this is my algorithm :

         swModel.ClearSelection2(True)

              swDocExt = swModel.Extension()

              MateName = "Concentric520" + strCompName

              FirstSelection = "Point1@Origin@" + strCompName & "@" + AssemblyName

              SecondSelection = "Point1@Origin@" + AssemblyName

       

       

              boolstat = swDocExt.SelectByID2(FirstSelection, "CONCENTRIC", 0, 0, 0, True, 1, Nothing, swSelectOption_e.swSelectOptionDefault)

              boolstat = swDocExt.SelectByID2(SecondSelection, "CONCENTRIC", 0, 0, 0, True, 1, Nothing, swSelectOption_e.swSelectOptionDefault)

       

              matefeature = swAssemblyDoc.AddMate3(swMateType_e.swMateCONCENTRIC, swMateAlign_e.swMateAlignALIGNED, False, 0, 0, 0, 0, 0, 0, 0, 0, False, mateError)

              swModel.ClearSelection2(True)

      when i run it, it works without error but the part isn't assembled.

      i tried to show the mateError  :  MsgBox(mateError) , it gives me : 4 as a result.

      Can you help me please, and thanks.

        • Re: How make a constraints between two parts
          Nilesh Patel

          If you want to select origin of the main assembly document then replace ""Point1@Origin@" + AssemblyName" with '"Point1@Origin" only in the following line.

          Learn Help wrote:

           

          SecondSelection = "Point1@Origin@" + AssemblyName

           

          Replace "CONCENTRIC" with "EXTSKETCHPOINT" in following two lines.

          Learn Help wrote:

           

          boolstat = swDocExt.SelectByID2(FirstSelection, "CONCENTRIC", 0, 0, 0, True, 1, Nothing, swSelectOption_e.swSelectOptionDefault)

          boolstat = swDocExt.SelectByID2(SecondSelection, "CONCENTRIC", 0, 0, 0, True, 1, Nothing, swSelectOption_e.swSelectOptionDefault)

           

          See if these changes works.

           

          Regards,

          Nilesh

            • Re: How make a constraints between two parts
              Learn Help

              hello, i do those modifications, but, i got the same response, nothing change

                • Re: How make a constraints between two parts
                  Nilesh Patel

                  Could you attach your assembly (if it is not too large) and the macro?

                    • Re: How make a constraints between two parts
                      Learn Help

                      Hello,

                      i can't, the size of my assembly is to high. but about the algorithm, i found other guys who use Point1@Origine@ with e.

                      my goal is to assemble the origin of  part with the assembly, or assemblr the axis of hte part with the assembly

                      i made same change  :

                      Code#

                          swModel.ClearSelection2(True)

                              swDocExt = swModel.Extension()

                              MateName = "Concentric52" + strCompName

                              FirstSelection = "Point1@Origine" + strCompName & "@" + AssemblyName

                              SecondSelection = "Point1@Origine" + AssemblyName

                        

                              boolstat = swDocExt.SelectByID2(FirstSelection, "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)

                              boolstat = swDocExt.SelectByID2(SecondSelection, "EXTSKETCHPOINT", 0, 0, 0, True, 1, Nothing, 0)

                       

                              ' Add the mate

                              matefeature = swAssemblyDoc.AddMate3(swMateType_e.swMateCOORDINATE, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, mateError)

                              If matefeature Is Nothing Then

                                  MsgBox(" mate failed! ")

                       

                              End If

                              swModel.ClearSelection2(True)

                              swAssemblyDoc.EditRebuild3

                       

                       

                              swModel.ViewZoomtofit2()

                      I'm getting crazy about it...hope you'll find a solution!