Linear Pattern Feature Help

Discussion in 'SolidWorks' started by j.eric.hunt, Aug 2, 2007.

  1. j.eric.hunt

    j.eric.hunt Guest

    So I'm new to API type stuff and I'm trying to create a UI to be able
    to enter the information for creating planes, linear patterns and
    circular patterns. Eventually I also would like to be able to change
    dimension values of the sketch/body I'm patterning, change the color
    on certain pieces as well as print out 1:1 drawings of the whole part
    but first things first.
    I've tried to isolate down to learning how to just create a linear
    pattern with the desired number of instances and spacing being entered
    by the user. I think my problem may be in not having my solidbody
    selected but I'm generally confused at what commands I need to use and
    which ones I don't. So far it seems as if what code you include is
    arbitrary. But anyway here is my code so far, any help would be
    greatly appreciated and a thorough explanation so that I make sure I
    learn it and can implement it again. Don't think anything is too
    elementary to mention as chances are I might not know it. Also I have
    tried various combinations for the Linear Pattern Feature call and
    haven't figured what I need, so that is why I have the Dim LinearPat1...
    and why right now the Part.FeatureManager.FeatureLinearPattern2 is not
    equal to anything,

    I got some of this code from the API tutorial and other from the help
    topics.



    Option Explicit
    Dim SwApp As SldWorks.SldWorks
    Dim Part As SldWorks.ModelDoc2
    Dim boolstatus As Boolean
    Dim Instance As Double
    Dim Spacing As Double
    Dim BodyInstance As Double
    Dim BodySpacing As Double
    Dim LinearPat1 As ModelDoc2

    Sub main()

    ' Connect to currently active SolidWorks document
    Set SwApp = Application.SldWorks

    Set Part = SwApp.ActiveDoc
    ' Create an instance of the user form
    Dim myForm As New frmLinearArray

    ' Set the caption for the form
    myForm.Caption = "Instances and Spacing"


    ' Display the user form and retrieve instance and spacing values
    entered by users
    ' Divide the values by 1000 to change millimeters to meters
    myForm.Show
    BodyInstance = myForm.Instance / 1000
    BodySpacing = myForm.Spacing / 1000

    'Destroy the user form and remove it from memory because it is no
    longer needed
    Set myForm = Nothing

    Part.FeatureManager.FeatureLinearPattern2(BodyInstance, BodySpacing,
    1, 0, False, False, "Null", "NULL", False)
    End Sub


    This is the code for my form that includes two text boxes and a
    command button

    Public Spacing As Double
    Public Instance As Double
    Private Sub CommandButton1_Click()
    ' Make sure that the text in the two text boxes on the
    ' form, txtInstance and txtSpacing, is numerical
    If IsNumeric(txtInstance.Text) And IsNumeric(txtSpacing.Text) Then
    Instance = txtInstance.Text
    Spacing = txtSpacing.Text
    ' Close the dialog box and continue
    Hide
    Else
    ' Display a message box telling users to enter numerical
    ' values for both depth and radius
    MsgBox "You must enter numeric values for both Instance and Spacing."
    End If

    End Sub
     
    j.eric.hunt, Aug 2, 2007
    #1
  2. j.eric.hunt

    j.eric.hunt Guest

    So I got my code to this stage but I still need help, I need to select
    the solid bofy for the bodies to pattern part of the linear pattern

    '---------------------------------------------
    '
    ' Preconditions:
    ' (1) Chain Part document is open.
    ' (2) Extrude1(SolidBody) and Axis1 exist to pattern.
    '
    ' Postconditions: Linear Pattern feature created.
    '
    '---------------------------------------------


    '
    ******************************************************************************
    ' C:\DOCUME~1\ehunt\LOCALS~1\Temp\swx3564\Macro1.swb - macro recorded
    on 08/02/07 by ehunt
    '
    ******************************************************************************
    Option Explicit
    Dim SwApp As SldWorks.SldWorks
    Dim Part As SldWorks.ModelDoc2
    Dim boolstatus As Boolean
    'Dim SelectedObject As Object
    Dim Instance As Double
    Dim Spacing As Double
    Dim BodyInstance As Double
    Dim BodySpacing As Double
    Dim Model As ModelDoc2
    Dim bRet As Boolean
    Dim swPattern As SldWorks.LinearPatternFeatureData
    Dim swFeat As SldWorks.Feature
    Dim swModel As SldWorks.ModelDoc


    Sub main()

    ' Connect to currently active SolidWorks document
    Set SwApp = Application.SldWorks

    Set Part = SwApp.ActiveDoc
    ' Create an instance of the user form
    Dim myForm As New frmLinearArray

    ' Set the caption for the form
    myForm.Caption = "Instances and Spacing"


    ' Display the user form and retrieve radius and depth values entered
    by users
    ' Divide the values by 1000 to change millimeters to meters
    myForm.Show
    BodyInstance = myForm.Instance
    BodySpacing = myForm.Spacing / 1000

    'Destroy the user form and remove it from memory because it is no
    longer
    ' needed
    Set myForm = Nothing

    ' Select axis to use for axis
    boolstatus = Part.Extension.SelectByID2("Axis1", "AXIS", 0#, 0#, 0#,
    True, _
    1, Nothing, swSelectOptionDefault) ': Debug.Assert boolstatus

    ' Select the body named "Solid Body<1>"

    boolstatus = Part.Extension.SelectByID2("", "SOLIDBODY", _
    4, 0, 0, True, 0, Nothing, swSelectOptionDefault)

    Part.FeatureManager.FeatureLinearPattern2 BodyInstance, _
    BodySpacing, 1, 0, False, False, "Null", "NULL", False



    End Sub
     
    j.eric.hunt, Aug 6, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.