What do you want to do with that selection? There might be other ways to do what you are looking for?
Well, the effect of my Add-in is:
In Assembly Documents:
When the user selects a part or sub assembly (through the design tree or the model view)
And Changes a specific custom property, it causes the Part/SubAssembly to Change colour
In Part Documents:
The Same thing is happening, the user has to manually select the part in the design tree
but its kind of pointless to make the user select the part when
... there is only one selection to make
(also, I've just found the shortcut key to reply)
Not sure if this is equivalent to select the top item in the feature tree (which I so far have failed to do with API... but there must be a way...)
This code selects the component (part). Sampling around shows that the selection manager states that the code below returns the same type of selected object as if it was manually selected by user. Give it a try with you other code to see if it works for parts....
Note that the top item in the feature tree is not marked/highlighted as if it was selected manually.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim bRetVal As Boolean
Dim FileName As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
bRetVal = swModel.Extension.SelectByID2(FileName, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Debug.Print swSelMgr.GetSelectedObjectType3(1, -1) '20 = component
Awesome, worked a treat.
1 person found this helpful
As an option, you can set colour to a part with this method: 2014 SolidWorks API Help - MaterialPropertyValues Property (IPartDoc) .
To use that you could add a If or Select case statement and depending on document type you call differnet code for assembly and part to set the colour.
I do not know you application but just wanted to think out loud...
I've actually already been using the "MaterialPropertyValues Property" in conjunction with a 'select case'
but that "SetMaterialVisualProperties" could also prove useful.