Hide Table of Contents

Get DimXpert Intersect Features Example (VB.NET)

This example shows how to build a part and get attributes for the following DimXpert features:

 

    *  Intersect Point

    *  Intersect Line

    *  Intersect Circle

    *  Intersect Plane

'---------------------------------------------------------------------------

' Preconditions:

' 1. Open: <SolidWorks_install_dir>\samples\tutorial\api\face_plate_ads_geo.sldprt

' 2. Open the DimXpert toolbar from View > Toolbars (select the first instance of Toolbars on the View menu).

' 3. Create an Intersect Point DimXpert Feature:

'    a. Click the Location Dimension icon on the DimXpert toolbar.

'    b. Select the front face of the part.

'    c. Select the Create Intersection Point icon from the DimXpert pop-up menu.

'    d. Select a cylinder whose axis intersects the first face at a point.

'    e. Click the green check mark in the pop-up menu to create the

'       intersect point.

'    f. Select a feature on the part to dimension against the intersect point.

'    g. Click away from the part to position the dimension in the view.

'    h. Observe the new DimXpert feature on the DimXpertManager tab:  

'       Intersect Point1

' 4. Create an Intersect Line DimXpert Feature:

'    a. Click the Location Dimension icon on the DimXpert toolbar.

'    b. Select the front face of the part.

'    c. Select the Create Intersection Line icon from the DimXpert pop-up menu.

'    d. Select a perpendicular plane that would intersect the first plane

'       if extended (e.g., a top or side face of the part)

'    e. Click the green check mark in the pop-up menu to create the

'       intersect line.

'    f. Select a feature on the part to dimension against the intersect line.

'    g. Click away from the part to position the dimension in the view.

'    h. Observe the new DimXpert feature on the DimXpertManager tab:  

'       Intersect Line1

' 5. Create an Intersect Circle DimXpert Feature:

'    a. Click the Size Dimension icon on the DimXpert toolbar.

'    b. Select the front face of the part.

'    c. Select the Intersect Circle icon from the DimXpert pop-up menu.

'    d. Select the opening conical surface of a flat head machine screw

'      (LPattern1 or LPattern3) in the part.

'    e. Click the green check mark in the pop-up menu to finish the dimension.

'    f. Click away from the part to position the size dimension in the view.

'    g. Observe the new DimXpert feature on the DimXpertManager tab:  

'       Intersect Circle1

' 6. Create an Intersect Plane DimXpert Feature:

'    a. Click the Location Dimension icon on the DimXpert toolbar.

'    b. Zoom in on a flat head machine screw (LPattern1 or LPattern3).

'    c. Select the opening conical surface of a flat head machine screw

'       in the part.

'    d. Select the Intersect Plane icon from the DimXpert pop-up menu.

'    e. Select the inner cylindrical bore face of the flat head machine screw.

'    f. Click the green check mark in the pop-up menu to create the

'       intersect plane.

'    g. Select the top face of one of the extruded entities.

'    h. Click away from the part to position the location dimension in the view.

'    i. Observe the new DimXpert feature on the DimXpertManager tab:  

'       Intersect Plane1

' 7. Open an Immediate Window in the IDE.

' 8. Ensure that the latest SolidWorks.Interop.swdimxpert.dll interop

'    assembly is loaded (right-click on project in Project Explorer,

'    click Add Reference, and click .NET tab).

' 9. Run this macro (F5).

'

' Postconditions: Compare the output in the Immediate Window

' with the features displayed on the DimXpertManager tab of the Management Panel.

' NOTE: Because this part is used in a SolidWorks online tutorial,

' do not save any changes when you close it.

'----------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swdimxpert

Imports SolidWorks.Interop.swconst

Imports System

Imports System.Diagnostics

