style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<JamieVJohnson> wrote in messageTony,
href="news:6081488@discussion.autodesk.com">news:6081488@discussion.autodesk.com...
Your
a programmer I can definitely see that. However, as a proficient professional
of logic, you seem to assume too many things. Proficient programmers should
never leave their code up to assumtions for the processor. This is why most
people use option explicit.
With that said, the assumtion that
everybody will see your statements the same way your first in this long chain
of retorts. Just realize that other people took many proper english classes
too. Some of us even got the equivelent of an A in these classes. Therefore,
its a shame that you keep redirecting people to go back and read the original
statement in your posts. They did, you just did not write them properly to
eliminate all possible assumptions, otherwise there would not be any
confusion.
Later
dude,
jvj
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<joelkarr> wrote in messageSince
href="news:6081666@discussion.autodesk.com">news:6081666@discussion.autodesk.com...
my initial post got so many answers I thought I would go for the extra bonus
and ask this question.
Now that I have a block inserted I would
like to have it inserted on a specific layer. I have set up a microsoft access
database to be used to store which layer each block should be
inserted.
It all works great until I get a block that needs to
be inserted on a layer that does not yet exist. I am guessing that I need to
add a new layer and its properties to the LayerTable but got a little caught
up when I tried to use the same idea as I did for adding a block to the block
table.
So for the bonus points. Can anyone submit sample code
in C# or another language for adding a layer to the
layerTable?
Here is my quick attempt. I am reading a database
to get the values for all the properties. I still need to convert from string
into ACAD properties but I thought I would see what everyone
though.
public void createLayer(string layerName, string
layerColor, string layerLineType, string layerDescription, bool
blnPlot)
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db =
doc.Database;
// For multiple layers should I be adding all newly
created layers to an object collection and then adding that collection to the
LayerTable all at once?
// ObjectIdCollection layersIds = new
ObjectIdCollection();
using (Transaction tr =
db.TransactionManager.StartTransaction())
{
try
{
LayerTable
lt = (LayerTable)tr.GetObject(db.LayerTableId,
OpenMode.ForRead);
LayerTableRecord ltr = new
LayerTableRecord();
//Set Layer Properties
//Still need
to work out converting from string to appropriate acad prop. Color, linetype,
plot
ltr.Name = layerName;
ltr.Color =
layerColor;
ltr.LinetypeObjectId =
layerLineType;
ltr.PlotStyleName = blnPlot;
ltr.Description =
layerDescription;
//add newly created layer back to
layerTable
lt.Add(ltr);
tr.Commit();
}
catch
{
tr.Abort();
}
}
Public Overridable Function SetLayer(ByVal strLayerName As String, ByVal sngColor As Single) As LayerTableRecord 'find it or create it
If strLayerName = "" Then Return Nothing
Dim ltr As LayerTableRecord
ltr = FindLayer(strLayerName)
If ltr IsNot Nothing Then Return ltr
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim lt As LayerTable = trans.GetObject(db.LayerTableId, OpenMode.ForWrite, True, True)
ltr = New LayerTableRecord
ltr.Name = strLayerName
ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, sngColor)
lt.Add(ltr)
trans.AddNewlyCreatedDBObject(ltr, True)
trans.Commit()
End Using
Return ltr
End Function
Public Overridable Function FindLayer(ByVal strLayerName As String) As LayerTableRecord
If strLayerName = "" Then Return Nothing
Dim ltr As LayerTableRecord = Nothing
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim lt As LayerTable = trans.GetObject(db.LayerTableId, OpenMode.ForWrite, True, True)
For Each oid As ObjectId In lt
ltr = trans.GetObject(oid, OpenMode.ForRead, True, True)
If ltr.Name = strLayerName Then
Return ltr
End If
Next
End Using
Return Nothing
End Function
Hope this helps,
jvj
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<JamieVJohnson> wrote in messageWow
href="news:6082244@discussion.autodesk.com">news:6082244@discussion.autodesk.com...
Tony, that gun statement was totally irrelavent!! Cute
though.
Word.
This is some VB.Net code for your
layer problem:
Public Overridable Function SetLayer(ByVal strLayerName As String,
ByVal sngColor As Single) As LayerTableRecord 'find it or create
it
If strLayerName = "" Then Return Nothing
Dim ltr As LayerTableRecord
ltr = FindLayer(strLayerName)
If ltr IsNot Nothing Then Return ltr
Using trans As Transaction =
db.TransactionManager.StartTransaction
Dim lt As LayerTable = trans.GetObject(db.LayerTableId,
OpenMode.ForWrite, True, True)
ltr = New LayerTableRecord
ltr.Name = strLayerName
ltr.Color =
Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci,
sngColor)
lt.Add(ltr)
trans.AddNewlyCreatedDBObject(ltr, True)
trans.Commit()
End Using
Return ltr
End Function
Public Overridable Function FindLayer(ByVal strLayerName As String) As
LayerTableRecord
If strLayerName = "" Then Return Nothing
Dim ltr As LayerTableRecord = Nothing
Using trans As Transaction =
db.TransactionManager.StartTransaction
Dim lt As LayerTable = trans.GetObject(db.LayerTableId,
OpenMode.ForWrite, True, True)
For Each oid As ObjectId In lt
ltr = trans.GetObject(oid, OpenMode.ForRead, True, True)
If ltr.Name = strLayerName Then
Return ltr
End If
Next
End Using
Return Nothing
End Function
Hope this
helps,
jvj
HI folks,
I came across this interesting thread from a while ago, which raises an important point:
(i) when employing transactions utlising the using(......) statement :if an exception is thrown, will the transaction still get disposed?
using( Transaction tr = database.TransactionManager.StartTransaction)
{
// code goes here
// exception is thrown here
}
Will the transaction be disposed of at all?