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

    .NET

    Reply
    Valued Contributor
    Posts: 71
    Registered: ‎06-03-2005

    Layers and Linetypes

    114 Views, 2 Replies
    07-29-2005 09:09 AM
    After looking through every example I can find, it seems like no one has set a linetype to a layer with C# yet. I can get the linetype loaded into my current drawing, but I cannot set it to a layer. Any ideas?
    David
    Everyone has a photographic memory,
    some just don't have film.
    Please use plain text.
    *Jim Awe

    Re: Layers and Linetypes

    07-30-2005 08:41 PM in reply to: davidhall
    You just need to get the ObjectId of the LinetypeTableRecord and set it
    with:

    LayerTableRecord.LinetypeObjectId = myLinetypeId;

    I posted a large sample called MgdDbg the other day on this forum. In there
    there is sample code that loads a named Linetype from the external file,
    makes a new LayerTableRecord, and assigns the linetype to that Layer.

    Here is the code (from ObjTests\MakeSymTblRecTests.cs):

    public void

    Layer()

    {

    string symName = "Jimbo";


    using (TransactionHelper tr = new TransactionHelper(m_db)) {

    tr.Start();


    if (tr.SymbolTableRecExists(typeof(LayerTableRecord), symName)) {

    Utils.AcadUi.PrintToCmdLine(string.Format("\nLayer \"{0}\" already exists.",
    symName));

    return;

    }


    LayerTableRecord lyr = new LayerTableRecord();

    lyr.Name = symName;

    lyr.LinetypeObjectId = Utils.SymTbl.GetOrLoadLinetypeId("ZIGZAG", m_db);

    //lyr.Description = "Layer created programmatically by MgdDbg"; // Can't set
    until after its added to the database!


    lyr.Color = Color.FromRgb(0, 130, 160);


    tr.AddNewSymbolRec(lyr);


    tr.Commit();

    Utils.AcadUi.PrintToCmdLine(string.Format("\nCreated layer \"{0}\".",
    symName));

    }

    }


    (sorry for the whacky formatting... it will fix itself if you paste it into
    Visual Studio)

    See the MgdDbg sample for the full code.

    Jim Awe
    Autodesk, Inc.


    wrote in message news:4914948@discussion.autodesk.com...
    After looking through every example I can find, it seems like no one has set
    a linetype to a layer with C# yet. I can get the linetype loaded into my
    current drawing, but I cannot set it to a layer. Any ideas?
    Please use plain text.
    Valued Contributor
    Posts: 71
    Registered: ‎06-03-2005

    Re: Layers and Linetypes

    08-01-2005 11:02 AM in reply to: davidhall
    Thanks. I was close, but now I know what I was doing wrong
    David
    Everyone has a photographic memory,
    some just don't have film.
    Please use plain text.