i have 3 linestyles in a dgn file so is it possible to find out how many linestyles do i have and what are their names using vba.
Sure...
The count of linestyles in designfile: ActiveDesignFile.LineStyles.Count
To get names:
Dim LS as LineStyle For Each LS In ActiveDesignFile.LineStyles Debug.Print LS.Name Next
Dim LS as LineStyle
For Each LS In ActiveDesignFile.LineStyles
Debug.Print LS.Name
Next
Thank you for reply Don.
But i think i missed a word. i mean, the code must be for multi-line style not line style.
Regards, cenber
Paste the following code into module. Can NOT be placed into class or form (form is class as well)...
Then run GetMLineAll...
Techniques used in the following example are NOT recommended for those VBA users, who don't know, how it works.
Declare Sub MoveMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (ByVal strDest As Any, _ ByVal lpSource As Any, _ ByVal length As Long) Type MLineStyleNames Count As Long Names() As String End Type Function TrimNullChar(InputStr As String) As String TrimNullChar = Left$(InputStr, InStr(1, InputStr, vbNullChar) - 1) End Function Function TraverseFunction(ByRef MayContinue As Long, ByVal mlineStyleP As Long, _ ByVal MSWNameP As Long, ByRef Styles As MLineStyleNames) As Long On Error Resume Next Dim Buffer As String Buffer = String(256, vbNullChar) MoveMemory StrPtr(Buffer), MSWNameP, 256 With Styles ReDim Preserve .Names(.Count) .Names(.Count) = TrimNullChar(Buffer) If .Names(.Count) = "" Then .Names(.Count) = "Default" .Count = .Count + 1 End With MayContinue = 1 TraverseFunction = 0 End Function Function GetMultiLineStyles(MR As ModelReference) As MLineStyleNames Dim CExpression As String CExpression = "mdlMlineStyle_traverse(" & Val(AddressOf TraverseFunction) & ", " & _ VarPtr(GetMultiLineStyles) & ", " & MR.MdlModelRefP & ", -1)" GetCExpressionValue CExpression End Function Sub GetMLineAll() Dim Styles As MLineStyleNames Dim i As Long Styles = GetMultiLineStyles(ActiveModelReference) If Styles.Count > 0 Then For i = 0 To Styles.Count - 1 MsgBox i + 1 & " - " & Styles.Names(i) Next i End If End Sub
Awful! This is what i want exactly. Thank you so much, Don.
I'm sorry for little mistake Dušan (Dan).
And again God bless you :)