' ******************************************************************************
'NamingDimensions.swb - Macro Created on 08/31/04 by Sam White
'
'The User selects a dimension and runns the NamingDimensions macro to assign the
'dimension a signifikant letter L(Length), OD(Outer Diameter), ID (Inner Diameter)
'NamingDimensions also creates a Custom Propety with the same letter and a link
'to the dimension
'Assing three Macro buttons / hotkeys in SW and call the specifik Method(L,OD,ID)******************************************************************************
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim, swDimMem As SldWorks.Dimension
Dim swAnn As SldWorks.Annotation
Dim bRet As Boolean
Dim swSelMgr As SldWorks.SelectionMgr
Dim swEnt As SldWorks.entity
Dim swComp As SldWorks.Component2
Sub DimensionL()
Call Naming("L")
End Sub
Sub DimensionOD()
Call Naming("OD")
End Sub
Sub DimensionID()
Call Naming("ID")
End Sub
Public Sub Naming(Letter As String)
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Set swSelMgr = swModel.SelectionManager
Set swDispDim = swSelMgr.GetSelectedObject5(1)
'Check if the user really selected a dimension prior to running the macro
If swDispDim Is Nothing Then
swApp.SendMsgToUser "Select the dimension you want to assign the " & Letter & " before running the macro!"
End
End If
'Check so that there are no dimension already assigned to that letter
Set swDimMem = swDispDim.GetDimension
Do While Not swFeat Is Nothing
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Set swDispDim = swSubFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
Set swAnn = swDispDim.GetAnnotation
Set swDim = swDispDim.GetDimension
Set swDispDim = swSubFeat.GetNextDisplayDimension(swDispDim)
Loop
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
Set swDispDim = swFeat.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
Set swAnn = swDispDim.GetAnnotation
Set swDim = swDispDim.GetDimension
' If we find a dimension with that letter we activates that feature and then the dimension before we ends the macro
If swDim.Name = Letter Then
Set swFeat = swDim.GetFeatureOwner
swApp.SendMsgToUser "A dimension named " & Letter & " already exist in " & swFeat.Name & "! " & Chr(10) & "Solve this problem before running the macro"
swModel.SelectByID swFeat.Name, "BODYFEATURE", 0, 0, 0
swModel.SelectByID swFeat.Name, "SKETCH", 0, 0, 0
swModel.ActivateSelectedFeature
swModel.SelectByID swDim.FullName, "DIMENSION", 0, 0, 0
End
End If
Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
Loop
Set swFeat = swFeat.GetNextFeature
Loop
'If we got through the tests we assign the dimension the letter and creates the custom property
swDimMem.Name = Letter
swModel.AddCustomInfo3 "", Letter, swCustomInfoText, Chr(34) & swDimMem.FullName & Chr(34)
End Sub