Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Dimension Length of 3D Spline

Status
Not open for further replies.

sdb999

Mechanical
May 1, 2003
96
Does anyone know how to dimension the length of a 3D spline? I can measure it, but ultimately I'd like to populate a custom property with it.
thanks.
 
Replies continue below

Recommended for you

Give the following macro a whirl. I just found it in a thread in the SW Discussion Forum but haven't had chance to try it.

Code:
'JHILL 1/22/07 SW 2006 SP5.0
'this macro traverses throught the configurations of a part file
'and gets the length of the specified 3D spline given and then
'places the value returned into a custom property cell call "Length"
'
'requirements:
'a) a solidoworks part file is open
'b) a spline with the name specified exists
'
'notes:
'change the sSplineName and sCustPropName below to suit your needs
'(excuse the amount of extra detail in the notes...I included them for those who may not be familiar with VBA and SW API)

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfig As SldWorks.Configuration
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSketchSegment As SldWorks.SketchSegment
Dim sSplineName As String
Dim length As Double
Dim sLength As String
Dim vNameArr As Variant
Dim vName As Variant
Dim boolstatus As Boolean
Dim DoNextPart As String
Dim lSaveAsOptions As Long
Dim sCustPropName As String
Dim longerrors As Long
Dim longwarnings As Long
Dim vConfNames As Variant
Dim sConfName As String
Dim sConfDesc As String
Dim nStart As Single
Dim i As Long


Sub main()

'set the name of your 3D Spline here
sSplineName = "Spline1@3DSketchPath"
'set the name of the custom property here, if it does not exist, it will be created
sCustPropName = "Length"

'set a pointer to the application object
Set swApp = Application.SldWorks
'get the currently active document
Set swModel = swApp.ActiveDoc
'check to see if a document is loaded
If (swModel Is Nothing) Then
MsgBox " No document is open"
Exit Sub
End If
'set a pointer to the selection manager
Set swSelMgr = swModel.SelectionManager
'get the document type, make sure it is the right document type
'I use this as a generic filter to trap macros being applied to wrong file types
Select Case swModel.GetType
Case Is = 1 'part

Case Is = 2 'assembly
MsgBox " Open document is not the correct type for this operation"
Exit Sub
Case Is = 3 'drawing
MsgBox " Open document is not the correct type for this operation"
Exit Sub
Case Else 'not a SW document
MsgBox " Open document is not valid"
Exit Sub
End Select
'get a list of the configuration names
vConfNames = swModel.GetConfigurationNames
'set the timer, I use this to see how long a macro takes to parse through all configurations
nStart = Timer
'loop through each configuration
For i = 0 To UBound(vConfNames)
'get the current configuration name
sConfName = vConfNames(i)
'set and show the active configuration
boolstatus = swModel.ShowConfiguration2(sConfName)
If boolstatus = False Then
MsgBox " Configuration not activated successfully " & sConfName
End If
'show the current active configuration
swModel.ShowConfiguration sConfName
'rebuild features that need a rebuild if any
boolstatus = swModel.EditRebuild3()
If boolstatus = False Then
MsgBox " Configuration rebuild error" & sConfName
End If
'force a rebuild whether needed or not, true=top level assm only, false all sub assm
DoNextPart = "N"
If DoNextPart = "Y" Then
boolstatus = swModel.ForceRebuild3(False)
If boolstatus = False Then
MsgBox " Configuration rebuild error" & sConfName
End If
End If
'after rebuilds, get the active configuration
Set swConfig = swModel.GetActiveConfiguration

'select the 3D spline to measure, get the length in meters, convert to inches, round to three places
boolstatus = swModel.Extension.SelectByID2(sSplineName, "EXTSKETCHSEGMENT", 0, 0, 0, True, 0, Nothing, 0)
If boolstatus = False Then
MsgBox " 3D Spline not selected successfully " & sConfName
Exit Sub
End If
Set swSketchSegment = swSelMgr.GetSelectedObject6(1, -1)
length = swSketchSegment.GetLength
length = length * 39.37007874016
length = Round(length, 3)

'get a list of the custom properties for this configuration
vNameArr = swModel.GetCustomInfoNames2(sConfName)

'check the list for a custom property named sCustPropName, if it exists update the value
DoNextPart = "Y"
For Each vName In vNameArr
If vName = sCustPropName Then
swModel.CustomInfo2(sConfName, sCustPropName) = length
DoNextPart = "N"
End If
Next vName

'if no custom property with matching name was found then
If DoNextPart = "Y" Then
boolstatus = swModel.AddCustomInfo3(sConfName, sCustPropName, swCustomInfoNumber, length)
If boolstatus = False Then
MsgBox " Custom configuration property not added successfully " & sConfName
Exit Sub
End If
End If

'save the document after editing configuration?
DoNextPart = "Y"
If DoNextPart = "Y" Then
'set the save options
lSaveAsOptions = 0
'swSaveAsOptions_e bitmask options list
'swSaveAsOptions_Silent
'swSaveAsOptions_Copy
'swSaveAsOptions_SaveReferenced \\Supports parts, assemblies, and drawings. This setting indicates to save all components (sub-assemblies and parts) in both assemblies and drawings. If a part has an external reference, then this setting indicates to save the external reference.
'swSaveAsOptions_AvoidRebuildOnSave
'swSaveAsOptions_UpdateInactiveViews \\ Not a valid option for PartDoc::SaveToFile2. This setting is only applicable for a drawing that has one or more sheets. This setting updates the views on inactive sheets.
'swSaveAsOptions_OverrideSaveEmodel \\Saves eDrawings-related information into a section of the file being saved. Specifying this setting overrides the Tools, Options, System Options, General, Save eDrawings data in SolidWorks document setting. Not a valid option for PartDoc::SaveToFile2.
'swSaveAsOptions_SaveEmodelData \\Not a valid option for PartDoc::SaveToFile2
'swSaveAsOptions_DetachedDrawing \\Not a valid option for PartDoc::SaveToFile2

'do you want to return errors found during save3 method?
DoNextPart = "Y"
If DoNextPart = "Y" Then
longerrors = 0
longwarnings = 0
Else
longerrors = Null
longwarnings = Null
End If

'save the document
'retval = ModelDoc2.Save3 ( Options, &Errors, &Warnings )
boolstatus = swModel.Save3(lSaveAsOptions, longerrors, longwarnings)

'check for a save error(s)?
'DoNextPart = "Y"
If DoNextPart = "Y" Then
If boolstatus = False Then
'get the error
MsgBox " Save Error: " & "Long Error = " & longerrors
End If
End If
'check for long warnings?
'DoNextPart = "Y"
If DoNextPart = "Y" Then
If longwarnings <> 0 Then
'get the error
MsgBox " Save Error: " & "Long Warnings = " & longwarnings
' 1 swFileSaveWarning_RebuildError
' 2 swFileSaveWarning_NeedsRebuild
' 4 swFileSaveWarning_ViewsNeedUpdate
' 8 swFileSaveWarning_AnimatorNeedToSolve
'16 swFileSaveWarning_AnimatorFeatureEdits
'32 swFileSaveWarning_EdrwingsBadSelection
End If
End If
End If

Next i

MsgBox " Setting of 3D Spline length completed" & " Time = " & Timer - nStart & " s"

End Sub

[cheers]
 
Also, there used to be a little add-in application floating around called Spliner. Search it and you might still find it. (I don't have it installed currently, so I'm not sure how well it works with newer versions of SW).



Jeff Mowry
A people who value security over freedom will soon find they have neither.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor