.NET

Reply
Member
geenakv
Posts: 4
Registered: ‎01-27-2014
Message 1 of 7 (254 Views)

Extracting Layer Attributes

254 Views, 6 Replies
01-27-2014 11:11 PM

Hi Group..!!

 

I am doing one application for autocad designers using VB.Net. In the application we can select one dwg file and extracting the layers inside the drawing..! i did that..but there is one problem. If i clicked on a layer, all layers attributes which is present on the dwg will be extracting... i need one by one depends on the selection of layer.

Can u help me..

Thanks & Regards
Geena..
Mentor
mzakiralam
Posts: 229
Registered: ‎11-09-2012
Message 2 of 7 (227 Views)

Re: Extracting Layer Attributes

01-28-2014 04:45 AM in reply to: geenakv

HI,
I did not understand completely your requirement.. Do you want to click the layer from layer manager? if so there is already those attribute. Or if something like that you want to click an entity then it will show in which layer that entitiy is and then shows the layer details then you have to code it and get the layer attribute from its layer table record properties. if so you can start from below code snippet. If I understand wrong then please describe more clearly what do you want to meet your requirement. you can also use picture how do you want .

 

  Public Sub LayerAttribute()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Using tx As Transaction = db.TransactionManager.StartTransaction()
            Dim lt As LayerTable = tx.GetObject(db.LayerTableId, OpenMode.ForRead)
            For Each id As ObjectId In lt
                Dim ltr As LayerTableRecord = tx.GetObject(id, OpenMode.ForRead)
                'layer name
                Dim lName As String = ltr.Name
                'layer on or off
                Dim lStatus As Boolean = ltr.IsOff
                'layer color
                Dim lcolor As Color = ltr.Color
            Next
        End Using
    End Sub

 

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

Re: Extracting Layer Attributes

01-28-2014 01:42 PM in reply to: geenakv

Start with this:

        public void SelectBlocksByLayerFilter()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            PromptNestedEntityResult atres = ed.GetNestedEntity("\nSelect attribute ");
            if (atres.Status != PromptStatus.OK)
                return;

            ObjectId[] nestIds = atres.GetContainers();
            if (nestIds.Length == 0)
            {
                return;
            }

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockReference br = (BlockReference)tr.GetObject(nestIds[0], OpenMode.ForRead);
                string blockName = br.Name;
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                TypedValue[] tv = new TypedValue[] {
                    new TypedValue((int)DxfCode.Start, "insert"),
                    new TypedValue((int)DxfCode.BlockName, blockName),
                    new TypedValue(66, 1), new TypedValue((int)DxfCode.LayerName, br.Layer)
                };

                SelectionFilter flt = new SelectionFilter(tv);
                PromptSelectionResult resSel = ed.SelectAll(flt);
                SelectionSet selSet = resSel.Value;
                ObjectId[] ids = selSet.GetObjectIds();
                ed.SetImpliedSelection(ids);
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("found: " + ids.Length + " blocks\n on layer:" + br.Layer);
     
                //    // rest your code here    //  //

                tr.Commit();

            }
        }

 Or VB.NET

		Public Sub SelectBlocksByLayerFilter()

			Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

			Dim db As Database = doc.Database

			Dim ed As Editor = doc.Editor

			Dim atres As PromptNestedEntityResult = ed.GetNestedEntity(vbLf & "Select attribute ")
			If atres.Status <> PromptStatus.OK Then
				Return
			End If

			Dim nestIds As ObjectId() = atres.GetContainers()
			If nestIds.Length = 0 Then
				Return
			End If

			Using tr As Transaction = db.TransactionManager.StartTransaction()
				Dim br As BlockReference = DirectCast(tr.GetObject(nestIds(0), OpenMode.ForRead), BlockReference)
				Dim blockName As String = br.Name
				Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

				Dim tv As TypedValue() = New TypedValue() {New TypedValue(CInt(DxfCode.Start), "insert"), New TypedValue(CInt(DxfCode.BlockName), blockName), New TypedValue(66, 1), New TypedValue(CInt(DxfCode.LayerName), br.Layer)}

				Dim flt As New SelectionFilter(tv)
				Dim resSel As PromptSelectionResult = ed.SelectAll(flt)
				Dim selSet As SelectionSet = resSel.Value
				Dim ids As ObjectId() = selSet.GetObjectIds()
				ed.SetImpliedSelection(ids)
				Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(("found: " + ids.Length & " blocks" & vbLf & " on layer:") + br.Layer)

				'    // rest your code here    //  //


				tr.Commit()
			End Using
		End Sub

 If you need select by attribute layer then change in layer filter instead of br.Layer

put attres.ObjectId.Layer

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Member
geenakv
Posts: 4
Registered: ‎01-27-2014
Message 4 of 7 (192 Views)

Re: Extracting Layer Attributes

01-28-2014 09:26 PM in reply to: mzakiralam
Hi, Yes i want the layer attribute from layer table records and should be
stored in an excel file in the name of the layer which is selected.
Thanks & Regards
Geena..
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 7 (182 Views)

Re: Extracting Layer Attributes

01-29-2014 12:36 AM in reply to: geenakv
Check this out:
http://www.dotsoft.com/freestuff.htm
scroll down to 'LAYERREP.zip'
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mzakiralam
Posts: 229
Registered: ‎11-09-2012
Message 6 of 7 (172 Views)

Re: Extracting Layer Attributes

01-29-2014 01:46 AM in reply to: geenakv
Member
geenakv
Posts: 4
Registered: ‎01-27-2014
Message 7 of 7 (127 Views)

Re: Extracting Layer Attributes

02-04-2014 12:50 AM in reply to: Hallex
thank u...its very helpful..!!
Thanks & Regards
Geena..

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