Get and Set Connection Point Feature Data Example (VBA)
This example shows how to get and set data for connection point features.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Ensure that the latest SolidWorks Design Library is loaded.
' 2. Drag and drop design library > routing > electrical > db9 male.sldprt
' into the main view.
' 3. Run (F5) this macro.
' Postconditions:
' 1. Inspect the Immediate Window.
' 2. Inspect CPoint1 in the FeatureManager design tree.
'
' NOTE: Because this is a Design Library part, close it without saving changes.
'----------------------------------------------------------------------------
Dim swApp As SolidWorks.Application
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim selMgr As SldWorks.SelectionMgr
Dim selCount As Long
Dim selType As Long
Dim selObj As Object
Dim selFeat As SldWorks.Feature
Dim vLocation As Variant
Dim xLoc As Double, yLoc As Double, zLoc As Double
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set selMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("CPoint1", "CONNECTIONPOINT", 0, 0, 0, False, 0, Nothing, 0)
selCount = selMgr.GetSelectedObjectCount2(-1)
If (selCount > 0) Then
selType = selMgr.GetSelectedObjectType3(1, -1)
Set selObj = selMgr.GetSelectedObject6(1, -1)
If (selType = SwConst.swSelCONNECTIONPOINTS) Then
Set selFeat = selObj
End If
End If
Part.ClearSelection2 True
Dim featData As Object
Set featData = selFeat.GetDefinition()
Dim cPointData As SldWorks.ConnectionPointFeatureData
Set cPointData = featData
If Not cPointData Is Nothing Then
Debug.Print "Get stublength = " & cPointData.StubLength
cPointData.StubLength = 0.009
Debug.Print "Set stublength = " & cPointData.StubLength
Debug.Print "Get diameter = " & cPointData.RouteDiameter
cPointData.RouteDiameter = 0.011
Debug.Print "Set diameter = " & cPointData.RouteDiameter
Debug.Print "Get route type = " & cPointData.RouteType
cPointData.RouteType = 2
Debug.Print "Set route type = " & cPointData.RouteType
Debug.Print "Get route sub type = " & cPointData.RouteSubType
cPointData.RouteSubType = 3
Debug.Print "Set route sub type = " & cPointData.RouteSubType
Debug.Print "Get electrical Pin ID = " & cPointData.ElectricalPinID
cPointData.ElectricalPinID = "zxc"
Debug.Print "Set electrical Pin ID = " & cPointData.ElectricalPinID
Debug.Print "Get port ID = " & cPointData.PortID
cPointData.PortID = "newPortID"
Debug.Print "Set port ID = " & cPointData.PortID
Debug.Print "Get CPoint name = " & cPointData.Name2
cPointData.Name2 = "myCPoint"
Debug.Print "Set CPoint name = " & cPointData.Name2
vLocation = cPointData.Location
xLoc = vLocation(0)
yLoc = vLocation(1)
zLoc = vLocation(2)
Debug.Print "Get Location: " & xLoc & " " & yLoc & " " & zLoc
End If
Part.ForceRebuild3(false)
Set cPointData = Nothing
Set featData = Nothing
End Sub