DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

need macro to find text, zoom in on it

Started by Mark Laing, December 10, 2010, 04:35:23 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Mark Laing

this sounded so simple when I thought of it. input the desired text, find the desired text, and zoom in on it.
trouble is, I use getselect to find it, and then I can't deselect everything else. Any help would be appreciated. I've included the macro so far.
it falls down in the 'found' subroutine.
thanks.



sys(800) = 01
INCLUDE "DcadAlias.d3i"
Input "Find ? ", found$

sys(1027) = 0
Precision 0
On Error goto stop
If sys(80)= 0 then goto oops
start:

For i = 1 to sys(80)
getselect i, entnum
entity entnum
query ent_type, e
If e = 13 then goto check
next i

check:
query t_text, j$
if j$ = found$ then goto found
next i

found:

PUTATTR entity, type, {select, laynum, group, red, green, blue, solid}
'>ID_ZOOM_SELECTION
'{
'}

stop:
End


Oops:
>Selectall
{
}
goto start

handler:
end

Bob P

Are the quoted lines in this for debugging?

PUTATTR entity, type, {select, laynum, group, red, green, blue, solid}
'>ID_ZOOM_SELECTION
'{
'}
...

I didn't test this out but shouldn't

PUTATTR entity, type, {select, laynum, group, red, green, blue, solid}
>ID_ZOOM_SELECTION
{
}
Have a line here to de-select the entity?
PUTATTR entity, type, {0, laynum, group, red, green, blue, solid}      Is that the correct syntax???

End

paulerens

PUTATTR entity, type, select, laynum, group, red, green, blue, solid
Test this, no quoted lines.

Paul.

Mark Laing

For some reason I couldn't get 'change ent_selected, 1' to work.
I used 'change ent_layer, 666' and selcected that, and zoomed in on it, and changed it's layer back.
But I would like to how to use ent_selected, or hear that it's a bug.

paulerens

#4
Input "Text?",found$
For j = 1 to Sys(9)
Entity j
 If Sys(90) = 13 Then   ' 13 For 2Dtext 119 for Multiline text
   a$ = Sys$(1)
    End If
   If a$ = found$ Then
   PutAttr j, 13, 1           'select = 1
  End If
Next j
>ID_ZOOM_SELECTION
{
 }
Regen
End

magic

Hi Paul,

It looks like it works, but only when you know the whole text.

You can't find just the start, a middle bit, or the end.

However, if the text occurs more than once, it will zoom in on some place in the middle.
It's a kind of magic!




paulerens

Hi magic,

That's right, therefore, this very complex macro.  ;D

>FindText
{
 }

dcadRob

If you want to find a partial string then change IF A$=FOUND$ THEN to IF INSTR(A$,FOUND$)<>0 THEN

Mark Laing

Wow that was a LOT simpler, more direct than what I was trying. And it answered the selection question. Thank you much. I love this board.

magic

Hi dcadRob,

That works like a charm. Now the only thing missing is to be able to search without knowing, if your text includes capital letters.
It's a kind of magic!




dcadRob

magic,

Did you try 'Find/Replace Text' (Main menu->Edit)? It's not case sensitive. If you have the info box open, it shows the text and lets you edit without closing the 'Find' window.

That's what paulerens proposed with the following macro code which opens the 'Find' window:

>FindText
{
  }

PS It's not listed in the V17 macro help. Not sure which versions have it.

Mark Laing

I thought the 'find text' thing was a joke. I still use mostly v17 because of the dimension text, and only run v20 for importing, exporting, and prlinting. I don't recall that findtext being advertised as an improvement on any version.
Might have to step up to v.20

GooPie

Hello,

Sorry for my bad English. My language is French.
I registered in this forum since short time.
This forum is for me a great help. :D

This macro is what I was looking for:
--------------------------------------------------------------------
Input "Text?",found$
For j = 1 to Sys(9)
Entity j
  If Sys(90) = 13 Then   ' 13 For 2Dtext 119 for Multiline text
    a$ = Sys$(1)
     End If
    If a$ = found$ Then
    PutAttr j, 13, 1           'select = 1
   End If
Next j
>ID_ZOOM_SELECTION
{
  }
Regen
End
--------------------------------------------------------------------

However, if the desired text entity does not exist in the drawing, we have a command error DesignCad "ID_ZOOM_SELECTION."

How to display first the message "Number text entities found = ..." and then zoom to selection?
How to display the message "No entity text found" instead of the error message?

Thank you for your help.

Goopie

prl

Quote from: GooPie on February 23, 2015, 01:49:25 AM
How to display first the message "Number text entities found = ..." and then zoom to selection?
How to display the message "No entity text found" instead of the error message?

Here you go Goopie,

Added/corrected code is in blue


sys(80)=0
Input "Text?",found$
For j = 1 to Sys(9)
Entity j
  If Sys(90) = 13 Then   ' 13 For 2Dtext 119 for Multiline text
    a$ = Sys$(1)
     End If
    If a$ = found$ Then
    PutAttr j, 13, 1           'select = 1
   End If
Next j

if sys(80)> 0 then
   >ID_ZOOM_SELECTION
   {
   }
   precision 0
   count = sys(80)
   Message  "Number text entities found = ...", count
else
   Message  "No entity text found"
endif


sys(1)=0
End

GooPie

Thank you prl
It is exactly what I wanted.
:D :D :D