What is the difference between .Net created and Interop object created layer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guys,
I have used VB.net created a layer. then place a polyline on this layer. Then I use Teigh object export the drawing to bmp
oHost =
New TeighaX.OdaHostApp 'Create the DDX application
oBmp =
New TeighaX.OdaBmpOut 'Create the bmp-exporter'Variable stores a reference to the current drawing
oDoc = oHost.Application.Documents.Open(strDrawingPath)
'Open a drawing from the specified dwg-file
oBmp.WriteFile(oDoc.Database, strThumbBMPPath)
This throw an error.
However if I use COM Interop Object create a layer. place the same polyline on it. Then use the same code to export drawing to bmp. There is no error.
I think there must be different between .Net created layer to COM Interop created layer. Could anybody give me a hint? This drive me mad now.
here are code
VB.Net
Public Function AutoCADCreateLayer(ByVal strLayerName As String, Optional ByVal lngLayerColour As Long = -1, _
Optional ByVal blnLayerOn As Boolean = True, Optional ByVal blnLayerLocked As Boolean = False) As Boolean
Dim db As Database = acApp.DocumentManager.MdiActiveDocument.Database
Dim blnRt As Boolean
Try
Using lock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim objLayertb As LayerTable = db.LayerTableId.GetObject(OpenMode.ForWrite)
Dim objNewLayer As New LayerTableRecord
With objNewLayer
.Name = strLayerName
.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, lngLayerColour)
' .IsHidden = Not blnLayerOn
' .IsLocked = blnLayerLocked
End With
objLayertb.UpgradeOpen()
Dim objNewLayerID As ObjectId = objLayertb.Add(objNewLayer)
trans.AddNewlyCreatedDBObject(objNewLayer, True)
db.Clayer = objNewLayerID
trans.Commit()
End Using
blnRt = True
End Using
Catch ex As Exception
acApp.ShowAlertDialog("Error in create layer: " & ex.Message)
Debug.Assert(False)
blnRt = False
Catch ex As SystemException
acApp.ShowAlertDialog("Erro in create layer: " & ex.Message)
Debug.Assert(False)
blnRt = False
End Try
Return blnRt
End FunctionCOM Interop
Dim objCOMDrawing As Autodesk.AutoCAD.Interop.AcadDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
objCOMDrawing.Layers.Add("mylayername")
Thanks very much