Hide Table of Contents

Create Reference Curve Example (VBA)

This example shows how to create a reference curve by first creating a temporary spline curve.

 

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

'

' Preconditions: A part is open.

'

' Postconditions: A reference curve is added to the part.

'

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

Option Explicit

 

' Type definition

Type DoubleRec

    dValue      As Double

End Type

Type Int2Rec

    iLower      As Long      ' One Integer is 4 bytes

    iUpper      As Long

End Type

 

' From 2 Integer to 1 Double

Function ImportFields(iLower As Integer, iUpper As Integer, dValue As Double)

    Dim dr                          As DoubleRec

    Dim i2r                         As Int2Rec

    i2r.iLower = iLower

    i2r.iUpper = iUpper

    LSet dr = i2r

    dValue = dr.dValue

End Function

 

Sub main()

 

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swPart                      As SldWorks.PartDoc

    Dim swBody                      As SldWorks.Body2

    Dim swCurve(0)                  As SldWorks.Curve

    Dim vCurve                      As Variant

    Dim swRefCurve                  As SldWorks.ReferenceCurve

    

    Dim bRet                        As Boolean

    Dim nRetVal                     As Long

    Dim iDim                        As Integer

    Dim iOrd                        As Integer

    Dim incp                        As Integer

    Dim iper                        As Integer

    

    Dim dprops(1)                   As Double

    Dim knots(9)                    As Double

    Dim cPoints(17)                 As Double

    

    Dim vprops                      As Variant

    Dim vknots                      As Variant

    Dim vcPoints                    As Variant

    

    

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

    Set swBody = swPart.CreateNewBody

    

    

    ' Create a simple test curve

    

    ' Set properties

    iDim = 3: iOrd = 4: incp = 6: iper = 0

    ImportFields iDim, iOrd, dprops(0)

    ImportFields incp, iper, dprops(1)

    vprops = dprops

    

    ' Set knots

    knots(0) = 0: knots(1) = 0: knots(2) = 0: knots(3) = 0

    knots(4) = 0.33096: knots(5) = 0.72

    knots(6) = 1: knots(7) = 1: knots(8) = 1: knots(9) = 1

    vknots = knots

    

    ' Set control points

    cPoints(0) = 0: cPoints(1) = 0: cPoints(2) = 0

    cPoints(3) = 0.008703: cPoints(4) = 0.016501: cPoints(5) = 0

    cPoints(6) = 0.027636: cPoints(7) = 0.052399: cPoints(8) = 0

    cPoints(9) = 0.069472: cPoints(10) = -0.011297: cPoints(11) = 0

    cPoints(12) = 0.090421: cPoints(13) = 0.017622: cPoints(14) = 0

    cPoints(15) = 0.099188: cPoints(16) = 0.029725: cPoints(17) = 0

    vcPoints = cPoints

    

    ' Create a spline Curve

    Set swCurve(0) = swBody.AddProfileBspline((vprops), (vknots), (vcPoints))

    vCurve = swCurve

    

    ' Create a ReferenceCurve

    Set swRefCurve = swModel.FeatureReferenceCurve(1, (vCurve), True, "", nRetVal)

    

    ' Rebuild to display curve

    swModel.EditRebuild3

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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Reference Curve Example (VBA)
*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) 2010 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.