.NET

Reply
Contributor
Natalie-C
Posts: 19
Registered: ‎07-11-2006
Message 1 of 12 (90 Views)

Searching for text

90 Views, 11 Replies
08-10-2006 06:54 AM
This question may be to broad or general. I don't know but here it goes anyway....

Is there a way to search for a specific text string on a layer in autocad?

Any help or a point in the right direction would be appreciated!!
*Paul Richardson
Message 2 of 12 (90 Views)

Re: Searching for text

08-10-2006 07:59 AM in reply to: Natalie-C
//?
string ln = "layerName";
if (ln.Contains("stringToFind"))
{
...
}

wrote in message news:5264527@discussion.autodesk.com...
This question may be to broad or general. I don't know but here it goes
anyway....

Is there a way to search for a specific text string on a layer in autocad?

Any help or a point in the right direction would be appreciated!!
Contributor
Natalie-C
Posts: 19
Registered: ‎07-11-2006
Message 3 of 12 (90 Views)

Re: Searching for text

08-10-2006 08:22 AM in reply to: Natalie-C
Thanks for the response but it just doesn't seem to be working.

I've tried several different things.

I'm currently getting the current layer:
Dim lt As LayerTable = CType(trans.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
Dim ltr As LayerTableRecord = CType(trans.GetObject(db.Clayer, OpenMode.ForRead), LayerTableRecord)
If ltr.Name.Contains("TheStringToFind") Then
MsgBox("Found It!!")
End IF

This doesn't work.

I've also tried:

Dim ln AS String = "CurrentLayer"
If ln.Contains("TheStringToFind") Then
MsgBox("Found It!!")
End If

That doesn't seem to work either? Am I missing something, doing something wrong?

Thanks Again....a bunch!!
*Paul Richardson
Message 4 of 12 (90 Views)

Re: Searching for text

08-10-2006 09:06 AM in reply to: Natalie-C
>ltr.Name.Contains("TheStringToFind")
I assume you're changing "TheStringToFind" to
the string you're looling for?

wrote in message news:5264752@discussion.autodesk.com...
Thanks for the response but it just doesn't seem to be working.

I've tried several different things.

I'm currently getting the current layer:
Dim lt As LayerTable = CType(trans.GetObject(db.LayerTableId,
OpenMode.ForRead), LayerTable)
Dim ltr As LayerTableRecord = CType(trans.GetObject(db.Clayer,
OpenMode.ForRead), LayerTableRecord)
If ltr.Name.Contains("TheStringToFind") Then
MsgBox("Found It!!")
End IF

This doesn't work.

I've also tried:

Dim ln AS String = "CurrentLayer"
If ln.Contains("TheStringToFind") Then
MsgBox("Found It!!")
End If

That doesn't seem to work either? Am I missing something, doing something
wrong?

Thanks Again....a bunch!!
Contributor
Natalie-C
Posts: 19
Registered: ‎07-11-2006
Message 5 of 12 (90 Views)

Re: Searching for text

08-10-2006 09:10 AM in reply to: Natalie-C
Yes, you would be right. I am changing "TheStringToFind".

Exactly what I am doing is checking the layer to see if a specific string already exist before placing it on the layer. I just haven't figured out a way to search or find text.
*Paul Richardson
Message 6 of 12 (90 Views)

Re: Searching for text

08-10-2006 09:14 AM in reply to: Natalie-C
>Dim ln AS String = "CurrentLayer"
>If ln.Contains("TheStringToFind") Then
>MsgBox("Found It!!")
>End If

This would only be True if "TheStringToFind"
was contained in "CurrentLayer"; which it is
not.




"Paul Richardson" wrote in message
news:5264838@discussion.autodesk.com...
>ltr.Name.Contains("TheStringToFind")
I assume you're changing "TheStringToFind" to
the string you're looling for?

wrote in message news:5264752@discussion.autodesk.com...
Thanks for the response but it just doesn't seem to be working.

I've tried several different things.

I'm currently getting the current layer:
Dim lt As LayerTable = CType(trans.GetObject(db.LayerTableId,
OpenMode.ForRead), LayerTable)
Dim ltr As LayerTableRecord = CType(trans.GetObject(db.Clayer,
OpenMode.ForRead), LayerTableRecord)
If ltr.Name.Contains("TheStringToFind") Then
MsgBox("Found It!!")
End IF

This doesn't work.

I've also tried:

Dim ln AS String = "CurrentLayer"
If ln.Contains("TheStringToFind") Then
MsgBox("Found It!!")
End If

That doesn't seem to work either? Am I missing something, doing something
wrong?

Thanks Again....a bunch!!
*Paul Richardson
Message 7 of 12 (90 Views)

Re: Searching for text

08-10-2006 10:54 AM in reply to: Natalie-C
It's in c#, but should give you the idea.

Sample call:
SSFilter("Text", "Layer1", "bar");

[code]
public static void SSFilter(string entType,

string layerName, string txtToFind)

{

Editor ed = Autodesk.AutoCAD.ApplicationServices.

Application.DocumentManager.MdiActiveDocument.Editor;

Database db = HostApplicationServices.WorkingDatabase;

TypedValue[] filter = new TypedValue[2]

{

new TypedValue((int)DxfCode.Start, entType),

new TypedValue((int)DxfCode.LayerName, layerName)

};



SelectionFilter filterSS = new SelectionFilter(filter);

PromptSelectionResult psr = ed.SelectAll(filterSS);



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

{

ObjectIdCollection idCol =

new ObjectIdCollection(psr.Value.GetObjectIds());



using (Transaction tr =

db.TransactionManager.StartTransaction())

{



foreach (ObjectId id in idCol)

{

DBText dbt = (DBText)tr.GetObject

(id, OpenMode.ForRead, false);

if (((String)dbt.TextString).Contains(txtToFind))

{

//rip it up.

}

}



}



}

}

[/code]



wrote in message news:5264843@discussion.autodesk.com...
Yes, you would be right. I am changing "TheStringToFind".

Exactly what I am doing is checking the layer to see if a specific string
already exist before placing it on the layer. I just haven't figured out a
way to search or find text.
*Paul Richardson
Message 8 of 12 (90 Views)

Re: Searching for text

08-10-2006 10:57 AM in reply to: Natalie-C
Wow was that ugly...Here's a txt file.

"Paul Richardson" wrote in message
news:5265051@discussion.autodesk.com...
It's in c#, but should give you the idea.

Sample call:
SSFilter("Text", "Layer1", "bar");

[code]
public static void SSFilter(string entType,

string layerName, string txtToFind)

{

Editor ed = Autodesk.AutoCAD.ApplicationServices.

Application.DocumentManager.MdiActiveDocument.Editor;

Database db = HostApplicationServices.WorkingDatabase;

TypedValue[] filter = new TypedValue[2]

{

new TypedValue((int)DxfCode.Start, entType),

new TypedValue((int)DxfCode.LayerName, layerName)

};



SelectionFilter filterSS = new SelectionFilter(filter);

PromptSelectionResult psr = ed.SelectAll(filterSS);



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

{

ObjectIdCollection idCol =

new ObjectIdCollection(psr.Value.GetObjectIds());



using (Transaction tr =

db.TransactionManager.StartTransaction())

{



foreach (ObjectId id in idCol)

{

DBText dbt = (DBText)tr.GetObject

(id, OpenMode.ForRead, false);

if (((String)dbt.TextString).Contains(txtToFind))

{

//rip it up.

}

}



}



}

}

[/code]



wrote in message news:5264843@discussion.autodesk.com...
Yes, you would be right. I am changing "TheStringToFind".

Exactly what I am doing is checking the layer to see if a specific string
already exist before placing it on the layer. I just haven't figured out a
way to search or find text.
*Paul Richardson
Message 9 of 12 (90 Views)

Re: Searching for text

08-10-2006 11:44 AM in reply to: Natalie-C
There was no need, in the code I posted, for the
block({}) around the code after the if statement.
Note the return, don't confuse with:
if()
{
}

Here is that portion without the {}.
[/code]
if (psr.Status != PromptStatus.OK) return;

ObjectIdCollection idCol =
new ObjectIdCollection(psr.Value.GetObjectIds());

using (Transaction tr =
db.TransactionManager.StartTransaction())
{

foreach (ObjectId id in idCol)
{
DBText dbt = (DBText)tr.GetObject
(id, OpenMode.ForRead, false);
if (((String)dbt.TextString).Contains(txtToFind))
{
//rip it up.
}
}

}
[/code]
"Paul Richardson" wrote in message
news:5265057@discussion.autodesk.com...
Wow was that ugly...Here's a txt file.

"Paul Richardson" wrote in message
news:5265051@discussion.autodesk.com...
It's in c#, but should give you the idea.

Sample call:
SSFilter("Text", "Layer1", "bar");

[code]
public static void SSFilter(string entType,

string layerName, string txtToFind)

{

Editor ed = Autodesk.AutoCAD.ApplicationServices.

Application.DocumentManager.MdiActiveDocument.Editor;

Database db = HostApplicationS
ervices.WorkingDatabase;

TypedValue[] filter = new TypedValue[2]

{

new TypedValue((int)DxfCode.Start, entType),

new TypedValue((int)DxfCode.LayerName, layerName)

};



SelectionFilter filterSS = new SelectionFilter(filter);

PromptSelectionResult psr = ed.SelectAll(filterSS);



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

{

ObjectIdCollection idCol =

new ObjectIdCollection(psr.Value.GetObjectIds());




using (Transaction tr =

db.TransactionManager.StartTransaction())

{



foreach (ObjectId id in idCol)

{

DBText dbt = (DBText)tr.GetObject

(id, OpenMode.ForRead, false);

if (((String)dbt.TextString).Contains(txtToFind))

{

//rip it up.

}

}



}



}

}

[/code]



wrot
e in message news:5264843@discussion.autodesk.com...
Yes, you would be right. I am changing "TheStringToFind".

Exactly what I am doing is checking the layer to see if a specific string
already exist before placing it on the layer. I just haven't figured out a
way to search or find text.
Contributor
Natalie-C
Posts: 19
Registered: ‎07-11-2006
Message 10 of 12 (90 Views)

Re: Searching for text

08-10-2006 02:19 PM in reply to: Natalie-C
Thanks, I'm trying it now!!

I'll post back when I'm done to let you know how it goes.

Thanks again!
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 or visit the Installation and Licensing Forum to get help installing your software.