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

    .NET

    Reply
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    Re: AutoCAD Commands from vb.net 2010

    03-26-2012 10:46 AM in reply to: vbNinja

    Add these lines to the top of the class

     

    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Colors

     

    and add the reference to

    acdbmgr.dll

    acmgd.dll

    and set copy local to false.

     

     

    ---------------------------



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Valued Mentor
    Mike.Wohletz
    Posts: 351
    Registered: ‎07-29-2008

    Re: AutoCAD Commands from vb.net 2010

    03-26-2012 10:47 AM in reply to: vbNinja

    What  namespaces have you imported? Is this a standalone EXE application? 

     

    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    Re: AutoCAD Commands from vb.net 2010

    03-26-2012 10:50 AM in reply to: Mike.Wohletz

    the above code won't work for a stand alone exe.

     

     

    ---------------------------



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎03-18-2012

    Re: AutoCAD Commands from vb.net 2010

    03-26-2012 11:13 AM in reply to: Mike.Wohletz

    Hi

    I have the following imports:

    Imports System
    Imports System.Runtime.InteropServices
    Imports Autodesk.AutoCAD.Interop

     

    And yes this is a standalone EXE Application

     

    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎03-18-2012

    Re: AutoCAD Commands from vb.net 2010

    03-26-2012 11:14 AM in reply to: Mike.Wohletz

    Hi

    I have the following imports:

    Imports System
    Imports System.Runtime.InteropServices
    Imports Autodesk.AutoCAD.Interop

     

    And yes this is a standalone EXE application

     

    Please use plain text.
    Valued Mentor
    Mike.Wohletz
    Posts: 351
    Registered: ‎07-29-2008

    Re: AutoCAD Commands from vb.net 2010

    03-27-2012 06:04 AM in reply to: vbNinja

    Try something like this to set the layer colors:

     

     

        Private Sub WorkingWithAutoCAD()
            ' we can set the color of one layer or current by:
            acSetLayerColor(AcColor.acYellow)
            'or
            'set them all to green
            For Each oLayer As AcadLayer In ThisApplication.ActiveDocument.Layers
                acSetLayerColor(AcColor.acGreen, oLayer)
            Next
            ' or set the OB layer to red and see if it happened calling by name
            Dim Rval As Boolean = acSetLayerColorByName(AcColor.acRed, "OB")
    
        End Sub
        Private Function acSetLayerColor(ByVal oColor As AcColor, Optional ByVal oLayer As AcadLayer = Nothing) As Boolean
            Try
                If oLayer Is Nothing Then 'we will look at the current layer
                    oLayer = ThisApplication.ActiveDocument.ActiveLayer
                End If
                oLayer.color = oColor
                Return True
            Catch ex As Exception
                Return False
            End Try
        End Function
        Private Function acSetLayerColorByName(ByVal oColor As AcColor, ByVal oLayerName As String) As Boolean
            Try
                Dim oLayer As AcadLayer = ThisApplication.ActiveDocument.Layers.Item(oLayerName)
                oLayer.color = oColor
                Return True
            Catch ex As Exception
                Return False
            End Try
        End Function

     

    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎03-18-2012

    Re: AutoCAD Commands from vb.net 2010

    03-27-2012 10:01 AM in reply to: Mike.Wohletz

    Hi

    Your suggestions worked after I added a reference to acdbmgd.dll and acdmgd.dll and imported these namespaces:

    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Colors

     

    Thank you all for your help.

    Best regards

    Please use plain text.