ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
SPSanjay Phadke24/07/2012

I tried to write a code in vb for creating new line style

but it is not working

Solidworks does not create line other than formatting key A or B

def = "B,1.2,-0.2,2,-0.1,2" or

def = "A,1.2,-0.2,2,-0.1,2"

I want to create line style as below

-----o------o------o-----o------o

-----//------//------//----//-----//------

Pls guide me for the same

-Sanjay

example in api help given as below - I tried with this example but I am unable to acieve the new line style I want

Sub main()

    Dim def As String
    Dim name As String

    Set swApp = Application.SldWorks

    Set Part = swApp.NewDocument("<SolidWorks_install_dir>\data\Templates\drawing.drwdot", 2, 0.2794, 0.4318)
    swApp.ActivateDoc2 "Draw1 - Sheet1", False, longstatus

    printData "Line Style Data at Start", ""

    def = "B,1.2,-0.2,2,-0.1,2"
    name = "NewOne"
    boolstatus = Part.AddLineStyle(name, def)
    printData "Line Style Data After Add", ""

    Dim names As Variant
    Dim styleNames(2) As String

    styleNames(0) = "NewOne"
    styleNames(1) = "CHAIN"
    styleNames(2) = "PHANTOM"

    names = styleNames

    ' Save line styles, replacing already saved line styles
    boolstatus = Part.SaveLineStyles("c:\temp\styles", names, True)
    printData "Line Style Data saved to file ", "c:\temp\styles"

    ' Delete a line style
    boolstatus = Part.DeleteLineStyle("NewOne", "STITCH")
    printData "Line Style Data After Delete", ""

    ' Load saved line styles, replacing existing line styles
    boolstatus = Part.LoadLineStyles("c:\temp\styles", names, True)
    printData "Line Style Data Imported from file", ""

End Sub

Sub printData(title As String, file As String)

    Dim names As Variant
    Dim types As Variant
    Dim i As Integer
    Dim stat As Boolean

    Debug.Print Chr$(10) + "-------------------------"
    Debug.Print title
    Debug.Print "-------------------------"

    If file = "" Then
       stat = Part.GetLineStyles(names, types)
    Else
       stat = swApp.GetLineStyles(file, names, types)
    End If

    If stat Then

        For i = 0 To UBound(types)

        Debug.Print Str$(i) + " ", names(i) + " " + types(i)
        Next i
    Else
        MsgBox "Error in printData"
    End If
   

End Sub