Author Topic: Entmake with Existing Block  (Read 8531 times)

0 Members and 1 Guest are viewing this topic.

AARYAN

  • Newt
  • Posts: 72
Entmake with Existing Block
« on: September 06, 2013, 08:08:53 AM »
Hi All,

Please guide.
If the block is existing in a drawing is there a way to use entmake the same by changing its some of the values (e.g Attributes, Position, color etc.)
I hope there should be some way to do it.

Waiting for your kind Reply.

Regards

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Entmake with Existing Block
« Reply #1 on: September 06, 2013, 10:04:01 AM »
You can (entmake) an INSERT

You will have to also (entmake) all ATTRIButes ( if appropriate ) and then a SEQEND entity as well

-David
R12 Dos - A2K

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #2 on: September 06, 2013, 10:53:14 AM »
Thanks for your reply david.
if i entmake an insert, will the objects other than Attributes be drawn? I mean if no attributes associated to block will entmake insert do the job?

An example is appreciated.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Entmake with Existing Block
« Reply #3 on: September 06, 2013, 01:40:59 PM »

(setq bname "MY_BLOCK")

For an INSERT With 1 ATTRibute ;
Code - Auto/Visual Lisp: [Select]
  1. (and (tblsearch "BLOCK" bname)
  2.      (entmake (list (cons 0 "INSERT")
  3.                     (cons 8 "0")
  4.                     (cons 66 1)
  5.                     (cons 2 bname)
  6.                     (cons 10 (list 0 0 0))
  7.                     (cons 41 1)
  8.                     (cons 42 1)
  9.                     (cons 50 0)
  10.                     (cons 43 1)
  11.                     (cons 70 0)
  12.                     (cons 71 0)
  13.                     (cons 44 0)
  14.                     (cons 45 0)
  15.                     (cons 210 (list 0 0 1))
  16.                     (cons 62 256)
  17.                     (cons 39 0)
  18.                     (cons 6 "BYLAYER")))
  19.      (entmake (list (cons 0 "ATTRIB")
  20.                     (cons 8 "0")
  21.                     (cons 10 (list 0 0 0))
  22.                     (cons 40 1)
  23.                     (cons 1 "TESTING 123")
  24.                     (cons 2 "TAGNAME")
  25.                     (cons 70 0)
  26.                     (cons 73 0)
  27.                     (cons 50 0)
  28.                     (cons 41 1)
  29.                     (cons 51 0)
  30.                     (cons 7 "STANDARD")
  31.                     (cons 71 0)
  32.                     (cons 72 0)
  33.                     (cons 11 (list 0 0 0))
  34.                     (cons 210 (list 0 0 1))
  35.                     (cons 74 0)
  36.                     (cons 62 256)
  37.                     (cons 39 0)
  38.                     (cons 6 "BYLAYER")))
  39.      (entmake (list (cons 0 "SEQEND")
  40.                     (cons 8 "0")))
  41.      )
  42.  
   
You will have to make an (entmake ) call for each ATTRibute

For an INSERT WithOUT ATTRibutes ;

Code - Auto/Visual Lisp: [Select]
  1. (and (tblsearch "BLOCK" bname)
  2.      (entmake (list (cons 0 "INSERT")
  3.                     (cons 8 "0")
  4.                     (cons 66 0)
  5.                     (cons 2 bname)
  6.                     (cons 10 (list 0 0 0))
  7.                     (cons 41 1)
  8.                     (cons 42 1)
  9.                     (cons 50 0)
  10.                     (cons 43 1)
  11.                     (cons 70 0)
  12.                     (cons 71 0)
  13.                     (cons 44 0)
  14.                     (cons 45 0)
  15.                     (cons 210 (list 0 0 1))
  16.                     (cons 62 256)
  17.                     (cons 39 0)
  18.                     (cons 6 "BYLAYER")))
  19. )
  20.  

Other than simple single ATTRIBUTES, I believe that for ATTRIbuted BLOCKs that the (command "_.INSERT" ....) is much easier.  Translating the text points can be quite a daunting task.


-David
R12 Dos - A2K

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #4 on: September 06, 2013, 02:43:37 PM »
Thanks your examples are very clear.
i agree command option is easier but its very slow in a large operation.
i am actually tring to insert block atts at multiple coords from the text file which has more than 4 lacs of points and command is taking more than 5 hours to complete where activex reduces the time by half of it. i heard entmake is the fastest one so i am chasing it.

is there any other way for the fastest import.

regards

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Entmake with Existing Block
« Reply #5 on: September 06, 2013, 02:54:02 PM »
To insert with as many attributes as you wish;

