.NET

Reply
Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 1 of 6 (469 Views)
Accepted Solution

JLS2012-1

469 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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 6 (455 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:

 

using.AutoCAD.Colors;

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 3 of 6 (426 Views)

Re: JLS2012-1

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

Thanx for the reply.

Now, when i add this line 

 

using.AutoCAD.Colors;

 

i got the next error.

 

***************************************************************************************************************************************

System.BadImageFormatException was unhandled
  Message=No se puede cargar el archivo o ensamblado 'acdbmgd, Version=18.1.0.0, Culture=neutral, PublicKeyToken=null' ni una de sus dependencias. Se ha intentado cargar un programa con un formato incorrecto.
  Source=DrivingAutoCAD
  FileName=acdbmgd, Version=18.1.0.0, Culture=neutral, PublicKeyToken=null
  FusionLog==== Información de estado anterior al enlace ===
LOG: Usuario = Juan-VAIO\Juan
LOG: DisplayName = acdbmgd, Version=18.1.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Trabajo/Palmatools/INECO/PEIF/Pruebas_VC2010/Prueba_AutoCAD/DrivingCAD/bin/Debug/
LOG: PrivatePath inicial = NULL
Ensamblado de llamada : DrivingAutoCAD, Version=1.0.0.0, 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.

  StackTrace:
       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()
  InnerException:

*************************************************************************************************************************************************

 

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");
LY_Rutas.TrueColor.SetRGB(r,g,b);

 

 

thanx again

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (414 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);
                        ltr.Erase(false);
                    }
                }
                else
                {
                    // 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);
                    tr.Commit();
                }
            }
        }

 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;
                acCol.SetRGB(255,255,0);
                //2. change color index etc...
                //acCol.ColorMethod = AcColorMethod.acColorMethodByACI;
                //acCol.ColorIndex = (AcColor)140;
                LY_Rutas.TrueColor = acCol;
                //release AcadAcCmColor object
                acCol = null;

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
jlsantiago
Posts: 14
Registered: ‎03-29-2011
Message 5 of 6 (389 Views)

Re: JLS2012-1

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

Thanx very much.

it works perfectly.

 

:smileyhappy:

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

Re: JLS2012-1

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

Glad to help

Cheers :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community