Hide Table of Contents

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. Observe CPoint1 in the FeatureManager design tree.
' 4. Run (F5) this macro.
' Postconditions:
'  1. Inspect the Immediate Window.
'  2. CPoint1 is now MyCPoint 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 vDirection As Variant
    Dim xDir As Double, yDir As Double, zDir 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

        vDirection = cPointData.Direction
        xDir = vDirection(0)
        yDir = vDirection(1)
        zDir = vDirection(2)
        Debug.Print "Get direction vector: " & xDir & " " & yDir & " " & zDir

    End If


    Set cPointData = Nothing
    Set featData = Nothing
End Sub

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Get and Set Connection Point Feature Data Example (VBA)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2013 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.