Is the linetype your pulling from your dataset an AutoCAD LineType?
Here is a quick 20 minute demo... had to try this out myself and a dwg
that was saved from inventor
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Colors
Imports Autodesk.AutoCAD.EditorInput
Public Class Class1
Dim visibleId As ObjectId
Dim hiddenId As ObjectId
Dim centerId As ObjectId
Dim dimensionId As ObjectId
Dim partId As ObjectId
Dim part2Id As ObjectId
Dim movementId As ObjectId
Dim interfaceequipId As ObjectId
Dim interfaceequip2Id As ObjectId
Dim balloonId As ObjectId
<CommandMethod("ChangeLayers", CommandFlags.Session)> _
Public Sub ChangeLayers()
Dim foundFile As String = ""
Dim fbd As New Windows.Forms.FolderBrowserDialog
Dim ThisOne As String = ""
If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
ThisOne = fbd.SelectedPath
Else
MsgBox("You must select a Folder")
Exit Sub
End If
Dim docLock As DocumentLock
For Each foundFile In My.Computer.FileSystem.GetFiles(ThisOne, FileIO.SearchOption.SearchAllSubDirectories, "*.dwg")
Dim docs As Autodesk.AutoCAD.ApplicationServices.DocumentCollection
docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = docs.Open(foundFile, False)
docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Call SetMyLayers()
Call This2That_Layers()
docLock.Dispose()
doc.CloseAndSave(foundFile)
Next
End Sub
Public Sub SetMyLayers()
visibleId = CheckForLayer("my01", 7, "Continuous")
hiddenId = CheckForLayer("my02", 2, "Hidden")
centerId = CheckForLayer("my03", 6, "Center")
dimensionId = CheckForLayer("my04", 3, "Continuous")
partId = CheckForLayer("my05", 5, "Phantom")
part2Id = CheckForLayer("my06", 1, "Phantom")
movementId = CheckForLayer("my07", 4, "Phantom2")
interfaceequipId = CheckForLayer("my08", 30, "Phantom")
interfaceequip2Id = CheckForLayer("my09", 201, "Phantom")
balloonId = CheckForLayer("BallnStock", 146, "Continuous")
End Sub
Public Function CheckForLayer(ByVal namLay As String, ByVal colLay As Integer, ByVal typLin As String) As ObjectId
Dim layerId As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim t As Transaction = db.TransactionManager.StartTransaction()
Dim lt As LayerTable = t.GetObject(db.LayerTableId, OpenMode.ForWrite)
If lt.Has(namLay) Then
layerId = lt.Item(namLay)
Else
Dim ltr As LayerTableRecord = New LayerTableRecord
ltr.Name = namLay
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, colLay)
If typLin <> "Continuous" Then ltr.LinetypeObjectId = CheckForLineType(typLin)
layerId = lt.Add(ltr)
t.AddNewlyCreatedDBObject(ltr, True)
End If
t.Commit()
t.Dispose()
Return layerId
End Function
Public Function CheckForLineType(ByVal typeline As String) As ObjectId
Dim linetypeId As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim t As Transaction = db.TransactionManager.StartTransaction()
Dim tbl As LinetypeTable = t.GetObject(db.LinetypeTableId, OpenMode.ForRead, False)
If tbl.Has(typeline) Then
linetypeId = tbl(typeline)
Else
db.LoadLineTypeFile(typeline, "acad.lin")
linetypeId = tbl(typeline)
End If
t.Commit()
t.Dispose()
Return linetypeId
End Function
Sub This2That_Layers()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim t As Transaction = db.TransactionManager.StartTransaction()
Dim psr As PromptSelectionResult
Dim idArray() As ObjectId
Dim objId As ObjectId
Dim ent As Entity
Try
Dim filterfor() As TypedValue = {New TypedValue(8, "Hidden (ANSI)")}
Dim sf As SelectionFilter = New SelectionFilter(filterfor)
psr = ed.SelectAll(sf)
If psr.Status = PromptStatus.OK Then
Dim ss As Autodesk.AutoCAD.EditorInput.SelectionSet = psr.Value
idArray = ss.GetObjectIds()
For Each objId In idArray
ent = t.GetObject(objId, OpenMode.ForWrite, False)
ent.LayerId = hiddenId
ent.Color = Color.FromColorIndex(ColorMethod.ByLayer, 256)
ent.Linetype = SymbolUtilityServices.LinetypeByLayerName()
Next objId
End If
Catch ex As Exception
Finally
psr = Nothing
idArray = Nothing
objId = Nothing
ent = Nothing
End Try
t.Commit()
t.Dispose()
End Sub
End Class