What is the difference between .Net created and Interop object created layer?

What is the difference between .Net created and Interop object created layer?

Anonymous
Not applicable
1,031 Views
3 Replies
Message 1 of 4

What is the difference between .Net created and Interop object created layer?

Anonymous
Not applicable

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 Function

 COM Interop

Dim objCOMDrawing As Autodesk.AutoCAD.Interop.AcadDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument

objCOMDrawing.Layers.Add("mylayername")

 

Thanks very much

0 Likes
1,032 Views
3 Replies
Replies (3)
Message 2 of 4

Hallex
Advisor
Advisor

If you're adding layer in the current document

me think you need to remove" using LockDocument.. " code block from there,

just a guess, sorry

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 4

DiningPhilosopher
Collaborator
Collaborator

Are you sure you're asking your question in the right place ?

 

There's plenty of implementation differences between AutoCAD and other look-a-like APIs, and I don't know if this is the best place to ask about them.

 

Message 4 of 4

michael_robertson
Collaborator
Collaborator

What type of error is shown? If it is in one of your catch statements what does ex.message say?

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
0 Likes