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

Select only Text and Mtext objectss

9 REPLIES 9
Reply
Message 1 of 10
J-Rocks
1228 Views, 9 Replies

Select only Text and Mtext objectss

Hello everyone .

 

It seems that my TypedValue structure is wrong because I could not select Texts or Mtext nor anything when I ran the program . strange Smiley Happy

 

Could someone help me to modify the codes ?

 

TypedValue[] Tvalues = new TypedValue[] { new TypedValue(0, "TEXT"), new TypedValue(0, "MTEXT") };
9 REPLIES 9
Message 2 of 10
J-Rocks
in reply to: J-Rocks

It seems this modification is working with wild-cards .

 

Is this correct ?

 

TypedValue[] Tvalues = new TypedValue[] { new TypedValue(0, "*TEXT") };
Message 3 of 10
Anonymous
in reply to: J-Rocks

your last pattern call is correct, but also try to separate the pattern with commas, in example:

 

TypedValue[] typedValues = { new TypedValue((int)DxfCode.Start, "LINE,ARC,LWPOLYLINE,POLYLINE,CIRCLE,SPLINE,ELLIPSE") };

hth.-

Message 4 of 10
J-Rocks
in reply to: Anonymous

Thanks LE that works very well .

 

I am trying to write a program to select text strings that match a specific text string "BedRoom" , and my question is : how can I highlight if the list contained values ( text strings "BedRoom" ) ?

 

Regards

 

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                Editor ed = acDoc.Editor;
                TypedValue[] Tvalues = new TypedValue[] {new TypedValue((int)DxfCode.Start,"TEXT,MTEXT")};
                SelectionFilter fltr = new SelectionFilter(Tvalues);
                PromptSelectionResult SSprompt;
                SSprompt = acDoc.Editor.GetSelection(fltr);
                if (SSprompt.Status == PromptStatus.OK)
                    foreach (SelectedObject item in SSprompt.Value)
                    {
                        DBObject obj = acTrans.GetObject(item.ObjectId, OpenMode.ForRead) as DBObject;
                        MText mtext = obj as MText;
                        if (mtext != null && mtext.Contents=="BedRoom")
                        {
                            mylist.Add(mtext.Contents);
                            ed.WriteMessage(mtext.Contents + System.Environment.NewLine);
                        }
                        else
                        {
                            DBText text = obj as DBText;
                            if (text != null && text.TextString == "BedRoom")
                            {
                                mylist.Add(text.TextString);
                                ed.WriteMessage(text.TextString + System.Environment.NewLine);
                            }
                        }
                    }
            }
Message 5 of 10
Anonymous
in reply to: J-Rocks

that sounds like you want to have a similar Find (built-in-command) tool, looks like you maybe able to use the TextEditor Class - read about this on the arxmgd.chm - it might help.

Message 6 of 10
J-Rocks
in reply to: Anonymous

I read about this TextEditor class but it seems a little bit difficult to a biginner guy like me , can you give me an example if it is not that bothering ?

 

Thank you

Message 7 of 10
Anonymous
in reply to: J-Rocks

sorry, don't have time for that, and also no need for a tool like this as i am not an autocad user anymore.

maybe there is something already there (similar) never knows in the net, good luck! 

Message 8 of 10
Anonymous
in reply to: Anonymous

see, KEAN WALMSLEY great site about autocad, has an usage sample of this class:

 

http://through-the-interface.typepad.com/through_the_interface/2010/06/changing-the-case-of-an-mtext...

 

just need to do a search.... hth.-

Message 9 of 10
Anonymous
in reply to: J-Rocks

This uses extension methods that are posted at the swamp but should be easy to tell what little typing it saves

for example

 

var mtxt = item.GetEntity<MText>();
///////Change to
 DBObject obj = acTrans.GetObject(item.ObjectId, OpenMode.ForRead) as DBObject;
                        MText mtext = obj as MText;

 

 

        private static IntPtr mtxtPtr = RXObject.GetClass(typeof(MText)).UnmanagedObject;
        [CommandMethod("roomnameHighlight")]
        public void roomnameHighlight()
        {
            using (Transaction trx = Db.TransactionManager.StartTransaction())
            {
                AllowedClassFilter acf = new AllowedClassFilter(typeof(MText), typeof(DBText));
                PromptSelectionResult selResult = Ed.GetSelection(acf);
                if (selResult.Status != PromptStatus.OK){return;}

                    foreach (var item in selResult.Value.GetObjectIds())
                    {
                        if (item.ObjectClass.UnmanagedObject == mtxtPtr)
                        {
                            var mtxt = item.GetEntity<MText>();
                            if (mtxt.Text.Equals("RoomName", StringComparison.OrdinalIgnoreCase))
                            {
                                mtxt.Highlight();
                            }
                        }
                        else
                        {
                            var txt = item.GetEntity<DBText>();
                            if (txt.TextString.Equals("RoomName", StringComparison.OrdinalIgnoreCase))
                            {
                                txt.Highlight();
                            }
                        }
                    }
                trx.Commit();
            }
        }

 

 

Message 10 of 10
J-Rocks
in reply to: Anonymous

Thank you jeff for your help .

 

I have an error on

Intptr 
and
AllowedClassFilter

but the HighLight Method works and I just add it to my codes and it works , though I am looking for a way to SELECT and not just to HIGHLIGHT.

 

The HighLight method is not clear enough to see the highlighted objects if I have many objects .

 

Thank you.

 

 

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

Post to forums  

Forma Design Contest


AutoCAD Beta