.NET

Reply
*Bobby C. Jones
Message 11 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 08:22 AM in reply to: Natalie-C
You can shorten it a bit more by getting rid of the loop.

LayerTableRecord currentLayer =
(LayerTableRecord)trans.GetObject(activeDb.Clayer, OpenMode.ForRead);
string currentLayerName = currentLayer.Name;
--
Bobby C. Jones

wrote in message news:5257809@discussion.autodesk.com...
Ahh...yes, that does make more since.

Dim id As ObjectId
Dim lt As LayerTable = CType(trans.GetObject(db.LayerTableId,
OpenMode.ForRead), LayerTable)
For Each id In lt
Dim ltr As LayerTableRecord = CType(trans.GetObject(id,
OpenMode.ForRead), LayerTableRecord)
If ltr.Id = db.Clayer Then
MsgBox("Current Layer: " + ltr.Name)
Exit Sub
End If
Next

Much less code too!!

Thanks!
Distinguished Contributor
Posts: 303
Registered: ‎09-26-2004
Message 12 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 08:24 AM in reply to: Natalie-C
It is just made! :smileyhappy:
*Bobby C. Jones
Message 13 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 08:29 AM in reply to: Natalie-C
Hey Alex,
I just saw that you're faster on the draw! :-)
--
Bobby C. Jones

wrote in message news:5257860@discussion.autodesk.com...
It is just made! :smileyhappy:
Distinguished Contributor
Posts: 303
Registered: ‎09-26-2004
Message 14 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 08:34 AM in reply to: Natalie-C
:smileyhappy: If I also knew how to programme on VB.NET, it will be more quickly...
Contributor
Posts: 19
Registered: ‎07-11-2006
Message 15 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 08:34 AM in reply to: Natalie-C
OK, now you guys are just showing off :smileyhappy:
Distinguished Contributor
Posts: 303
Registered: ‎09-26-2004
Message 16 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 08:38 AM in reply to: Natalie-C
No Natalie! I really do not program on VB.NET (only C++/C#/VisualLisp)
*Tony Tanzillo
Message 17 of 17 (200 Views)

Re: Get Current/Active Layer?

08-03-2006 01:13 PM in reply to: Natalie-C
In a completely new drawing (only layer 0):

Command: -LAYER

Current layer: "0"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/PStyle/Freeze/Thaw/LOck/Unlock/stAte]: N

Enter name list for new layer(s): LAYER1
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/PStyle/Freeze/Thaw/LOck/Unlock/stAte]:

Command: PURGE

Command: -PURGE

Enter type of unused objects to purge
[Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/Tablest
yles/Regapps/All]: LAYER
Enter name(s) to purge <*>: LAYER1
Verify each name to be purged? [Yes/No] : N
Deleting layer "LAYER1".
1 layer deleted.

Command: -LAYER

Current layer: "0"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/PStyle/Freeze/Thaw/LOck/Unlock/stAte]: N

Enter name list for new layer(s): LAYER1
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/PStyle/Freeze/Thaw/LOck/Unlock/stAte]:

Command: (command "NETLOAD" "CsMgdAcad1.dll")
NIL

Command: ERASED_TABLE_RECORD

Layer name: LAYER1

Layer table indexer returned an erased record!

Command: NON-ERASED_TABLE_RECORD

Layer name: LAYER1

GetSymbolTableRecordId() returned non-erased record

////////////////////////////////////////////////////////////////////////////////////////////////////////

using System ;
using System.Text;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using System.Collections;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;


namespace CsMgdAcad1
{
public class SymbolTableIssue
{
public SymbolTableIssue()
{
}

[CommandMethod("ERASED_TABLE_RECORD")]
public void Test()
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

PromptStringOptions ops = new PromptStringOptions("\nLayer name: ");
ops.AllowSpaces = true;

PromptResult res = ed.GetString(ops);

if( res.Status == PromptStatus.OK && res.StringResult != string.Empty )
{

Database db = HostApplicationServices.WorkingDatabase;

using( Transaction tr = db.TransactionManager.StartTransaction() )
{
LayerTable table = (LayerTable) tr.GetObject(db.LayerTableId, OpenMode.ForRead);
ObjectId id = table[res.StringResult];
if( id.IsNull )
ed.WriteMessage("\nLayer not found");
if( id.IsErased )
ed.WriteMessage("\nLayer table indexer returned an erased record!");
else
ed.WriteMessage("\nLayer table indexer returned non-erased record");
}
}
}

[CommandMethod("NON-ERASED_TABLE_RECORD")]
public void Test1()
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

PromptStringOptions ops = new PromptStringOptions("\nLayer name: ");
ops.AllowSpaces = true;

PromptResult res = ed.GetString(ops);

if( res.Status == PromptStatus.OK && res.StringResult != string.Empty )
{

Database db = HostApplicationServices.WorkingDatabase;

using( Transaction tr = db.TransactionManager.StartTransaction() )
{
LayerTable table = (LayerTable) tr.GetObject(db.LayerTableId, OpenMode.ForRead);
ObjectId id = GetSymbolTableRecordId(table, res.StringResult);
if( id.IsNull )
ed.WriteMessage("\nSpecified layer not found.");
else if ( id.IsErased )
ed.WriteMessage("\nGetSymbolTableRecordId() returned erased record ???");
else
ed.WriteMessage("\nGetSymbolTableRecordId() returned non-erased record");
}
}
}

// Workaround. Always returns the non-erased record, when there
// are multiple records with the same name (in that case, all but
// one will be erased).

ObjectId GetSymbolTableRecordId(SymbolTable table, string name)
{
ObjectId result = ObjectId.Null;
if( table.Has(name) )
{
result = table[name];
if( result.IsErased )
{
using( Transaction tr = table.Database.TransactionManager.StartTransaction() )
{
foreach( ObjectId id in table )
{
if( ! id.IsErased )
{
SymbolTableRecord rec =
(SymbolTableRecord) tr.GetObject(id, OpenMode.ForRead, false);
if( string.Compare(rec.Name, name, true) == 0 )
{
result = id;
break;
}
}
}
}
}
}
return result;
}
}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5257814@discussion.autodesk.com...
See...even better! 17 line to just 3.

Thanks a bunch for your help!

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
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community