14 Replies Latest reply on Jul 29, 2015 1:20 AM by Charlie Fan

    How to make Macro embeded into a part

    Charlie Fan

      Hi all,

       

      I have a simple macro. All it does is to change the dimension of a part.

       

      I used those "active doc" thing to refer to the part file and to the dimension I want to change.

       

      When I open this part and run the macro, no problems it can change the dimension.

       

      However, when I put this part file in an assembly, and then run the macro, it doesn't work since the "Activedoc" is changed to the assembly, not the part.

       

      I need the macro I made, or the logic I programmed to be embedded into the part file, so when this part file is in assembly, the logic can still run automatically.

       

      This is particularly useful, if the part need to be intelligent and fit the change of the assembly, and if this logic need to be achieved by programming in vba.

       

      In other words, this logic(macro) must run automatically when I rebuild model, and interact with only this part, not the assembly file I have opened.

       

      I have tried to attach macro to part, use equation to trigger it. But this is a silly work around since the equation editor always stand in my way and, you cannot edit this macro once attached.

       

      I have tried to squeeze macro codes into properties and that is also another silly solution, since I cannot easily debug the code and it cannot be longer than 1024 Bytes.

       

      I don't understand why the competitor of solidworks, namely Autodesk Inventor, can have a function "iLogic" to have vba code built into a part decently and travel with the part. Even when this part is in the assembly those logic can still run smoothly to fit the change of the assembly. Is it true that Solidworks is a software that inferior to Autodesk Inventor?

       

      Any insights or suggestions will be highly regarded.

       

      Thank you.

          • Re: How to make Macro embeded into a part
            Charlie Fan

            Not really helpful.
            I just cannot find anyway to just create a macro feature.

            Is this just a advertisement link??? Especially the last one.

             

            Plus, can the macro feature still works if I change the part file name and put it in another assembly? this happens when I do pack and go, the part file name will change.

              • Re: How to make Macro embeded into a part
                Deepak Gupta

                Second link is an example of macro feature.

                 

                The last link is video showing the macro feature. To get the details on how to create that, one need to be a member of the CadSharp.com (if you want to learn API, I can recommend this site).

                 

                Plus, can the macro feature still works if I change the part file name and put it in another assembly? this happens when I do pack and go, the part file name will change.

                I'm not sure as I've not experimented with macro feature.

            • Re: How to make Macro embeded into a part
              Charlie Fan

              Still no useful answers? Then should I say this is what Inventor can do and Solidworks can't?

               

              Making the part smart and can fit the change of the assembly is important. Certainly we can use some "equation" in the part to do it, but this is very limited functionality. All I want is a method to embed macro into the part when I update the assembly, so the part will change itself to fit the assembly.

               

              I don't want to switch to inventor. But I have to if there is no solution on this.

               

              If still no answer, I will have to make "Solidworks can't, but its competitor Inventor can" as correct answer.

                • Re: How to make Macro embeded into a part
                  Ivana Kolin

                  Solidworks can't, but its competitor Inventor can

                   

                  When part file with macrofeature is in assembly and you rebuild assembly, then macrofeature does nothing. MacroFeature calls methods only when model, where feature resides is root model.

                    • Re: How to make Macro embeded into a part
                      Charlie Fan

                      That is really a shame for Solidworks. How can a parametric modeling software has such a limitation? Don't they know how important this is for BIM? They say solidworks have highest market share in this kind of modeling software, and nobody had asked this question before???

                       

                      Now, we have a good example that something inventor can do and solidworks can't. This one is not small, this one is big, and this one will cost solidworks  it's future.

                       

                      If nobody object to your answer in 48 hours, then I will make your one correct Answer, and tell everyone about it!!!

                        • Re: How to make Macro embeded into a part
                          Deepak Gupta

                          Have you tried using smart components rather than making a macro feature in the part?

                           

                          Can you share more details on what you'r trying to do, may be with some simple example?

                            • Re: How to make Macro embeded into a part
                              Charlie Fan

                              I have made it very clear above.

                               

                              And sorry, smart component is not what I am talking about.

                                • Re: How to make Macro embeded into a part
                                  Deepak Gupta

                                  There can be many ways apart from using a macro or macro feature. So just wanted to know as what logic you're using to drive the dimensions.

                                   

                                  And by suggesting about smart component, I wanted to ask if you've tried using that.

                                  You can add auto-sizing capability to cylindrical Smart Components. When you insert the Smart Component onto a cylindrical component, the size of the Smart Component adjusts to fit the cylindrical component.

                                    • Re: How to make Macro embeded into a part
                                      Charlie Fan

                                      If it is just about changing the cylindrical diameter, an equation is good enough.

                                       

                                      The part file can detect one dimension from assembly. The assembly is skeleton driven, so it is easy to transfer the dimension from assembly skeleton to part skeleton sketch by using external reference.

                                       

                                      Then the part need to make decision based on this value, it is result of complicated "if then", "For loop", and even sometimes query from SQL database. The result operation can be changing configuration, delete bodies or updating cutlist properties that all requires API programming within a macro.

                                       

                                      This logic has to be run within the part when the assembly, which contains it, is open, and even if I change the part file name the logic still works(that is why cannot use filename to refer to it, and cannot use "Activedoc" class to refer to it).

                                       

                                      Is it clear enough?

                                        • Re: How to make Macro embeded into a part
                                          Deepak Gupta

                                          Yes clear enough. Have you tried editing that part in assembly mode and then let the macro feature or macro run?

                                            • Re: How to make Macro embeded into a part
                                              Charlie Fan

                                              No, that assembly have dozens of "smart part", each with its own logic and it is silly to open each single part, run it and then get out.

                                               

                                              This assembly would be sub assembly of an even bigger assembly. The part must run the logic itself when the top top level of main assembly have updated dimension.

                                               

                                              This is what BIM is about. When I change the floor to floor height of a building, the staircase (smart sub assembly of the building) have to update its shape and number of treads, then the handrail(smart sub assembly of staircase) on this stair have to be driven by the stair, and determine the number of glass panel on it. Each panel(smart sub assembly of handrail) will then update the fixing type and calculate shape of the glass(smart part). This system have dozens of "smart" sub assemblies and hundreds of "smart parts". Each floor have dozens of staircases. We make hundreds of this kind of system per day. We fabricate them and install them onto the buildings, not designing them and show people, so Revit is not good idea. We don't have an army of solidworks operators and only rely on handful of a few to put those smart models onto the concrete base 3D model of the building which is exported from architects. Those architects keep changing there dimensions and the change will drive our staircase and railing models. These logics have to be achieved by programming macro.

                                               

                                              Now tell me, is it a good idea to open each single part and update them??? What's the point of making those assemblies?

                                               

                                              Why inventor can do this and solidworks can't??

                              • Re: How to make Macro embeded into a part
                                Charlie Fan

                                Still no useful answer yet?