.NET

.NET

Reply
Valued Contributor
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 1 of 4 (386 Views)

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

386 Views, 3 Replies
01-10-2013 06:28 AM

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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (357 Views)

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

01-10-2013 11:07 AM in reply to: yaqiz

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
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 4 (332 Views)

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

01-11-2013 06:42 AM in reply to: yaqiz

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.

 

Distinguished Mentor
michael.robertson
Posts: 604
Registered: ‎03-18-2008
Message 4 of 4 (320 Views)

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

01-11-2013 11:43 AM in reply to: DiningPhilosopher

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.