• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    *Expert Elite*
    Keith.Brown
    Posts: 747
    Registered: ‎03-13-2008

    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
    Please use plain text.
    *Expert Elite*
    Keith.Brown
    Posts: 747
    Registered: ‎03-13-2008

    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
    Please use plain text.
    Valued Mentor
    KerryBrown
    Posts: 259
    Registered: ‎11-29-2008

    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


    I do not endorse the social media app links below:smileyembarrassed:

    Please use plain text.