SW API - FeatureManager GoTo?
SW API - FeatureManager GoTo?
(OP)
Hey guys, in large assemblys we put our components and such in folders. So I usually right-click and choose GoTo and do a search for my folder. Is there a way to make that into a button. I tried recording the macro and assigning it to a button, but something must be wrong with the code. Anyone know how to do this?
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("CONTROL MATES", "FTRFOLDER", 0, 0, 0, False, 0, Nothing, 0)
End Sub
CODE
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("CONTROL MATES", "FTRFOLDER", 0, 0, 0, False, 0, Nothing, 0)
End Sub






RE: SW API - FeatureManager GoTo?
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
http://sw.fcsuper.com/index.php
RE: SW API - FeatureManager GoTo?
RE: SW API - FeatureManager GoTo?
RE: SW API - FeatureManager GoTo?
Thanks dgowans and TheTick.
Hmmm, macro recording is kinda limited. :P
Can anyone point me to the right Method for this. I looked in the Help Doc under ModelDoc and AssembyDoc but can't seem to find something that does the same action. Such as searching the FeatureManager Tree for a specific word and then placing that Folder/Component/Feature at the top of the FeatureManager Tree View.
I would like to have it be a button that I can click and use to select this folder in the FeatureManager. I'm placing specific Mates in this folder that I use often to manipulate the Assembly.
Can anyone point me in the right direction?
RE: SW API - FeatureManager GoTo?
RE: SW API - FeatureManager GoTo?
far too much Scrollworks in Solidworks.
This only has gotten worse the last years
as more (unnecessairy) information gets
into the tree every release that needs to
be scrolled away.
I also have been trying to do this for the
rightmouse view mate command but with no luck.
I rather have a programmable shortcut for the
view mate command instead of a right mousebutton
and then go to the view mate command.
RE: SW API - FeatureManager GoTo?
Yeah the feature manager tree does get pretty huge. So richardfoodindustrie, what do you mean "view mate command"?
Thanks again guys for responding.
CODE
' Variable used to hold the SldWorks object
Dim swApp As Object
' Variable used to hold the ModelDoc object
Dim Model As Object
' Variable used to hold the current Feature object
Dim feat As Object
Dim featureName As String
' These definitions are consistent with type names
Const swDocPART = 1
' Constant enumerators
Const swDocASSEMBLY = 2
Const swDocDRAWING = 3
Set swApp = CreateObject("SldWorks.Application")
' Attach to the active document
Set Model = swApp.ActiveDoc
' Exit if no model is active
If Model Is Nothing Then
Exit Sub
End If
' Do not allow drawings or assemblies
If (Model.GetType <> swDocPART) Then
' Define message
Msg = "Only Allowed on Parts"
' OK Button only
Style = vbOKOnly
' Define title
Title = "Error"
' Display error message
Call MsgBox(Msg, Style, Title)
' Exit this program
Exit Sub
End If
' Get the 1st feature in part
Set feat = Model.FirstFeature
' While we have a valid feature
Do While Not feat Is Nothing
' Get the name of the feature
Let featureName = feat.Name
' See if the feature name contains our search string
If InStr(1, featureName, SearchStr, 1) Then
' Select the feature
res = Model.SelectByID(featureName, "BODYFEATURE", 0, 0, 0)
If (Action = "Suppress") Then ' User chose to suppress
res = Model.EditSuppress() ' Suppress the feature
ElseIf (Action = "Unsuppress") Then ' User chose to unsuppress
res = Model.EditUnsuppress() ' Unsuppress the feature
End If
End If
Set feat = feat.GetNextFeature() ' Get the next feature
Loop ' Continue until no more features exist
End Sub
RE: SW API - FeatureManager GoTo?
Thanks anyways guys, I do appreciate the input.
Pyroclasm
RE: SW API - FeatureManager GoTo?
That's one tricky thing about API. While it's pretty powerful in that you can make it do just about anything, it takes a while to learn your way around. And just because something is easy to do manually doesn't mean it's easy to do with API.