Right now i am using a macro code to add apperances to the marked features but i can only do one at a time. how do i edit this code so i can mark multiple features? or even so i can just run this macro and it it automaticly apply this to all hole wizard features it can find?
- 'Written by Keith Rice
- 'CADSharp LLC
- 'www.cadsharp.com
- Option Explicit
- Const APPEARANCE_PATH As String = _
- "c:\\Program Files\\solidworks corp\\solidworks\\data\\graphics\\materials\\organic\\wood\\maple\\polished maple 2d.p2m"
- Sub main()
- Dim swApp As SldWorks.SldWorks
- Dim swModel As SldWorks.ModelDoc2
- Dim swSelMgr As SldWorks.SelectionMgr
- Dim swObj As Object
- Dim swRenderMat As SldWorks.RenderMaterial
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc
- Set swSelMgr = swModel.SelectionManager
- Set swObj = swSelMgr.GetSelectedObject6(1, -1)
- If swModel.GetType = swDocPART Then
- If swObj Is Nothing Then Set swObj = swModel
- ElseIf swModel.GetType = swDocASSEMBLY Then
- Dim swAssy As SldWorks.AssemblyDoc
- Dim swComp As SldWorks.Component2
- Dim lngInfo As Long
- Set swAssy = swModel
- If TypeOf swObj Is SldWorks.Face2 Or _
- TypeOf swObj Is SldWorks.Feature Or _
- TypeOf swObj Is SldWorks.Body2 Then
- Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, -1)
- swComp.Select4 False, Nothing, False
- swAssy.EditPart2 False, True, lngInfo
- If lngInfo = -1 Then
- swApp.SendMsgToUser "Failed to edit component."
- Exit Sub
- End If
- End If
- Else
- Exit Sub
- End If
- Set swRenderMat = swModel.Extension.CreateRenderMaterial(APPEARANCE_PATH)
- If swRenderMat.AddEntity(swObj) = False Then
- swApp.SendMsgToUser "Failed to add entity."
- Exit Sub
- End If
- If swModel.Extension.AddDisplayStateSpecificRenderMaterial( _
- swRenderMat, swAllDisplayState, Empty, Empty, Empty) = False Then
- swApp.SendMsgToUser "Failed to add appearance."
- Exit Sub
- End If
- swModel.EditRebuild3
- If Not swComp Is Nothing Then
- swComp.Select4 False, Nothing, False
- swAssy.EditAssembly
- End If
- End Sub

For multiple features, you could do something like this:
When you feel more confident, look for "traversing" techniques...
So you won't need to select anything and will be able to do, as you said, "all in once".
For instance, this example:
2019 SOLIDWORKS API Help - Traverse Assembly at Component and Feature Level Example (VBA)
It "scan" the entire tree and print in the immediate window the name of every sub assembly, every component and every feature (assuming the component is not in lightweight)
Once you understand it, you can tweak to set specific colors to specific features.
This is super helpful. Thank you. Managed to apply the code so i can color the different features with different colours. not all in once but small steps
Bookmark the SW API help (I prefer the online version)
2019 SOLIDWORKS API Help - Welcome
(Preferably the same version of SW you are using. 2019 in my case)
When you need to understand more about a function or knowing its parameters or return values, search for the "Method" (or "Members" in other cases)
For example, let's say you don't need hole wizard, but linear pattern...
Go to the API Help and search for the "GetTypeName2" method.
When you find it, it's page will show how to use it, list some examples and make some remarks, including a list of the values you can use inside the quotes. In my example (linear pattern): "LocalLPattern"
i have no idea really :d looks like:
sets the SolidWorks render material? so the apperance that applys is just the basic standard whiteish color?
But how do you know all the shorts like HoleWzd? and how can i learn them?
Don't worry...
First, let me add that this code I put is not very neat.
It can and should be improved/organized
You will be able to do it when you learn to read where is what...
For example,
This line checks if the active model is a .sldprt file. If so, it runs whatever the code you put there
Otherwise,
if it is a assembly (.sldasm) do something else.
I said you could insert right after the swDocPART line, but that is not necessarily true, since you can have hole wizard both in parts and assembly. And when I said that, I was having only parts in mind. u know?
So, instead of just trusting me, try to learn reading the code, the instructions.
And test.
In other words: what would happen if you insert it right before
?
Third times the charm. got it working. if i only want to filter the cut extrude or fillet, do i only need to change out "HoleWzd" out of this:
line? if so, is there somewhere i can see all the different macro words for holewizard and cut extrude and so on?
im very new to macro is im having truble knowing exactly where to insert:
into:
tried a couple of things but no good result. but you have to place it after:
for it to work? sry for being so noobish
line 3
the "i" lights up
In which line?
Thank you for the answers, the first part works well but im having truble adding this second part of code to the doc. it just says "variable not defined".
To filter only the hole wizard features, you have to add this in the DocPart section