Code - Auto/Visual Lisp: [Select]
  1.   (defun ABLKInsert (BlockName / Ename NextEnt Data Attdefs)
  2.     (setq BlkIP (if (= BlkPT nil)'(0 0 )BlkPT)
  3.           rAng  (if (= rAng  nil)0   rAng)
  4.           color (if (= color nil)256 color)
  5.           )
  6.     (cond
  7.       ((setq Ename (tblobjname "block" BlockName))      ;; get Parent entity name
  8.        (setq NextEnt (entnext Ename))                   ;; first sub entity
  9.  
  10.        (while NextEnt                                   ;; get ATTDEF subentities
  11.          (setq Data (entget NextEnt))
  12.          (if (= "ATTDEF" (cdr (assoc 0 Data)))
  13.            (setq Attdefs (cons Data Attdefs))
  14.            )
  15.          (setq NextEnt (entnext NextEnt))
  16.          )
  17.        (setq attblk (if (= nil attdefs) 0 1))
  18.        (and
  19.          (entmake                                       ;; entmake insert
  20.            (list
  21.              '(0 . "INSERT")
  22.              '(100 . "AcDbBlockReference")
  23.               (cons  8 Lname   )                        ;; layer name
  24.               (cons 66 attblk   )
  25.               (cons  2 BlockName)
  26.               (cons 10 BlkIP  )                         ;; Insert Point
  27.               (cons 41 1.0)
  28.               (cons 42 1.0)
  29.               (cons 43 1.0)
  30.               (cons 50 rAng  )                          ;; Rotation angle default = 0
  31.               (cons 62 color )                          ;; Color 256 = bylayer
  32.              )
  33.            )
  34.          (foreach x (reverse Attdefs)                   ;; entmake ATTRIBs based on ATTDEFS
  35.            (entmake
  36.              (list
  37.                '(0 . "ATTRIB")
  38.                 (assoc  8 x)
  39.                 (assoc 10 x)
  40.                 (assoc 40 x)
  41.                 (assoc  1 x)
  42.                 (assoc 50 x)
  43.                 (assoc 41 x)
  44.                 (assoc 51 x)
  45.                 (assoc  7 x)
  46.                 (assoc 71 x)
  47.                 (assoc 72 x)
  48.                 (assoc 11 x)
  49.                 (assoc  2 x)
  50.                 (assoc 70 x)
  51.                 (assoc 73 x)
  52.                 (assoc 74 x)
  53.                )
  54.              )
  55.            )
  56.          (entmake '((0 . "SEQEND")(8 . "0")))    ;; entmake SEQEND
  57.          )
  58.        )
  59.       (T nil)
  60.       )
  61.     (setq ent (entlast)
  62.           BlkPT nil
  63.           rAng  nil
  64.           color nil
  65.           )
  66.     );defun   (setq blockname "lot 6design intent" attdefs nil)

I don't bother to try to Translate the attribute points, I usually just insert @ 0,0 then perform a move & rotate command if required...

Once block is inserted I then have an attribute update function to update the attributes to the correct values....
« Last Edit: September 06, 2013, 03:02:03 PM by snownut2 »

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #6 on: September 06, 2013, 03:22:06 PM »
Thank you so much snownut2.
This must be the solution for fast operation. but i have to ignore other graphical entities associated with it. Can i get those entities too if possible?

Regards

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Entmake with Existing Block
« Reply #7 on: September 06, 2013, 03:28:54 PM »
You can add whatever entities you like just before the entmake "SeqEnd" line....

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #8 on: September 06, 2013, 03:37:53 PM »
Thanks a lot.
Cheers...

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #9 on: December 13, 2013, 03:10:48 PM »
Dear All

The function shared by Snownut2 works great but if i have to change the position of the block the how can I update the position of the attributes? as of now their positions are based on nearby 0,0,0 and if i change the block position they are still on nearby 0,0,0. Is there a way I can calculate the exact position (Dxf code 10 & 11) of the attributes based on the new position of insert?

Please help as I am stuck only on this point.

Regards

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Entmake with Existing Block
« Reply #10 on: December 13, 2013, 04:56:06 PM »
I use a move command after inserting the block @ 0,0.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  (ABLKInsert blk)                                          ; inserts block with attributes (sets varialbe ent to block inserted)
  3.   (command "move" ent "" 0,0 pause)         ;this example uses a pause for user input, you could also use a predefined location.
  4.  

You could easily add a rotate command also.

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #11 on: December 14, 2013, 12:49:54 AM »
Thanks for your reply snownut2.

But issuing move command may affect the speed of the routine as i have lacs of points.
The actual position of the attributes are on nearby 0,0 not exact on 0,0 and even their justifications could be different. Isnt there a way I can calculate the 10 & 11th position of the attributes from insbase and then entmake them based on new position like 500000,21425000,13.1?

Any help would be highly appreciated.
Regards

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Entmake with Existing Block
« Reply #12 on: December 14, 2013, 05:54:02 AM »
Assuming everything is WCS, a starting call could look like :

Code: [Select]

  (setq bb (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 insert_def)))))
        ip (cdr (assoc 10 insert_def))
        ir (cdr (assoc 50 insert_def))
        ix (cdr (assoc 41 insert_def))
        iy (cdr (assoc 42 insert_def))
        iz (cdr (assoc 43 insert_def))
       a10 (mapcar
             '*
              (polar ip ir (distance ip
                           (mapcar '- (cdr (assoc 10 attdef_def)) bb)))
              (list ix iy iz))
       a11 (mapcar
             '*
              (polar ip ir (distance bb
                           (mapcar '- (cdr (assoc 11 attdef_def)) bb)))
              (list ix iy iz)))

Translating to the INSERT OCS would be a lot more complex.  Also scaling ( dxf 40 & 41 ) of the attribute would not be fun. This would be made even more difficult if the ATTRIB are not WCS

-David
R12 Dos - A2K

AARYAN

  • Newt
  • Posts: 72
Re: Entmake with Existing Block
« Reply #13 on: December 16, 2013, 01:25:29 AM »
Thanks for Your Crucial Input Mr.David,
I tried the routine in this way and still no Luck. The 10 and 11 position is not coming as it should be.
 I am attaching the block drawing file and also the routine. Please review it as I might miss something.

Code: [Select]
(DEFUN ENTMAKEBLOCK (BLOCKNAME BPOSITION BLAYER BCOLOR BLINETYPE BSCALE)
  (SETQ IATTDEFS NIL)
  (SETQ BATTLIST (LIST "TEST1" "TEST2"))
  (IF (SETQ INSENT (TBLOBJNAME "BLOCK" BLOCKNAME))
    (WHILE INSENT
      (IF (= (CDR (ASSOC 0 (SETQ IBLOCKENT (ENTGET INSENT))))
     "ATTDEF"
  )
(SETQ IATTDEFS (CONS IBLOCKENT IATTDEFS))
      )
      (SETQ INSENT (ENTNEXT INSENT))
    )
  )
  (SETQ SYMBOLINSBASE (CDR (ASSOC 10 (TBLSEARCH "BLOCK" BLOCKNAME))))
  (ENTMAKE (LIST (CONS 0 "INSERT") (CONS 100 "AcDbBlockReference") (CONS 100 "AcDbEntity")
(CONS 2 BLOCKNAME) (CONS 6 BLINETYPE) (CONS 8 BLAYER) (CONS 10 BPOSITION)
(CONS 41 BSCALE) (CONS 42 BSCALE) (CONS 43 BSCALE) (CONS 50 0.0) (CONS 62 BCOLOR) (CONS 66 (IF IATTDEFS 1 0))))
  (SETQ BCOUNT -1)
  (WHILE IATTDEFS
    (SETQ BATTENT (CAR IATTDEFS))
    (SETQ IATTDEFS (CDR IATTDEFS))
    (SETQ BATTSTR (NTH (SETQ BCOUNT (1+ BCOUNT)) BATTLIST))
    (ENTMAKE (LIST (CONS 0 "ATTRIB")
   (CONS 100 "AcDbAttribute")
   (CONS 100 "AcDbEntity")
   (CONS 1 (IF BATTSTR BATTSTR ""))
   (ASSOC 2 BATTENT)
   (ASSOC 6 BATTENT)
   (ASSOC 7 BATTENT)
   (ASSOC 8 BATTENT)
   (CONS 10 (MAPCAR (QUOTE *) (POLAR BPOSITION 0.0 (DISTANCE BPOSITION (MAPCAR (QUOTE -) (CDR (ASSOC 10 BATTENT)) SYMBOLINSBASE)))
    (LIST BSCALE BSCALE BSCALE)))
   (CONS 11 (MAPCAR (QUOTE *) (POLAR BPOSITION 0.0 (DISTANCE SYMBOLINSBASE (MAPCAR (QUOTE -) (CDR (ASSOC 11 BATTENT)) SYMBOLINSBASE)))
    (LIST BSCALE BSCALE BSCALE)))
   (CONS 40 BSCALE)
   (ASSOC 41 BATTENT)
   (ASSOC 50 BATTENT)
   (ASSOC 51 BATTENT)
   (ASSOC 62 BATTENT)
   (ASSOC 70 BATTENT)
   (ASSOC 71 BATTENT)
   (ASSOC 72 BATTENT)
   (ASSOC 73 BATTENT)
   (ASSOC 74 BATTENT))))
  (ENTMAKE (LIST (CONS 0 "SEQEND") (CONS 8 BLAYER)))
(ENTLAST))

Any help would be highly appreciated.

Regards

Bernie

  • Guest
Re: Entmake with Existing Block
« Reply #14 on: November 28, 2014, 10:09:09 AM »
Hi Aaryan,
Here you go with what I think works well.
Code: [Select]
;;; ==========================================================================
;;;  E_Insert - adapted from the swamp  [ ABLKInsert ]
;;;  place block with Emake instead of command INSERT
;;; usage:   (E_Insert  BlockName  InsPunt insLayer )
;;; -
;;;  these may have a preset value, which will be used and reset to nil:
;;; E_InsPt E_rAng E_dAng E_Color E_Scale
;;; ==========================================================================

(defun E_Insert (BlockName E_InsPt E_InsLay / Ename NextEnt Data Attdefs Attblk pt10 pt11)
  (setq E_InsPt (ifnot E_InsPt '(0 0) E_InsPt)
E_rAng (if E_rAng    ; wordt nil gemaakt aan einde
   E_rAng
   (if E_dAng    ; E_dAng = angel in degrees.
     (deg_rad E_dAng)
     0
   )
)
E_Color (ifnot E_Color 256)    ; wordt nil gemaakt aan einde
E_Scale (ifnot E_Scale 1.0)    ; wordt nil gemaakt aan einde
E_InsLay (ifnot E_InsLay (getvar "clayer"))
  )
  ;; alleen als het block al bestaat ....
  (cond ((setq Ename (tblobjname "block" BlockName))    ; tblsearch
;; get Parent entity name
(setq NextEnt (entnext Ename))
;; first sub entity
(while NextEnt
   ;; get ATTDEF subentities
   (setq Data (entget NextEnt))
   (if (= "ATTDEF" (cdr (assoc 0 Data)))
     (setq Attdefs (cons Data Attdefs))
   )
   (setq NextEnt (entnext NextEnt))
)
(setq Attblk (if (= nil attdefs)
0
1
      )
)    ;(pri "attdefs")
(and (entmake ;; entmake insert
       (list '(0 . "INSERT")
     '(100 . "AcDbBlockReference")
     (cons 8 E_InsLay)    ; layer name
     (cons 66 Attblk)
     (cons 2 BlockName)
     (cons 10 E_InsPt)    ; Insert Point
     (cons 41 E_Scale)
     (cons 42 E_Scale)
     (cons 43 E_Scale)
     (cons 50 E_rAng)    ; Rotation angle default = 0
     (cons 62 E_Color)    ; E_Color 256 = bylayer
       )
      )
      (foreach x (reverse Attdefs)
;; voor de atributen met FIT alignments....
(setq pt10 (plusXY (cdr (assoc 10 x)) E_InsPt))
(setq pt11 (plusXY (cdr (assoc 11 x)) E_InsPt))
;; entmake ATTRIBs based on ATTDEFS
(entmake (list '(0 . "ATTRIB")
       (assoc 8 x)
       (cons 10 pt10)
       (assoc 40 x)
       (assoc 1 x)
       (assoc 50 x)
       (assoc 41 x)
       (assoc 51 x)
       (assoc 7 x)
       (assoc 71 x)
       (assoc 72 x)
       (cons 11 pt11)
       (assoc 2 x)
       (assoc 70 x)
       (assoc 73 x)
       (assoc 74 x)
)
)
      )
      (entmake '((0 . "SEQEND") (8 . "0")))    ; entmake SEQEND
)
)
(t nil)
  )
  (setq ent (entlast)
E_InsPt nil
E_rAng nil
E_dAng nil
E_Color nil
E_Scale nil
  )
)
;; ==========================================================================
;; used routine.. (cause i sometimes forget how mapcar works)
(defun Plusxy (p disp / p3)    ; ipv polar    mag 2D en 3D zijn. 
  (setq p3 (mapcar '+ p disp))    ; telt afstand (x,y,z) op bij punt (x,y,z)
)
;; littlebit shorter if nil check function
(defun ifnot (def new /)
  (if def
    def
    new
  )
)
(defun deg_rad (fDeg) (/ (* fDeg pi) 180))

some words may look funny, they are not! I am Dutch.
Hope this works for you, even if it was a while.
the trick is probably what I did with pt10 and pt11, check it out. 
And of cause, after this 'insert', you still need to fill the Attributes.
« Last Edit: November 28, 2014, 10:12:34 AM by Bernie »