9 Replies Latest reply on Sep 25, 2017 7:37 AM by Aaron Torberg

    Modify an existing concentric mate using a macro?

    Aaron Torberg

           I have a macro that needs to update a concentric mate.  In the image below there is a pattern of the part "1400-015-035-0", I update the pattern using the macro to change the number of parts from 15 to 20, then I need to update this mate to attach to the 20th instance of this part.  Can I do this within a macro?  I am writing all of this in VBA.  Thanks for any help!



        • Re: Modify an existing concentric mate using a macro?
          Josh Brady

          "Can I do this with a macro?"  I don't know.  I could do it with a macro.  Whether or not you can is another question.  What is your ability?  What is your plan?  What are your thoughts on ways that this might be done?  Are you just looking for someone to do it for you?


          I can tell you it's probably going to involve EditMate4.  There's an example in the API help. 

            • Re: Modify an existing concentric mate using a macro?
              Aaron Torberg

                   I am glad to hear you can do it - I guess I just have to figure out how I will do it.  While the literal translation of my question does imply that I would need the knowledge to do it, I guess I am more or less questioning if this is a simple operation, or something way more involved.


                   I have very little programming experience, but I have developed a few marcos.  I am entirely self taught so I guess my programming ability is relatively limited, but better than not knowing anything.


                   I don't have a plan other than to edit the number of instances and update this mate.  In searching for an answer I did not find much on updating mate references so I thought I would ask the question here.


                   I don't have any thoughts on how I would do this.  I have never come across this previously, also, why I thought I would ask the question here.


                   I am not looking for someone to do it for me.  If someone could point me to a good resource I would be happy to try to figure it out on my own.  After looking at the API Help and EditMate4 it looks like I will be able to do just that.  Thank you!

                • Re: Modify an existing concentric mate using a macro?
                  Josh Brady

                  That was kind of the point of my post... Not really intending to be a jerk.  We don't have a way to know if we need to tell you "go to Tools->Macro->Edit" or just point you to one or two topics in the help to kick-start you in the right direction. If it's the former, then no, you can't.  Too much to learn.  If the latter, you probably can.  There are plenty of people who post vague API questions that wouldn't know a macro from a Word document and hope someone writes the code for 'em. 


                  Do you already know how to edit the pattern feature?  Do you already know how to programmatically find and select the face of interest on your last component?  

                    • Re: Modify an existing concentric mate using a macro?
                      Aaron Torberg

                      Yes, I can edit the instances of my pattern.  I do not know how to find the face of interest on my last component, but I am sure I will learn.  Thank you for the Help Josh.

                        • Re: Modify an existing concentric mate using a macro?
                          Josh Brady

                          OK, here's the path you're going to need to take...


                          Use MateEntity on the mate of interest to get the currently-mated entity.  And, of course, the other mated entity for EditMate2.

                          Might have to use GetCorresponding to get the entity in the context of the component's ModelDoc2. Not sure.

                          Use GetFirstSubFeature and GetNextSubFeature on the pattern feature to access the pattern instances.

                          Use GetSpecificFeature on the Feature object corresponding to the last pattern instance to return a Component2 object.

                          Use GetCorrespondingEntity (or one of those similar ones, I forget which) to get a reference to the entity on that specific Component2 instance in the context of the assembly.  I'm not sure if you can go straight from the MateEntity to the correct entity on the new Component2 or if you'll have to do that second step above.

                          Clear selections

                          Select the mate, the entity on the new component, and the entity that stays in the mate.  Then EditMate2.


                          The other thing I would caution is more related to assembly practices.  I try to be very careful when positioning assembly components with mates to patterned components.  Patterns don't seem to always solve simultaneously with mates.  I have seen several instances of assemblies being unstable as far as positioning goes due to hanging too many components off the end of a patterned component.

                      • Re: Modify an existing concentric mate using a macro?
                        Elmar Klammer

                        Hello Aaron,


                        You can read Josh's comment and ask yourself what he is trying to say. Or you can feel upset about the fact that he might have not offered the help you would have expected. I do think you can learn a lot from someone like Josh. I would encourage you to look into the brass tax of his point and you will indeed see the benefits. I can only say that Josh is one of the top skilled users of SolidWorks in particular when it comes to programming. So he is definitely capable and knowledgeable.

                        I think it should go without saying. There is not entitlement or birthright to help. You can ask for help but can't demand it. If you don't get the help you are looking for then look into other options. See what you can do differently to change the outcome.

                        Ask yourself if your questions describe what you want to accomplish in a way that someone other than yourself can understand.

                        That's in a nutshell what Josh has tried to point out. He could have responded differently. You could have put some more effort in your post. No one the wiser. One word of advise. Check your ego at door and life will be better in the long run. Whether your name is Josh, Aaron or Elmar or whoever




                          • Re: Modify an existing concentric mate using a macro?
                            Aaron Torberg



                                 Thank you for your insight.  Your correct, I probably could have put more effort into my post, and Josh certainly seems like one of the "top skilled users of SolidWorks".  I appreciate the help Josh has provided, and I have learned quite a bit as a result.


                                 I agree, it goes without saying, there is not entitlement or birthright to help.  I hope no one reads my initial post is assumes otherwise.

                        • Re: Modify an existing concentric mate using a macro?
                          Amen Allah Jlili

                          You can edit mates with IAssembly::EditMate4


                          Select the following items in the following order before calling this method:

                          1. Mate feature to edit.
                          2. Two model items to mate (that is, two faces, edge and face, and so on). The two model items must be selected with a selection mark of 1. See ISelectData or IModelDocExtension::SelectByID2 for details on using selection marks.




                          CADHERO consulting SUARL – CAD Design Automation & Training – SOLIDWORKS API