Author Topic: Block Definition & EntLast  (Read 5410 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Block Definition & EntLast
« on: November 16, 2006, 02:21:56 PM »
While defining a block I am adding text & want to get the bounding box for that text.
Trying EntLast doesn't work because the text although created i not yet added to the
database. At least that is what I suppose. Is there a way to use the bounding box on
this text, or am I forced to create all item first & add then to the block?
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block Definition & EntLast
« Reply #1 on: November 16, 2006, 02:28:32 PM »
I think you can't use anything because Acad doesn't know it exists in the database yet.  I was working on getting the height and width of text, so one could use this sub to get the bounding box (true one) with any rotation, but it isn't going as nice as I hoped.  You could add one to the database, get the bounding box for it, and delete it.
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block Definition & EntLast
« Reply #2 on: November 16, 2006, 03:50:21 PM »
Thanks Tim, that's what I suspected.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block Definition & EntLast
« Reply #3 on: November 16, 2006, 04:04:20 PM »
Can you entmake a block with objects that already exist?

Can you add entities to an existing block definition?
« Last Edit: November 16, 2006, 04:05:59 PM by CAB »
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block Definition & EntLast
« Reply #4 on: November 16, 2006, 04:47:46 PM »
Can you entmake a block with objects that already exist?
Not sure.

Can you add entities to an existing block definition?
Yes.  I only know how with ActiveX controls.  I have one where I replace a block definitions with new objects.  I get the blocks definition, and then erase all them, and then fill it in with the new objects.  Let me see if I can clean it up a little.  It's when I first started learning ObjectDBX and the ActiveX controls.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block Definition & EntLast
« Reply #5 on: November 16, 2006, 05:02:11 PM »
It would take to long to clean it up, so here is a quick example of what I'm talking about.  You must have a block named 'TestBlock' in the drawing before you use it.
Code: [Select]
(defun c:AddObjectToBlock (/ ActDoc BlkCol BlkObj Ent ObjList)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq BlkCol (vla-get-Blocks ActDoc))
(setq BlkObj (vla-Item BlkCol "TestBlock"))
(setq Ent (entsel))
(setq ObjList (list (vlax-ename->vla-object (car Ent))))
(vlax-invoke ActDoc 'CopyObjects ObjList BlkObj)
)
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block Definition & EntLast
« Reply #6 on: November 16, 2006, 05:04:46 PM »
Thanks Tim, i will look into that method.
For the short term I have resorted to the .-Block command.  :-(
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block Definition & EntLast
« Reply #7 on: November 16, 2006, 05:10:59 PM »
I know the feeling.  I hate using 'command' calls in lisp routines now.  One thing to point out is that when adding the new object to the blocks definition, it will be placed relative to '(0.0 0.0 0.0).
Tim

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

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Block Definition & EntLast
« Reply #8 on: November 16, 2006, 10:37:28 PM »
I may be missing something, but have you tried the texbox function with enough dxf data to accurately represent the text as defined in the burgeoning block definition?

e.g. --

Code: [Select]
(textbox
   '(
        (0 . "text")
        (6 . "romans")
        (40 . 0.09375)
        (1 . "Miss ya'll.")
    )
)

=>

Code: [Select]
(
    (0.0 -0.03125 0.0)
    (0.734375 0.09375 0.0)
)

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block Definition & EntLast
« Reply #9 on: November 16, 2006, 11:28:38 PM »
Where have you been? See what happens when your away too long. 8-)
Seriously though, I miss remembered the textbox & though it needed an ename too.
Well I'll redo the routine again. At least now it will work the way I had intended. :-)

Thanks Michael.
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.

Tramber

  • Guest
Re: Block Definition & EntLast
« Reply #10 on: November 17, 2006, 03:35:36 AM »
I would have helped if had read this topic early enough. 'Cause Textbox was one of the first function I ever used and learned. I can even remember the looking of the page in the R13 customizing book !

Now that we are talking about ancient time, I would like to introduce you to my old little routines, before I learned the Copyobjects Method.

Code: [Select]
(defun injecto (j / i element elementGet)
  (setq i 0)
  (while (< i (sslength j))
    (setq element (ssname j i))
    (setq elementGet (entget element))
    (setq i (1+ i))
    (entmake elementGet))) 

(defun FAITBLO (nom jeu oudonc / ea eb);(setq nom "pot3D" jeu jeuab oudonc pt0)
    (setq ea (list (cons 0 "block") (CONS 2 nom) (cons 10 oudonc) (cons 70 64)))
    (setq eb (list (cons 0 "endblk")) index 0)
    (entmake ea)
    (injecto jeu)
    (entmake eb)
    (repeat(sslength jeu)(entdel (ssname jeu index))(setq index (1+ index)))
  )
       
(defun FAITBLO+ (nom ent+ oudonc+ / lisor jeux+ fir)
  (setq oudonc+(if(=(length oudonc+)2)(AP-2D->3D oudonc+)oudonc+) lisor nil jeux+(ssadd)
fir (cdr(assoc -2 (tblsearch "block" nom))) pt+ (cdr(assoc 10 (tblsearch "block" nom))))
  (if(not pt+)(setq pt+ '(0 0 0)))
  (while fir(setq lisor(append lisor(list (entget fir))))(setq  fir (entnext fir)))
  (repeat (length lisor)    (entmake (nth 0 lisor))(setq jeux+(ssadd(entlast)jeux+))(setq lisor (cdr lisor)))
  (entmake(mapcar  '(lambda (x)
          (cond((=(car x)10)(if(=(length x)4)
      (list 10 (+(cadr x)(-(car pt+)(car oudonc+)))(+(caddr x)(-(cadr pt+)(cadr oudonc+)))(-(cadddr x)(-(caddr pt+)(caddr oudonc+))))
      (list 10 (+(cadr x)(-(car pt+)(car oudonc+)))(+(caddr x)(-(cadr pt+)(cadr oudonc+))))))
       ((=(car x)11)(if(=(length x)4)
      (list 11 (+(cadr x)(-(car pt+)(car oudonc+)))(+(caddr x)(-(cadr pt+)(cadr oudonc+)))(-(cadddr x)(-(caddr pt+)(caddr oudonc+))))
      (list 11 (+(cadr x)(-(car pt+)(car oudonc+)))(+(caddr x)(-(cadr pt+)(cadr oudonc+))))))
       (T x)))(entget ent+)))
  (setq jeux+(ssadd (entlast) jeux+))  (entdel ent+)
  (FAITBLO nom jeux+ pt+)
  lisor)

(defun FAITBLO- (nom  / lisor jeux- fir)
  (setq lisor nil jeux-(ssadd) fir (cdr(assoc -2 (tblsearch "block" nom))) pt+ (cdr(assoc 10 (tblsearch "block" nom))))
  (while fir(setq lisor(append lisor(list (entget fir))))(setq fir (entnext fir)))
  (repeat (1-(length lisor))   (entmake (nth 0 lisor))(setq jeux-(ssadd(entlast)jeux-))(setq lisor (cdr lisor)))
  (FAITBLO nom jeux- pt+)
  lisor)

I wrote them when I was a beginner with ENTMAKE (not so long ago but still prehistoric !)

FAITBLO works with a name, a Sset and a base point and ENTMAKEs a block def
FAITBLO+ works with a name, a Entityname and a base point (stupid) and ADD an object to the block def
FAITBLO- works with a name and remove the last object of a block def

All that stuff is old fashion to me but I still use them ! Hope you won't (joking) !

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block Definition & EntLast
« Reply #11 on: November 17, 2006, 12:17:36 PM »
Well thank you Bert.  :-)
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.

Tramber

  • Guest
Re: Block Definition & EntLast
« Reply #12 on: November 17, 2006, 12:27:50 PM »
Well thank you Bert.  :-)

Frankly, won't you rather use the CopyObject Method, I'm sure you will.

I wanted to answer your question which was :
Quote
Can you entmake a block with objects that already exist?

The answer is no, unless you re-Entmake all, as you saw in my routines.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block Definition & EntLast
« Reply #13 on: November 17, 2006, 12:48:14 PM »
Thanks Bert.

I have a working solution using the commands -BLOCK & -INSERT but am still working on this.

This is the pseudo code
Start Block definition
Create lines, etc
Create text
Create a rectangle, offset from the text bounding box
Create more text
Finish the block definition


The minor problem I have now is that the entlist created for the text object has the insert point cpt
at middle center as expected but the TextTable returns the ll & ur relative to 0,0
That is ll is always 0,0 so I need to find the mid point ll - ur & then calc the new points based on
that & cpt
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.

LE

  • Guest
Re: Block Definition & EntLast
« Reply #14 on: November 17, 2006, 01:23:56 PM »
The minor problem I have now is that the entlist created for the text object has the insert point cpt
at middle center as expected but the TextTable returns the ll & ur relative to 0,0
That is ll is always 0,0 so I need to find the mid point ll - ur & then calc the new points based on
that & cpt

Master Alan;

I have two function in my post about lisp here in the show your stuff, that might do what you want, anyway here is a short sample:

Original posted here:
http://www.theswamp.org/index.php?topic=9441.msg121484#msg121484

Code: [Select]
(defun transptblk_pt  (ptblk porig ang fx fy / sinang cosang xptblk
       yptblk)
  (setq sinang (sin ang)
cosang (cos ang)
xptblk (car ptblk)
yptblk (cadr ptblk))
  (list
    (+ (- (* xptblk cosang fx) (* yptblk sinang fy))
       (car porig))
    (+ (+ (* xptblk sinang fx) (* yptblk cosang fy))
       (cadr porig))
    0))

(defun transpt_ptblk
       (pt porig ang fx fy / sinang cosang dx dy xpt ypt)
  (setq sinang (sin ang)
cosang (cos ang)
dx     (car porig)
dy     (cadr porig)
xpt    (- (car pt) dx)
ypt    (- (cadr pt) dy))
  (list
    (/ (+ (* xpt cosang) (* sinang ypt)) fx)
    (/ (- (* cosang ypt) (* xpt sinang)) fy)
    0))

(defun dxf (code elist) (cdr (assoc code elist)))

(setq blk (car (entsel "\nSelect one block: ")))

(setq datblk (entget blk)
      nomblk (dxf 2 datblk)
      porig  (dxf 10 datblk)
      angblk (dxf 50 datblk)
      fx     (dxf 41 datblk)
      fy     (dxf 42 datblk))

(setq ent1 (car (nentsel "\nSelect a nested entity - a text: ")))

(setq ed (entget ent1)
      ;; point returned transformed
      v1 (transptblk_pt
   (dxf 10 ed)
   porig
   angblk
   fx
   fy))

;; point returned without transformation
(setq pt (dxf 10 ed))

HTH