Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting and sorting ATRIBUTE TEXTs in the block and divide

0 REPLIES 0
Reply
Message 1 of 1
k005
102 Views, 0 Replies

Getting and sorting ATRIBUTE TEXTs in the block and divide

Hello friends;

 

Blok reference ( attribute text )

 

2x15ø14/200 L=1550

10ø12/200 L=1500

5ø12 L=150

 

I have Value values ​​in the POZYAZI tag in block references such as. I want to divide these into /xxx and L=xxx 10 and print them as a text object, one under the other, as a list in a new format. However, I cannot access the value in POZYAZI. Where am I making a mistake?


Thanks in advance to my helpful friend.

 

 

wanted: ( text object)

 

2x15ø14/20 L=155

10ø12/20 L=150

5ø12 L=15

 

 

 

 

 

 

 [CommandMethod("ProcessPozyazi")]
 public void ProcessPozyazi()
 {
     Document doc = Application.DocumentManager.MdiActiveDocument;
     Database db = doc.Database;
     Editor ed = doc.Editor;

     using (Transaction tr = db.TransactionManager.StartTransaction())
     {
         // Select block references with attributes
         PromptSelectionResult selRes = ed.GetSelection(new PromptSelectionOptions(), new SelectionFilter(new TypedValue[] { new TypedValue((int)DxfCode.Start, "INSERT") }));

         if (selRes.Status != PromptStatus.OK) return;

         SelectionSet selSet = selRes.Value;
         List<string> outputList = new List<string>();

         foreach (SelectedObject selObj in selSet)
         {
             if (selObj != null)
             {
                 BlockReference blockRef = tr.GetObject(selObj.ObjectId, OpenMode.ForRead) as BlockReference;
                 if (blockRef != null)
                 {
                     foreach (ObjectId attId in blockRef.AttributeCollection)
                     {
                         AttributeReference attRef = tr.GetObject(attId, OpenMode.ForRead) as AttributeReference;
                         if (attRef != null && attRef.Tag == "POZYAZI")
                         {
                             string pozyaziValue = attRef.TextString;

                             string[] parts = pozyaziValue.Split(' ');

                             if (parts.Length > 2)
                             {
                                 string[] sizeParts = parts[1].Split('/');
                                 string[] diamSpacingParts = sizeParts[0].Split('ø');

                                 string adet = parts[0];
                                 string cap = diamSpacingParts[0];
                                 string uzunluk = parts[3].Substring(2); // "L="'den sonraki kısmı al
                                 string aralik = sizeParts[1];
                                 string length = parts[5];

                                 outputList.Add($"{adet} {cap}ø{aralik}/{uzunluk} L={length}");
                             }
                             
                         }
                     }
                 }
             }
         }

         tr.Commit();

         if (outputList.Count == 0)
         {
             ed.WriteMessage("\nNo valid POZYAZI attributes found.");
             return;
         }

         PromptPointResult ppr = ed.GetPoint("Select a point to start writing text: ");
         if (ppr.Status != PromptStatus.OK) return;

         Point3d startPoint = ppr.Value;

         using (Transaction writeTr = db.TransactionManager.StartTransaction())
         {
             BlockTable bt = writeTr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
             BlockTableRecord btr = writeTr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

             double textHeight = 2.5;
             double lineSpacing = textHeight * 1.5;
             Point3d currentPoint = startPoint;

             foreach (var line in outputList)
             {
                 DBText text = new DBText
                 {
                     Position = currentPoint,
                     Height = textHeight,
                     TextString = line,
                     TextStyleId = db.Textstyle
                 };

                 btr.AppendEntity(text);
                 writeTr.AddNewlyCreatedDBObject(text, true);
                 currentPoint = new Point3d(currentPoint.X, currentPoint.Y - lineSpacing, currentPoint.Z);
             }

             writeTr.Commit();
         }
     }
 }

 

 

 

0 REPLIES 0

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report