.NET

.NET

Reply
*Expert Elite*
Keith.Brown
Posts: 1,130
Registered: ‎03-13-2008
Message 11 of 13 (131 Views)

Re: Write to command line more than once during a command using editor.writeline

01-29-2012 07:23 PM in reply to: KerryBrown

Good Suggestion,  I had actually already added this to the program.  Below is the current code that I am using to add the layers.

 

'This sub will accept a layername, a color number, a lineweight and then create the layer.
        Public Sub CreateTrimbleLayer(layerName As String, colorNum As Short, LineWeightNum As LineWeight)

            'Get the editor object
            Dim doc = AcApp.DocumentManager.MdiActiveDocument
            Dim db = doc.Database
            Dim ed = doc.Editor

            'Create the layer.  If there is an error then catch it.
            Try
                'Start the database transaction
                Using tr As Transaction = db.TransactionManager.StartTransaction()

                    'Open the LayerTable for write
                    Dim lt = DirectCast(db.LayerTableId.GetObject(OpenMode.ForWrite), LayerTable)

                    'If the layer is already in the database then write a message to the command
                    'line and return
                    If lt.Has(layerName) Then
                        ed.WriteMessage(layerName & " exists..." & vbLf)
                        Return
                    End If

                    'Create a new LayerTableRecord and set the name, color, and lineweight
                    Dim ltr = New LayerTableRecord()
                    ltr.Name = layerName
                    ltr.Color = AcColors.Color.FromColorIndex(ColorMethod.ByAci, colorNum)
                    ltr.LineWeight = LineWeightNum

                    'Add the LayerTableRecord to the LayerTable
                    lt.Add(ltr)

                    'Set the Layer Description equal to the Layer Name
                    ltr.Description = layerName

                    'Add the created object to the database and commit the transaction
                    tr.AddNewlyCreatedDBObject(ltr, True)
                    tr.Commit()

                    'The layer has been successfully created so write a message to the commandline
                    ed.WriteMessage(layerName & " layer created..." & vbLf)
                End Using

                'There was an unknown error when creating the layer so write a message to the commandline
            Catch generatedExceptionName As Autodesk.AutoCAD.Runtime.Exception
                ed.WriteMessage(layerName & " Ooooops ; not created..." & vbLf)
            End Try
        End Sub

 


Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013
────────────────────────────────────
⁞|⁞ Please use Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos as appropriate. Thank you!
*Expert Elite*
Keith.Brown
Posts: 1,130
Registered: ‎03-13-2008
Message 12 of 13 (128 Views)

Re: Write to command line more than once during a command using editor.writeline

01-29-2012 07:28 PM in reply to: KerryBrown

Kerry,

 

I see that you also post alot on theswamp.org.  Do you have any suggestions on the problems I have encountered in this thread?  Thanks in advance!

 

how to access pipe information


Keith Brown AutoCAD MEP BLOG | RSS Feed
AutoCAD MEP 2014 | Revit 2014 | EastCoast CAD/CAM V6.1 | Visual Studio 2013
────────────────────────────────────
⁞|⁞ Please use Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos as appropriate. Thank you!
Valued Mentor
KerryBrown
Posts: 269
Registered: ‎11-29-2008
Message 13 of 13 (118 Views)

Re: Write to command line more than once during a command using editor.writeline

01-30-2012 02:00 AM in reply to: Keith.Brown

 

Yeah, I feel at home @ theSwamp :smileyhappy:

 

 

I 'normally' stick with C# code. I just happened to scan your code and couldn't see an obvious reason it should act as you described ... so I hacked out the C# to see how I'd have attacked it.

 

Your code seems to be layed out well (modular)  and should lend itself to debugging and expansion ... which is important as I see it.

 

Sugestions ?  :smileyhappy:  just keep bashing keys.

Regards

 

 

//-------------------------------------------------------

class keyThumper<T> : Lazy<T>;      another  Swamper

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.