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

Searching for text

11 REPLIES 11
Reply
Message 1 of 12
Natalie-C
642 Views, 11 Replies

Searching for text

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!!
11 REPLIES 11
Message 2 of 12
Anonymous
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!!
Message 3 of 12
Natalie-C
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!!
Message 4 of 12
Anonymous
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!!
Message 5 of 12
Natalie-C
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.
Message 6 of 12
Anonymous
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!!
Message 7 of 12
Anonymous
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.
Message 8 of 12
Anonymous
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.
Message 9 of 12
Anonymous
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.
Message 10 of 12
Natalie-C
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!
Message 11 of 12
Natalie-C
in reply to: Natalie-C

That worked perfectly!!!

Thanks a lot.......
Message 12 of 12
simon
in reply to: Natalie-C

I use this code to get text, you could identify the k string

If TypeOf entity Is Autodesk.AutoCAD.DatabaseServices.MText Then
TextBox1.Text += "*MTEXT FOUND " & vbCrLf
Dim Txt As Autodesk.AutoCAD.DatabaseServices.MText = entity
TxtFound = TxtFound + 1
Dim k

k = Txt.Contents
TextBox1.Text += "Contents " & k.ToString & vbCrLf & vbCrLf
TextFnd(1, TxtFound) = k.tostring


k = Txt.Location
TextBox1.Text += "Location " & k.ToString & vbCrLf
Dim Spl
Spl = Mid(k.tostring, 2, Len(k.tostring) - 2)
TextBox1.Text += "SPLIT" & Spl & vbCrLf
Dim sa() As String
sa = Split(Spl, ",", -1)
TextFnd(0, TxtFound) = TxtFound
TextFnd(2, TxtFound) = sa(0)
TextFnd(3, TxtFound) = sa(1)


End If

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