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
' 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