.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layers and Linetypes

2 REPLIES 2
Reply
Message 1 of 3
davidhall
330 Views, 2 Replies

Layers and Linetypes

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.
2 REPLIES 2
Message 2 of 3
Anonymous
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?
Message 3 of 3
davidhall
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost