Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro - Tree Display 1

Status
Not open for further replies.

SBaugh

Mechanical
Mar 6, 2001
6,686
I tried to record a macro, then followed the process that I want the macro to do which is to change the tree display.

Turn on "Show Component Description"
Turn off "Show Component Confugration Names"
Turn off "Show Display State Names"

I need it to run for any assembly.

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim COSMOSWORKSObj As Object
Dim CWAddinCallBackObj As Object
Set CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks")
Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS
boolstatus = Part.Extension.SelectByID2("", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
StudyManagerObj = Nothing
ActiveDocObj = Nothing
Set CWAddinCallBackObj = Nothing
Set COSMOSWORKSObj = Nothing
End Sub

If fails on the
Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS
StudyManagerObj = Nothing
ActiveDocObj = Nothing

Then nothing happens... I have no clue about how macros are supposed to work if it doesn't record what I actually did and what I want it to repeat.

Any help would be appreciated

Scott Baugh, CSWP [pc2]
CAD Systems Manager
Dapco, INC

"If it's not broke, Don't fix it!"
faq731-376
 
Replies continue below

Recommended for you

That was my poor typing skills I think you are talking about. Here is the Code:

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim COSMOSWORKSObj As Object
Dim CWAddinCallBackObj As Object
Set CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks")
Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS
boolstatus = Part.Extension.SelectByID2("", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
StudyManagerObj = Nothing
ActiveDocObj = Nothing
Set CWAddinCallBackObj = Nothing
Set COSMOSWORKSObj = Nothing
End Sub

Scott Baugh, CSWP [pc2]
CAD Systems Manager
Dapco, INC

"If it's not broke, Don't fix it!"
faq731-376
 
Try the following codes (have not tested but should work for model files)

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager


Sub main()

Set swApp = Application.SldWorks
Set swModel= swApp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager

swFeatMgr.ShowComponentDescriptions = True
swFeatMgr.ShowComponentConfigurationNames = False
swFeatMgr.ShowDisplayStateNames = False

End Sub

Deepak Gupta
SOLIDWORKS Champion and Expert
SW 2022 SP0.0, 2021 SP5.1 and 2020 SP5.0
Boxer's SOLIDWORKS Blog


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor