how can I store an instance of an object of a custom class within a macro-Feature. I want to access the data in the object during swmRebuild(..).
it doesnt work that way. i supposed you could convert the com objects to Intptr (pointers) but that would be a terrible idea.
Select all of the items before you call InsertMacroFeature3. The selected items will then be accessible in GetSelections3.
selected items MUST BE SOLIDWORKS OBJECTS. or at least as far as i know.
Read this below
2018 SOLIDWORKS API Help - SetSelections2 Method (IMacroFeatureData)
trust me, its a terrible idea to go any other way than the way solidworks has specified.
you can use SetSelections3 but the array must be i believe an Object array
Dim Sels(2) as object
sels(0) = something
sels(1) = SomeOtherSolidworksThing
SelMarks are not used for SwSelectType_e.
dim SelMarks(2) as integer
leave them as is, they default to 0
so to recap.
before calling InsertMacroFeature3
Select all of the items in the order that you want to get them in swmRebuild
determine what each item is in the array returned
execute your code
using a xmlserialize may be an ok way to do it, however i would assume it would be very slow compared to using parameters (integer, Double, String)
dim ParamNames(5) as string
Dim ParamTypes(5) as integer
dim ParamVals(5) as string
paramNames(0) = "SomeParameterName"
ParamTypes(0) = swMacroFeatureParamType_e.swMacroFeatureParamTypeInteger (or string or double)
ParamVals(0)= SomeValue converted to a string
then in swmrebuild use IMacroFeaturedata:GetParameters to get these values
2018 SOLIDWORKS API Help - GetParameters Method (IMacroFeatureData)
it is important to know that you should set everything into MacroFeatureData that will be needed to rebuild the feature.
so take all the solidworks objects out of your class, Select them.
take all of the values and set them in ParamNames, ParamTypes, ParamVals
If I am understanding you correctly...
Dim myClass as New NameOfClass
Dim myClass as NameOfClass
Set myClass = NameOfClass
This will create a new instance of the class object within a subroutine. If this is not quite what you are looking for, please provide more detail and hopefully I can help.
you can only assign certain things to macrofeatures.
Parameters Like Strings, Doubles, Integers
Parameters can be anything.
so during swmrebuild, you would need to use the parameters to create this "Class" that you want to instantiate. it would be only data and no live COM references as it is not safe to do this.
For proper macrofeatures you need to capture all of the data you need and put that data in the MacroFeature (params)
when you call
2018 SOLIDWORKS API Help - InsertMacroFeature3 Method (IFeatureManager)
you specifiy all of the information needed to rebuild the macro feature.
the swmRebuild is the code that executes against that data.
if you were writing in .net then there is a lot more you can do. my macrofeatures all regenerate using a database and a class that is instantiated in my addin for each specific feature. this class is held by my addin.
what i gain is about a 30% reduction in regeneration time as the data used to regenerate is stored in the feature, however i use a live instance of a data class to remember information so my addin does not need to constantly ask solidworks for it, which is very time consuming.
clear as mud?
Yes, clear as mud . Definitely thought you were asking a more basic question...
Why can't you create a new class object during the swmRebuild function? Or call another macro (like this example from this thread...How do you add Macro as Macro Feature? ) to do what you are talking about. I might be still misunderstanding what your goal is and what you want this class to do exactly.
you can do whatever you want during rebuild, literally.
but sending a class in vba to a COM Server that is instantiated on the fly, not so much.
plus how do you capture a class and store it? you cant. you need to dissect the class into its data, then pass that to the macrofeature through SetStringByName, SetDoubleByName, SetIntegerByName.
but you need to do this at creation. IFeatureManger::InsertMacroFeature3
you can expand and change the size of the Parameter arrays using this
2018 SOLIDWORKS API Help - SetParameters Method (IMacroFeatureData)
you can also use IDisplayDimensions in macrofeatures which makes them really awesome. (and unstable in VB.NET)
if the class does not need to be instantiated, then the class is nothing more than a group of subs and functions. if this is the case, then you just need to set the functions and methods to Public and make sure you have a reference to them in the Class that executes SWMRebuild
if so, simple. an active class has data that is stored in it at that moment of time, think of it as alive. if its a class of functions and there are no local variables, then its just a group of functions.
probably still muddy. if so the answer is no
macrofeatures are a pain in the butt to get right, but they are also the most powerful piece of the Solidworks API.
Well sounds like you have a great understanding of these things and there is nothing I can help with. Good luck!
i didn't ask the question Evan Dlugopolski. Viktor Langofer did
...can't believe I made that rookie mistake..
Anyway...sounds like you are more suited to help Viktor out!
As Jacob suggested you have more options in .NET. You can serialize your class into JSON or XML and store the data in the macro feature string parameter.
Basically I have some entities like a few sketchlines, a sketchpoint and a coordinatesystem, which are now inside my class. During swmRebuild(..) I want to recover the selection to modify this entities. I tried now as Evan Dlugopolski said with selections but I dont get it to work. Below in the pictures I tried now with one entity, but it also doesnt work. Is it possible to select different types?
How can I execute SetSelections2 before creating the feature with insertMacroFeature3? I get the MacroFeatureData instance from the macrofeature "feat.GetDefiniton()" itself, or? Or do you mean I have to select the objects in a other way?
Ok I figured out, it works with Select4(...)! I got a positive SelectionCount.
But I'm still stuck with GetSelections3(...). I'm doing right below? Why the debugger shows me after calling GetSelections3 that Objects and the other values are all Nothing?
swmRebuild(vApp As Variant, vModel As Variant, vFeature As Variant) As Variant
Dim sw As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cgFeature As Feature
Dim featData As SldWorks.MacroFeatureData
Set sw = vApp
Set swModel = sw.ActiveDoc
Set cgFeature = vFeature
Set featData = cgFeature.GetDefinition()
Dim Objects(3) As Object
Dim ObjectTypes(3) As Object
Dim SelMarks(3) As Object
Dim drviews(3) As Object
Dim ComponentXForms(3) As Object
Call featData.GetSelections3(Objects, ObjectTypes, SelMarks, Nothing, Nothing)
Best and thanks for the help so far,
Dim sels, types, selmarks
2018 SOLIDWORKS API Help - Cut Body in Half using Macro Feature Example (VBA)
in .net its different for this, but if your writing this in VBA you use the above delcaration
see the link
Retrieving data ...