Posts: 14
Registered: ‎03-29-2011
Message 1 of 6 (498 Views)
Accepted Solution


498 Views, 5 Replies
05-08-2012 02:28 AM

(visual studio 2010 c# and AutoCAD 2010 )

I`m trying to create a new layer with ARGB color but SetRGB doesn`t work this way.

Any idea. thank you.

// Color is a System.Drawing.Color

private static void NewLayer(string layerName, Color layerColor)
            LY_Rutas = gbl_doc.Layers.Add(layerName);
            LY_Rutas.TrueColor.SetRGB(layerColor.R, layerColor.G, layerColor.B);

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

Re: JLS2012-1

05-08-2012 05:38 AM in reply to: jlsantiago

Color in AutoCAD is not a Drawing.Color

Add to your using region:





Posts: 14
Registered: ‎03-29-2011
Message 3 of 6 (455 Views)

Re: JLS2012-1

05-10-2012 12:28 AM in reply to: jlsantiago

Thanx for the reply.

Now, when i add this line 




i got the next error.



System.BadImageFormatException was unhandled
  Message=No se puede cargar el archivo o ensamblado 'acdbmgd, Version=, Culture=neutral, PublicKeyToken=null' ni una de sus dependencias. Se ha intentado cargar un programa con un formato incorrecto.
  FileName=acdbmgd, Version=, Culture=neutral, PublicKeyToken=null
  FusionLog==== Información de estado anterior al enlace ===
LOG: Usuario = Juan-VAIO\Juan
LOG: DisplayName = acdbmgd, Version=, Culture=neutral, PublicKeyToken=null
LOG: Appbase = file:///C:/Trabajo/Palmatools/INECO/PEIF/Pruebas_VC2010/Prueba_AutoCAD/DrivingCAD/bin/Debug/
LOG: PrivatePath inicial = NULL
Ensamblado de llamada : DrivingAutoCAD, Version=, Culture=neutral, PublicKeyToken=null.
LOG: Este enlace empieza en el contexto de carga default.
LOG: Utilización del archivo de configuración de la aplicación: C:\Trabajo\Palmatools\INECO\PEIF\Pruebas_VC2010\Prueba_AutoCAD\DrivingCAD\bin\Debug\DrivingAutoCAD.vshost.exe.Config
LOG: Utilizando el archivo de configuración de host:
LOG: Utilizando el archivo de configuración del equipo en C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: La directiva no se está aplicando a la referencia en este momento (enlace de ensamblado privado, personalizado, parcial o basado en la ubicación).
LOG: Intento de descarga de la nueva dirección URL file:///C:/Trabajo/Palmatools/INECO/PEIF/Pruebas_VC2010/Prueba_AutoCAD/DrivingCAD/bin/Debug/acdbmgd.DLL.
ERR: Error al completar la instalación del ensamblado (hr = 0x8007000b). Finalizó la búsqueda.

       en DrivingAutoCAD.Form1.button1_Click(Object sender, EventArgs e)
       en System.Windows.Forms.Control.OnClick(EventArgs e)
       en System.Windows.Forms.Button.OnClick(EventArgs e)
       en System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       en System.Windows.Forms.Control.WndProc(Message& m)
       en System.Windows.Forms.ButtonBase.WndProc(Message& m)
       en System.Windows.Forms.Button.WndProc(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       en System.Windows.Forms.Application.Run(Form mainForm)
       en DrivingAutoCAD.Program.Main() en C:\Trabajo\Palmatools\INECO\PEIF\Pruebas_VC2010\Prueba_AutoCAD\DrivingCAD\Program.cs:línea 19
       en System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       en System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       en System.Threading.ThreadHelper.ThreadStart()



Are there another way to do something like this, and that works?


int r = 255;
int g = 0;
int b = 0;
AcadLayer LY_Rutas = gbl_doc.Layers.Add("PruebaCAD");



thanx again

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

Re: JLS2012-1

05-10-2012 04:03 AM in reply to: jlsantiago

Here is what I would to create new layer

        [CommandMethod("myLay", CommandFlags.Modal | CommandFlags.Redraw)]

        public void CreateLayer()
            string layerName = "LY_Rutas";
            ObjectId layerId = ObjectId.Null;
            byte r = 176;
            byte g = 37;
            byte b = 28;
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
                // Get the layer table from the drawing and open for write
                LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
                if (lt.Has(layerName))
                    layerId = lt[layerName];
                    if (layerId.IsErased)
                        LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(layerId, OpenMode.ForWrite, true);
                    // Create new layer table record 
                    LayerTableRecord ltr = new LayerTableRecord();
                    // Add some properties
                    ltr.Name = layerName;
                    ltr.LinetypeObjectId = db.ContinuousLinetype;
                    ltr.LineWeight = LineWeight.LineWeight030;
                    ltr.Color = Color.FromRgb(r, g, b);
                    layerId = lt.Add(ltr);
                    // Append layer to database
                    tr.AddNewlyCreatedDBObject(ltr, true);

 Using your function try this way, not tested

              AcadLayer LY_Rutas = gbl_doc.Layers.Add("PruebaCAD");
               //change linetype
                LY_Rutas.Linetype = strLtype;
                //change entity color
                AcadAcCmColor acCol = LY_Rutas.TrueColor;
                //1. change color RGB
                acCol.ColorMethod = AcColorMethod.acColorMethodByRGB;
                //2. change color index etc...
                //acCol.ColorMethod = AcColorMethod.acColorMethodByACI;
                //acCol.ColorIndex = (AcColor)140;
                LY_Rutas.TrueColor = acCol;
                //release AcadAcCmColor object
                acCol = null;



Posts: 14
Registered: ‎03-29-2011
Message 5 of 6 (418 Views)

Re: JLS2012-1

05-16-2012 02:09 AM in reply to: Hallex

Thanx very much.

it works perfectly.



*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 6 (396 Views)

Re: JLS2012-1

05-18-2012 08:05 AM in reply to: jlsantiago

Glad to help

Cheers :smileyhappy:



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.