Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SW API - FeatureManager GoTo?

Status
Not open for further replies.

pyroclasm

Computer
May 17, 2005
24
0
0
CA
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?

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
 
Replies continue below

Recommended for you

I would suggest keeping projects (related assemblies/parts/drawings) in one common folder. I recommend against braking projects up into subfolders. This can affect performance. It does open up the possible for file management issues (such as multiple copies of a part file existing on the hard drive, with one the wrong version being loaded). Also, doing this has created your issue in the first place. SolidWorks works best if you keep related files of a project in the same folder. Sorry if I'm not addressing your issue directly.

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
 
I believe pyroclasm was referring to organizing assembly components into folders in the assembly feature tree, not separate folders in the Windows structure. I could be wrong.
 
Hi fcsuper, sorry for the confusion. I was speaking about folders organized in SolidWorks Feature Manager.

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?
 
Go to the API help and go to FeatureManager::GetNextFeature. Click on "Example" and choose "Suppress or Unsuppress Feature Example". That should give you a good starting point. You're going to need to traverse the features in the feature tree looking for your string. When you find it, just select it. You may have to look at sub-features as well.
 
I see your need, the tree is causing
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.


 
Thanks guys, I found the code, but well...this more complicated than I thought it would be. I'll have to sit down and stare at the code later.

Yeah the feature manager tree does get pretty huge. So richardfoodindustrie, what do you mean "view mate command"?

Thanks again guys for responding.

Code:
Sub main()
    ' 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
 
Ok, I can't do it. I thought it would've been easier because Solidworks already did something like it. I thought I'd ask at least. I don't really need it, it is more like convenience. Man, I feel dumb with code. I guess I really gotta sit down and go through one of those VBA books.

Thanks anyways guys, I do appreciate the input.

Pyroclasm
 
I thought it would've been easier because Solidworks already did something like it.

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.
 
Status
Not open for further replies.
Back
Top