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

Extracting Layer Attributes

6 REPLIES 6
Reply
Message 1 of 7
geenakv
673 Views, 6 Replies

Extracting Layer Attributes

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..
6 REPLIES 6
Message 2 of 7
mzakiralam
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

 

Message 3 of 7
Hallex
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
Message 4 of 7
geenakv
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..
Message 5 of 7
Hallex
in reply to: geenakv

Check this out:
http://www.dotsoft.com/freestuff.htm
scroll down to 'LAYERREP.zip'
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 7
mzakiralam
in reply to: geenakv

Message 7 of 7
geenakv
in reply to: Hallex

thank u...its very helpful..!!
Thanks & Regards
Geena..

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