Entities inside a block

Entities inside a block

Anonymous
Not applicable
356 Views
17 Replies
Message 1 of 18

Entities inside a block

Anonymous
Not applicable
When issuing a call to SSGET, I want to be able to search inside of the
defined blocks in the drawing and look for a text object with for example
the text "FOUNDME". I then want to change this text value to something else
such as "NEWTEXT". Issuing (ssget "x" '((1 . "FOUNDME"))) does not search
blocks defined in the drawing. I suspect that I need to search through the
block table using (TBLSEARCH). Thanks,

Ryan Small
--
Visit our website at http://www.braemarbldg.com
E-Mail: [email protected]
0 Likes
357 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable
Yep.

Kind of.

Have to walk the block table, and then descend thru each block definition.

__________________________________

Michael Puckett
[email protected]
> Not < an Autodesk hall monitor.
Imagination makes all things possible.
__________________________________

Ryan Small wrote in message
news:01bf2c8e$6043d6a0$a3a43dcf@user3...
When issuing a call to SSGET, I want to be able to search inside of the
defined blocks in the drawing and look for a text object with for example
the text "FOUNDME". I then want to change this text value to something else
such as "NEWTEXT". Issuing (ssget "x" '((1 . "FOUNDME"))) does not search
blocks defined in the drawing. I suspect that I need to search through the
block table using (TBLSEARCH). Thanks,

Ryan Small
--
Visit our website at http://www.braemarbldg.com
E-Mail: [email protected]
0 Likes
Message 3 of 18

Anonymous
Not applicable
Ssget doesn't search inside of blocks, so you're forced to
do this manually. If you're using AutoCAD 2000, you could
do it much faster with ActiveX. Otherwise, you'd have to
iterate through the block table and manually examine each
entity in each block's definition.

This will replace all text in every block, that matches a
wildcard pattern with a specified replacement string:

(defun replace-nested-text (pattern replacetext / block ent data)
(while (setq block (tblnext block (not block)))
(setq ent (cdr (assoc -2 block)))
(while ent
(setq data (entget ent))
(if (and (eq (cdr (assoc 0 data)) "TEXT")
(wcmatch (cdr (assoc 1 data)) pattern)
)
(entmod (list (cons -1 ent) (cons 1 replacetext)))
)
)
)
)

(replace-nested-text "FOUNDME" "NEWTEXT")

Ryan Small wrote:
>
> When issuing a call to SSGET, I want to be able to search inside of the
> defined blocks in the drawing and look for a text object with for example
> the text "FOUNDME". I then want to change this text value to something else
> such as "NEWTEXT". Issuing (ssget "x" '((1 . "FOUNDME"))) does not search
> blocks defined in the drawing. I suspect that I need to search through the
> block table using (TBLSEARCH). Thanks,
>
> Ryan Small
> --
> Visit our website at http://www.braemarbldg.com
> E-Mail: [email protected]

--
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* [email protected] */
/* http://ourworld.compuserve.com/homepages/tonyt */
/*********************************************************/
0 Likes
Message 4 of 18

Anonymous
Not applicable
How would I modify this routine to look for a certain block name and a certain text string and change the width of the text string?

Tim
0 Likes
Message 5 of 18

Anonymous
Not applicable
How are you getting the block? If it is text, then you can just select it
with 'nenetsel' and then change it from there, and since it is a peace of
text it will update all the blocks that are inserted. If it is an
attribute, then you will have to search the whole drawing for that block,
then seach each attribute to find the correct tag, and change all the
widths.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:[email protected]...
How would I modify this routine to look for a certain block name and a
certain text string and change the width of the text string?

Tim
0 Likes
Message 6 of 18

Anonymous
Not applicable
I need to be able to do it without user input. I want to write it so that I can run it on a group of drawings.

Attributes are easy compared to this. I can not for the life of me figure out how to get to a subentity of a block...like text, and change that text width.
Sure I can redefine it with insert=, but this block will have title area info in it that will be different from drawing to drawing. I just need to change a specific text string's (I know the value) width. I also know the block name.

Thanks, Tim
0 Likes
Message 7 of 18

Anonymous
Not applicable
Okay here is how I would do it.

(defun ChangeTextWidth (BlkName TextStr TextWid)

(vlax-for Blk (vla-get-Blocks (vla-get-ActiveDocument
(vlax-get-Acad-Object)))
(if (= (strcase (vla-get-Name Blk)) (strcase BlkName))
(vlax-for Obj Blk
(if
(and
(=(vla-get-ObjectName Obj) "AcDbText")
(= (vla-get-TextString Obj) TextStr)
)
(vla-put-ScaleFactor Obj TextWid)
)
)
)
)
(princ)
)

Or even better, since this one won't search the whole block collection.

(defun ChangeTextWidth-v02 (BlkName TextStr TextWid / Blk)

(if (not (vl-catch-all-error (setq Blk (vl-catch-all-apply 'vla-Item (list
(vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))))))))
(vlax-for Obj Blk
(if
(and
(= (vla-get-ObjectName Obj) "AcDbText")
(= (vla-get-TextString Obj) TextStr)
)
(vla-put-ScaleFactor Obj TextWid)
)
)
)
(princ)
)

