16 Replies Latest reply on Feb 7, 2014 5:43 PM by Jacob Corder

    About Macro feature .net file

    Raghvendra Bhargava

      Hi to all,

       

      Any one have macrofeature .net file for framework4.0...i got some some macrofeature file on forum but on compiling these files showing some error....

        • Re: About Macro feature .net file
          Artem Taturevych

          Note, if you are using the .NET Framework. You should use specific interop libraries. Please read this topic: http://help.solidworks.com/2013/English/api/sldworksapiprogguide/Welcome.htm

           

          I guess this is a reason of the fail.

          ____________________________________________________

          Regards,

          Artem Taturevych, Application Engineer at Intercad (Australia)


          translationXpert – add-in to translate SolidWorks models

          LinkedIn SolidWorks API Education Group

            • Re: About Macro feature .net file
              Raghvendra Bhargava

              Hi Artem,

              I ahve already added all required libraries..i t is showing me an error on compiling.  as..macro_feature error.JPG

              this kind of error i have faced when i tried to register framework 4.0 ..dll with regasm of framework 2.0 ..but here how to get rid of this ..

              Please help me...

              please try this link...i got files from

              https://forum.solidworks.com/docs/DOC-1396

                • Re: About Macro feature .net file
                  Artem Taturevych

                  Hi Raghvendra,

                   

                  Well, I assume the only thing you should change is the Post-Build action script. Please specify the paths to RegAsm v 4 in the script instead of v 2. In order to see your scrip go to Project->Properties->Build Events->Edit Post-build...

                   

                  RegAsm.png

                  BuildEvents.png

                  ____________________________________________________

                  Regards,

                  Artem Taturevych, Application Engineer at Intercad (Australia)

                   

                  translationXpert – add-in to translate SolidWorks models

                  LinkedIn SolidWorks API Education Group

                    • Re: About Macro feature .net file
                      Raghvendra Bhargava

                      Hi Artem thanks for ur reply...

                      But i am using Microsoft visual studio express edition 2012...and this option is not there...

                        • Re: About Macro feature .net file
                          Artem Taturevych

                          Try to replace your project file with the attached file.

                           

                          If that doesn’t work  let me know what sample project you have downloaded (there 2 VB.NET projects) and what exactly the path of your RegAsm for Framework 4.

                          ____________________________________________________

                          Regards,

                          Artem Taturevych, Application Engineer at Intercad (Australia)

                           

                          translationXpert – add-in to translate SolidWorks models

                          LinkedIn SolidWorks API Education Group

                            • Re: About Macro feature .net file
                              Raghvendra Bhargava

                              Hi Artem,

                              Thanks for your reply...

                              i have downloaded 'VB NET Addin InsertMacroFeature.zip'.

                              Anyways..i fixed all coding it is now working fine ..but now there is a problem ..please help me in this..the problem is there are three function in this ..

                               

                              1)Function Edit....

                              2)Function Regenerate

                              3)Function Security...

                               

                              now my aim for Macro feature is on every rebuild it should get length for one sketch segment and put in to the Custom properties ..

                               

                              So this code i am putting in Function Regenerate but it is not working ..so please help me in this where i should put this code.....

                                • Re: About Macro feature .net file
                                  Artem Taturevych

                                  Is your macro feature placed before the sketch in the feature tree? When it rebuild the sketch may be rolled back if it is lower than macro feature in the tree. You may need to use the swMacroFeatureAlwaysAtEnd as InsertMacroFeature3 options parameter. Another question is how you store the pointer to the target sketch segment?

                                  ____________________________________________________

                                  Regards,

                                  Artem Taturevych, Application Engineer at Intercad (Australia)

                                   

                                  translationXpert – add-in to translate SolidWorks models

                                  LinkedIn SolidWorks API Education Group

                                    • Re: About Macro feature .net file
                                      Raghvendra Bhargava

                                      Hi Artem,

                                       

                                      This problem is not with adding macro feature.

                                      Problem is in code only ..see i have already created macro feature in vb(.swp) in solidworks ..so there actually in InsertMacroFeature3..we have to define methods of 9 array ...so there in one of the method i am adding my desired code ..it was like this

                                       

                                      featmgr.InsertMacroFeature3("UpdateLength", "", (Methods), Empty, Empty, Empty, "", "", "", "", swMacroFeatureAlwaysAtEnd) ..

                                       

                                      Above code line i have used to create .swp file ...

                                      But in VS code is like

                                       

                                      FeatMgr.InsertMacroFeature3("Pipe_le", "swVBAddinTest.SwAddin",Nothing,(paramNames),(paramTypes), (paramValues), Nothing, Nothing, editBody, Nothing,opts)

                                       

                                      so here you can see..the difference..so my doubt is ....on the action of rebuild where i should write my code do desired output..

                                       

                                      so conclusion is like if i will do rebuild in solidworks part (where macro feature is added) it should return some code to do desired action...so in .net file where i should write ...

                                      I have downloaded 'VB NET Addin InsertMacroFeature.zip' in

                                      https://forum.solidworks.com/docs/DOC-1396 link...

                                      Please help me ....in this to understand...

                                        • Re: About Macro feature .net file
                                          Artem Taturevych

                                          Hi Raghvendra,

                                           

                                          OK, I think I understand your issue. You want to find out how to create a handler of macro feature functions in VB.NET. You are right it differs from VBA. In C#/VB.NET and C++ the com class is used as the handler of the functions.

                                           

                                          1) In order to create the handler in VB.NET you should create a public class and implement the ISwComFeature interface which actually contains all these functions. Please note that this class should be COM visible so either enable this option on the project level in project properties or add the ComVisible attribute.

                                           

                                          2) Pass the class id as the ProgId parameter of IFeatureManager::InsertMacroFeature3 Method. Usually this is the <Namespace>.<ClassName>. However you can explicitly assign the unique class id using the ComClass attribute. This should be the GUID of your COM-class.

                                           

                                          3) Once you done this your macro feature is bind to this com object which is responsible for macro feature behaviour. You should implement all the logic in handler functions.

                                          ____________________________________________________

                                          Regards,

                                          Artem Taturevych, Application Engineer at Intercad (Australia)

                                           

                                          translationXpert – add-in to translate SolidWorks models

                                          LinkedIn SolidWorks API Education Group

                                            • Re: About Macro feature .net file
                                              Raghvendra Bhargava

                                              Hi Artem,

                                               

                                              yes u got my point actually in this code IsComFeature was already added...

                                              i have already mentioned

                                              there are function edit,regenerate and Security..

                                              I have checked these are like if i want to edit in macrofeature i must use edit...or on rebuld i should use Regenerate..but there is a problem..i wrote my code inside regenerate..function..but it is not working ..so am i missing something...

                                               

                                               

                                              Function Regenerate(ByVal app As Object, ByVal modelDoc As Object, ByVal feature As Object) As Object Implements SwComFeature.Regenerate
                                                      '
                                                      Dim swmodel As ModelDoc2
                                                      Dim swfeat As Feature
                                                      Dim bret As Boolean


                                                      swmodel = Me.iSwApp.ActiveDoc


                                                      swfeat = swmodel.FirstFeature

                                                      Do While Not swfeat Is Nothing

                                                          If swfeat.Name = "ff" Then
                                                              bret = swmodel.Extension.SelectByID2("ff", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
                                                              MsgBox("Right")
                                                          End If
                                                          swfeat = swfeat.GetNextFeature
                                                      Loop

                                               

                                                      MsgBox("MF Regen")
                                                      Return Nothing

                                                  End Function

                                               

                                               

                                              but if am adding this code..Macro feature is not adding...

                                              And if i will remove my code ..and only if i will add MsgBox("MF Regen")  macro feature is adding and on rebuild it showing me message "MF Regen"....so what i am doing wrong i am not able to find...

                            • Re: About Macro feature .net file
                              Jacob Corder

                              Just something to add to this discussion.

                               

                              I had this same issue when i started creating my Application which uses Macro Features.  What I ended up doing was putting the callback in a separate class in the same project and passed that class name to the macro feature upon creation.  I had an issue where it would create a new instance of my main addin where the Callback functions were and i wanted to get the values from my current running addin so i called ISwapp.GetAddinObject(my addins class id) which worked great and connected my rebuild function with my current running application. I was then able to add lots of features at once and set a boolean to process them or  wait to process all of them at once.  It really helped to give me full control to the application.