Partial Class SolidWorksMacro

    

    Dim swModel As IModelDoc2

    Dim swModelDocExt As IModelDocExtension

    Dim swSelMgr As ISelectionMgr

    Dim swConfig As IConfiguration

    Dim swFeature As IFeature

    Dim swAnn As IFeature

    Dim swSchema As IDimXpertManager

    Dim swDXPart As IDimXpertPart

    Dim featureType As swDimXpertFeatureType_e

    Dim features As Object

    Dim appliedFeatures As Object

    Dim appliedAnnotations As Object

    Dim appliedAnnotation As IDimXpertAnnotation

    Dim feature As IDimXpertFeature

    Dim feature1 As IDimXpertFeature

    Dim feature2 As IDimXpertFeature

    Dim appliedFeature As IDimXpertFeature

    Dim msgStr As String

    Dim msgStr2 As String

    Dim msgStr3 As String

    Dim msgStr4 As String

    Dim n As Long

    Dim o As Long

    Dim p As Long

    Dim x As Double

    Dim y As Double

    Dim z As Double

    Dim i As Double

    Dim j As Double

    Dim k As Double

    Dim radius As Double

    Dim boolstatus As Boolean

    Sub main()

        swModel = swApp.ActiveDoc

        swModelDocExt = swModel.Extension

        swSelMgr = swModel.SelectionManager

        ' Get the default DimXpert schema using IModelDocExtension.DimXpertManager()

        swSchema = swModelDocExt.DimXpertManager("Default", True)

        ' Get IDimXpertPart from the IDimXpertManager

        swDXPart = swSchema.DimXpertPart

        Dim featCount As Long

        featCount = swDXPart.GetFeatureCount

        msgStr = "Total of "

        msgStr2 = featCount

        msgStr = msgStr + msgStr2 + " DimXpert features in " + (swSchema.SchemaName)

        Debug.Print("")

        Debug.Print(msgStr)

        ' Get IDimXpert features through IDimXpertPart

        features = swDXPart.GetFeatures

        msgStr = (swSchema.SchemaName) + " has the following features: "

        Debug.Print("")

        Debug.Print(msgStr)

        For n = 0 To UBound(features)

            feature = features(n)

            Debug.Print("  " + "Feature name: " + (feature.Name))

            featureType = feature.Type

            Call GetPatternType(featureType, msgStr2)

            msgStr = "     Feature type "

            msgStr3 = " is suppressed on the DimXpertManager tab? "

            msgStr4 = feature.IsSuppressed()

            Debug.Print(msgStr + msgStr2 + msgStr3 + msgStr4)

            msgStr = "     " + "Model feature: "

            swFeature = feature.GetModelFeature()

            If Not (swFeature Is Nothing) Then

                msgStr2 = swFeature.GetTypeName2()

                Debug.Print(msgStr + msgStr2)

            End If

            msgStr = "     " + "Number of SolidWorks face entities in this feature: "

            msgStr2 = feature.GetFaceCount

            Debug.Print(msgStr + msgStr2)

            msgStr = "     " + "Number of applied features: "

            msgStr2 = feature.GetAppliedFeatureCount()

            Debug.Print(msgStr + msgStr2)

            appliedFeatures = feature.GetAppliedFeatures()

            If Not (IsNothing(appliedFeatures)) Then

                For o = 0 To UBound(appliedFeatures)

                    appliedFeature = appliedFeatures(o)

                    Debug.Print("        " + "Applied feature name: " + (appliedFeature.Name))

                Next

            End If

            msgStr = "     " + "Number of applied annotations: "

            msgStr2 = feature.GetAppliedAnnotationCount()

            Debug.Print(msgStr + msgStr2)

            appliedAnnotations = feature.GetAppliedAnnotations()

            If Not (IsNothing(appliedAnnotations)) Then

                For p = 0 To UBound(appliedAnnotations)

                    appliedAnnotation = appliedAnnotations(p)

                    Debug.Print("        " + "Applied annotation name: " + (appliedAnnotation.Name))

                Next

            End If

            Debug.Print("     ")

        Next

        ' If you know the name of a DimXpert feature, you can get it directly using IDimXpertPart.GetFeature("name"),

        ' which can return a general IDimXpertFeature or a more specific interface on the feature

 

        ' Get IDimXpertIntersectCircleFeature for the Intersect Circle1 feature

        Dim iCircleFeature As IDimXpertIntersectCircleFeature

        iCircleFeature = swDXPart.GetFeature("Intersect Circle1")

        msgStr = iCircleFeature.Name + " is a DimXpert intersect circle feature"

        Debug.Print("")

        Debug.Print(msgStr)

        ' Get the nominal circle parameters

        boolstatus = iCircleFeature.GetNominalCircle(radius, x, y, z, i, j, k)

        If boolstatus Then

            msgStr = "   The nominal circle has the following parameters:"

            Debug.Print(msgStr)

            msgStr = "      Radius is "

            msgStr2 = radius

            Debug.Print(msgStr + msgStr2)

            msgStr = "      x-coordinate is "

            msgStr2 = x

            Debug.Print(msgStr + msgStr2)

            msgStr = "      y-coordinate is "

            msgStr2 = y

            Debug.Print(msgStr + msgStr2)

            msgStr = "      z-coordinate is "

            msgStr2 = z

            Debug.Print(msgStr + msgStr2)

            msgStr = "      i-component of pierce vector is "

            msgStr2 = i

            Debug.Print(msgStr + msgStr2)

            msgStr = "      j-component of pierce vector is "

            msgStr2 = j

            Debug.Print(msgStr + msgStr2)

            msgStr = "      k-component of pierce vector is "

            msgStr2 = k

            Debug.Print(msgStr + msgStr2)

        End If

        ' Get IDimXpertIntersectLineFeature for the Intersect Line1 feature

        Dim iLineFeature As IDimXpertIntersectLineFeature

        iLineFeature = swDXPart.GetFeature("Intersect Line1")

        msgStr = iLineFeature.Name + " is a DimXpert intersect line feature"

        Debug.Print("")

        Debug.Print(msgStr)

        ' Get the nominal line parameters

        boolstatus = iLineFeature.GetNominalLine(x, y, z, i, j, k)

        If boolstatus Then

            msgStr = "   The nominal line has the following parameters:"

            Debug.Print(msgStr)

            msgStr = "      x-coordinate is "

            msgStr2 = x

            Debug.Print(msgStr + msgStr2)

            msgStr = "      y-coordinate is "

            msgStr2 = y

            Debug.Print(msgStr + msgStr2)

            msgStr = "      z-coordinate is "

            msgStr2 = z

            Debug.Print(msgStr + msgStr2)

            msgStr = "      i-component of pierce vector is "

            msgStr2 = i

            Debug.Print(msgStr + msgStr2)

            msgStr = "      j-component of pierce vector is "

            msgStr2 = j

            Debug.Print(msgStr + msgStr2)

            msgStr = "      k-component of pierce vector is "

            msgStr2 = k

            Debug.Print(msgStr + msgStr2)

        End If

        ' Get IDimXpertIntersectPlaneFeature for the Intersect Plane1 feature

        Dim iPlaneFeature As IDimXpertIntersectPlaneFeature

        iPlaneFeature = swDXPart.GetFeature("Intersect Plane1")

        msgStr = iPlaneFeature.Name + " is a DimXpert intersect plane feature"

        Debug.Print("")

        Debug.Print(msgStr)

        ' Get the two features used to construct the intersect plane

        boolstatus = iPlaneFeature.GetFeatures(feature1, feature2)

        msgStr = "   The plane intersects the following DimXpert features:"

        Debug.Print(msgStr)

        msgStr = "      Feature1 is "

        msgStr2 = feature1.Name

        Debug.Print(msgStr + msgStr2)

        msgStr = "      Feature2 is "

        msgStr2 = feature2.Name

        Debug.Print(msgStr + msgStr2)

        ' Get IDimXpertIntersectPointFeature for the Intersect Point1 feature

        Dim iPointFeature As IDimXpertIntersectPointFeature

        iPointFeature = swDXPart.GetFeature("Intersect Point1")

        msgStr = iPointFeature.Name + " is a DimXpert intersect point feature"

        Debug.Print("")

        Debug.Print(msgStr)

        ' Get the nominal point

        boolstatus = iPointFeature.GetNominalPoint(x, y, z)

        If boolstatus Then

            msgStr = "   The nominal point has the following parameters:"

            Debug.Print(msgStr)

            msgStr = "      x-coordinate is "

            msgStr2 = x

            Debug.Print(msgStr + msgStr2)

            msgStr = "      y-coordinate is "

            msgStr2 = y

            Debug.Print(msgStr + msgStr2)

            msgStr = "      z-coordinate is "

            msgStr2 = z

            Debug.Print(msgStr + msgStr2)

        End If

    End Sub

    Public Sub GetPatternType(ByRef featureType As swDimXpertFeatureType_e, ByRef msgStr2 As String)

        If (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Plane) Then

            msgStr2 = "Plane"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Cylinder) Then

            msgStr2 = "Cylinder"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Cone) Then

            msgStr2 = "Cone"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Extrude) Then

            msgStr2 = "Extrude"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Fillet) Then

            msgStr2 = "Fillet"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Chamfer) Then

            msgStr2 = "Chamfer"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_CompoundHole) Then

            msgStr2 = "CompoundHole"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_CompoundWidth) Then

            msgStr2 = "CompoundWidth"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_CompoundNotch) Then

            msgStr2 = "CompoundNotch"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_CompoundClosedSlot3D) Then

            msgStr2 = "CompoundClosedSlot3D"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_IntersectPoint) Then

            msgStr2 = "IntersectPoint"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_IntersectLine) Then

            msgStr2 = "IntersectLine"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_IntersectCircle) Then

            msgStr2 = "IntersectCircle"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_IntersectPlane) Then

            msgStr2 = "IntersectPlane"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Pattern) Then

            msgStr2 = "Pattern"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Sphere) Then

            msgStr2 = "Sphere"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_BestfitPlane) Then

            msgStr2 = "Bestfit Plane"

        ElseIf (featureType = swDimXpertFeatureType_e.swDimXpertFeature_Surface) Then

            msgStr2 = "Surface"

        End If

    End Sub

   

    Public swApp As SldWorks

End Class



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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get DimXpert Intersect Features Example (VB.NET)
*Comment:  
*   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:

x

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
x

Web Help Content Version: API Help (English only) 2012 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.