Watch for word wrap.
--

Tim
"A blind man lets nothing block his vision."


wrote in message news:[email protected]...
I need to be able to do it without user input. I want to write it so that I
can run it on a group of drawings.

Attributes are easy compared to this. I can not for the life of me figure
out how to get to a subentity of a block...like text, and change that text
width.
Sure I can redefine it with insert=, but this block will have title area
info in it that will be different from drawing to drawing. I just need to
change a specific text string's (I know the value) width. I also know the
block name.

Thanks, Tim
0 Likes
Message 8 of 18

Anonymous
Not applicable
Getting this error...

; error: no function definition: VL-CATCH-ALL-ERROR

Thanks, Tim
0 Likes
Message 9 of 18

Anonymous
Not applicable
vl-catch-all-error-p

wrote in message news:[email protected]...
Getting this error...

; error: no function definition: VL-CATCH-ALL-ERROR

Thanks, Tim
0 Likes
Message 10 of 18

Anonymous
Not applicable
Here is what I ran...

(ChangeTextWidth-v02 "PDMS_BACK" "SHELL EASTERN PETROLEUM (PTE) LTD." "0.9")

It ran now without errors, but the text did not change.
I verified the block name and text string. They are both valid.

Ideas?
0 Likes
Message 11 of 18

Anonymous
Not applicable
The text width is a real, not a string. Try it again without the quotes
around the 0.9.

Thanks Michael for catching the typo.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:[email protected]...
Here is what I ran...

(ChangeTextWidth-v02 "PDMS_BACK" "SHELL EASTERN PETROLEUM (PTE) LTD." "0.9")

It ran now without errors, but the text did not change.
I verified the block name and text string. They are both valid.

Ideas?
0 Likes
Message 12 of 18

Anonymous
Not applicable
I had already tried that and it didn't make a difference.

Is there something else [like (vl-load-com)] that you may be assuming that I have loaded that needs to be loaded?

Thanks....
0 Likes
Message 13 of 18

Anonymous
Not applicable
Did you regen after the command?

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:[email protected]...
I had already tried that and it didn't make a difference.

Is there something else [like (vl-load-com)] that you may be assuming that I
have loaded that needs to be loaded?

Thanks....
0 Likes
Message 14 of 18

Anonymous
Not applicable
yes
0 Likes
Message 15 of 18

Anonymous
Not applicable
Here is the DXF data for the text entity...

100
AcDbEntity
8
PDMS_BACK
62
2
100
AcDbText
10
661.17075
20
26.4877
30
0.0
40
3.75
1
SHELL EASTERN PETROLEUM (PTE) LTD.
41
0.9
7
O8111901
72
1
11
702.177
21
28.3627
31
0.0


BTW: Thanks for the help......
0 Likes
Message 16 of 18

Anonymous
Not applicable
If you were using v02, which I would, there was another typo. I forgot to
add the block name to the search. Here you go. Tested and works. Sorry
about that.

(defun ChangeTextWidth-v02 (BlkName TextStr TextWid / Blk)

(if (not (vl-catch-all-error-p (setq Blk (vl-catch-all-apply 'vla-Item (list
(vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
BlkName)))))
(vlax-for Obj Blk
(if
(and
(= (vla-get-ObjectName Obj) "AcDbText")
(= (vla-get-TextString Obj) TextStr)
)
(vla-put-ScaleFactor Obj TextWid)
)
)
)
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)
(princ)
)


--

Tim
"A blind man lets nothing block his vision."


wrote in message news:[email protected]...
yes
0 Likes
Message 17 of 18

Anonymous
Not applicable
bingo...thnx.....ura genuis....

I may come back at you for explanations as to what is doing what so I understand better.

Again...thanks for the help...

Tim
0 Likes
Message 18 of 18

Anonymous
Not applicable
You're welcome.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:[email protected]...
bingo...thnx.....ura genuis....

I may come back at you for explanations as to what is doing what so I
understand better.

Again...thanks for the help...

Tim
0 Likes