Author Topic: extracting textstring from dtext to place as block name  (Read 2861 times)

0 Members and 1 Guest are viewing this topic.

bsteele

  • Guest
extracting textstring from dtext to place as block name
« on: February 02, 2007, 03:45:21 PM »
let me explain, I have a drafter who was told by an engineer to create water pipe fittings. So he finally accomplished this and placed Dtext titles under each to describe what each was. What the ENG. forgot to tell him was that he wanted to set up a block library with all these fittings. the blocks are easy enough to macro into blocks, but transferring the title to the block name is way over my head. Is there a way to "LISP" this?
Any and all help would be greatly appreciated. I know I've seen Text Extraction done here before, but I can't seem to plug in the right key words into the search engine to get any useful results.

Again, TIA
Brad

T.Willey

  • Needs a day job
  • Posts: 5251
Re: extracting textstring from dtext to place as block name
« Reply #1 on: February 02, 2007, 03:50:31 PM »
So you have one drawing, with 20 or some blocks (number not important) that are not blocks yet, with a text string under them?  So you want to select the objects to make a block, then pick the text string for the name of the blocks?  Then I guess you will need to pick a point for the insertion point of the blocks also.

If so this can be done pretty easily.  If you don't want help with all that, and you only want to get the text string of the text selected, then look at the association code 1.  Use 'entsel' 'entget' 'assoc' and 'cdr'.  <---- Hints  :-)

Welcome to theswamp.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #2 on: February 02, 2007, 04:00:50 PM »
Thanks for responding,
I think I might need a few more "hints", though........ : :-o

Brad

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: extracting textstring from dtext to place as block name
« Reply #3 on: February 02, 2007, 04:18:36 PM »
Why not WBLOCK the valve with title & you enter the name as you wish?
Did I miss something here?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #4 on: February 02, 2007, 04:36:18 PM »
CAB, I wish it would be that easy. The "wish" of the engineer is to have a single file library with all blocks attached. I can see the reasoning behind it, with the "design library" thing. But still, to have to Wblock all 2000 +/-  then make sure they ALL get converted to block definitions, and having to retype the convoluted naming conventions using the "title text" And trusting a Newbie to do it right.......I hope you can see my dilemma. I would want something as foolproof as possible, without having to stand over his shoulder at every step...


Thanks for the suggestion, though. Any thoughts on this is helpful.

Brad

T.Willey

  • Needs a day job
  • Posts: 5251
Re: extracting textstring from dtext to place as block name
« Reply #5 on: February 02, 2007, 04:49:43 PM »
How comfortable are you with writting lisp?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #6 on: February 02, 2007, 05:17:59 PM »
I usually do stuff like this:
(command "circle" pause pause)
I have been able to "borrow" pieces out of lisp that I understand from this Great place, But, I am far from even being competent at creating my own. I usually combine a Toolbar/menu macro with some lisp to get what I need.
an example would look like this:
[Single Pick Mtext]^C^C(progn (initdia)(command "._mtext" (getpoint) "_W" "0")(princ))

T.Willey

  • Needs a day job
  • Posts: 5251
Re: extracting textstring from dtext to place as block name
« Reply #7 on: February 02, 2007, 05:41:12 PM »
Okay.  Here is how I would do it.
Code: [Select]
(defun c:MakeBlock (/ ss sel entdata String InsPt)

(if
 (and
  (setq ss (ssget))
  (setq sel (entsel "\n Select text object with desired name of block: "))
  (setq entdata (entget (car sel)))
  (= (cdr (assoc 0 entdata)) "TEXT")
  (setq String (cdr (assoc 1 entdata)))
  (setq InsPt (getpoint "\n Select insertion point: "))
 )
 (command "_.-block" String InsPt ss "")
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #8 on: February 02, 2007, 07:14:57 PM »
THANK YOU THANK YOU, Very nice!!!

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #9 on: February 05, 2007, 11:06:51 AM »
Great help Mr. Willley. I have another question, you know how when you make a block, there is an option to convert the "blocked" entities into a "inserted" block definition, can this be done via Lisp or in a macro using the MB.lsp which works perfectly.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: extracting textstring from dtext to place as block name
« Reply #10 on: February 05, 2007, 11:11:10 AM »
Not really, but you can add a command to insert it after it blocks it.  Change this part
Code: [Select]
(command "_.-block" String InsPt ss "")
to
Code: [Select]
(progn
  (command "_.-block" String InsPt ss "")
  (command "_.-insert" String InsPt "" "" "")
 )
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #11 on: February 05, 2007, 11:46:13 AM »
Hi T. Willey,
I must be doing something wrong, here is what I have so far:

(defun c:MB (/ ss sel entdata String InsPt)
(if
 (and
  (setq ss (ssget))
  (setq sel (entsel "\n Select text object with desired name of block: "))
  (setq entdata (entget (car sel)))
  (= (cdr (assoc 0 entdata)) "TEXT")
  (setq String (cdr (assoc 1 entdata)))
  (setq InsPt (getpoint "\n Select insertion point: "))
 )
 progn
  (command "_.-block" String InsPt ss "")
  (command "_.-insert" String InsPt "" "" "")
 )
)
 (princ)
)

I apoligize for being unable to "format the code" correctly, I know it's some thing simple that I just can't see.
TIA
Brad

T.Willey

  • Needs a day job
  • Posts: 5251
Re: extracting textstring from dtext to place as block name
« Reply #12 on: February 05, 2007, 11:59:47 AM »
You forgot the parenthesis before the 'progn'.
Code: [Select]
(defun c:MB (/ ss sel entdata String InsPt)
(if
 (and
  (setq ss (ssget))
  (setq sel (entsel "\n Select text object with desired name of block: "))
  (setq entdata (entget (car sel)))
  (= (cdr (assoc 0 entdata)) "TEXT")
  (setq String (cdr (assoc 1 entdata)))
  (setq InsPt (getpoint "\n Select insertion point: "))
 )
[color=red] (progn[/color]
  (command "_.-block" String InsPt ss "")
  (command "_.-insert" String InsPt "" "" "")
 )
)
 (princ)
)
And you should use code tags.  How you ask.
[ code ] no spaces
Code goes here
[ /code ] no spaces again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

bsteele

  • Guest
Re: extracting textstring from dtext to place as block name
« Reply #13 on: February 05, 2007, 12:30:34 PM »
Thanks a bunch, Tim. Like I said, I KNEW it was something dumb. The MB lisp is a thing of beauty!
Great to know I can always find help here.

Forever in debt,
Brad

T.Willey

  • Needs a day job
  • Posts: 5251
Re: extracting textstring from dtext to place as block name
« Reply #14 on: February 05, 2007, 12:40:56 PM »
You're welcome Brad.  Now you just need to start learning Lisp yourself, or some other language, and you can be off and running.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.