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....
Ok, let me explain this issue. When you are passing the class name which implements the iSwComFeature interface macro feature will instantiate this class. In other words new instance of SwAddin is created. So you have two instances of the same class now: first is your add-in and second is your macro feature. When macro feature creates an instance of the SwAddin class ConnectToSw function is not raised and all variables are not instantiated.
The iSwApp is Nothing so this line throws the exception:
swmodel = Me.iSwApp.ActiveDoc
you should replace it by:
swmodel = app.ActiveDoc
where the app is the pointer to SldWorks passed as parameter to Regenerate function.
P.S. You should be able to debug add-in regardless it is class library.
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
LinkedIn SolidWorks API Education Group
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.
I ahve already added all required libraries..i t is showing me an error on compiling. as..
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
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...
Hi Artem thanks for ur reply...
But i am using Microsoft visual studio express edition 2012...and this option is not there...
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.
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 ..
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.....
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?
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
Please help me ....in this to understand...
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.
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
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
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...
Hi to all
Some one is having any idea about this..
Can you put the breakpoint in Regenerate to see where it fails. I wouldn’t select any objects in regenerate. Do you really need this or this just a test case? Can you attach the complete add-in for me to test?
As i have already mention i have downloaded...this macro feature from this link..
Three options are there i have downloaded first one...('VB NET Addin InsertMacroFeature.zip'.)
...its a class library type so i cant put breakpoint...
U plz go through this...and let me know how to put regenerate action back..through code...
Thank you so so much....for this..it was very small mistake from myside....
U are Genius man...Thanks a lot...
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.
Retrieving data ...