Author Topic: add text to attribute block  (Read 3009 times)

0 Members and 1 Guest are viewing this topic.

77077

  • Guest
add text to attribute block
« on: September 24, 2014, 02:15:05 AM »
Hi guys

There are some shortcomings, need  optimize.

1).why added a new base point ?
2). Need enter "tag" and "prompt" for text

Code: [Select]
(Defun c:addatt        (/ blk txt yn)
  (if
    (and (setq blk (entsel "\n Please pick the block <Exit>:"))
         (setq blk (Car blk))
         (= (cdr (assoc 0 (entget blk))) "INSERT")
                      (null (redraw blk 3))
         (princ
           "\n Please select text to be attached as attributes <Exit>:"
         )
         (setq txt (ssget '((0 . "text"))))
    )
     (progn
       (initget "Yen No")
       (if (null (setq yn
                        (getkword "\n Erase the attached texts [Yes/No] <Yes>:")
                 )
           )
         (setq yn "Yes")
       )
       (vlobj-attach-attrib blk txt (equal yn "Yes"))
     )
  )
)

(Defun vlobj-attach-attrib (blk atx erase / att bbb nxx tmp rtn)
  (setq        bbb blk
        blk (entget bbb)
  )
  (if (not (assoc 66 blk))
    (setq blk (append blk (list (cons 66 1))))
  )
  (setq nxx (list blk))
  (if (and (entnext bbb)
           (= (cdr (assoc 0 (entget (entnext bbb)))) "ATTRIB")
      )
    (while
      (/= (cdr (assoc 0 (entget (setq bbb (entnext bbb)))))
          "SEQEND"
      )
       (setq nxx (cons (entget bbb) nxx))
    )
  )
  (if (= (type atx) 'ename)
    (setq atx (ssadd atx))
  )
  (if (and (= (type atx) 'pickset)
           (setq bbb -1)
      )
    (progn     
      (repeat (sslength atx)
        (if (and (setq att (ssname atx (setq bbb (1+ bbb))))
                 (setq tmp (cdr (assoc 1 (entget att)))) 
                 (setq tmp (list
                             (cons 0 "ATTRIB")
                             (cons 100 "AcDbEntity")
                             (cons 100 "AcDbText")
                             (cons 100 "AcDbAttribute")
                             (cons 1 tmp)
                             (cons 2 (substr tmp 1 10))
                             (cons 6 "ByBlock")
                             (cons 7 "STANDARD")
                             (cons 8 "0")
                             (list 10 0.0 0.0 0.0)
                             (list 11 0.0 0.0 0.0)
                             (cons 40 1.0)
                             (cons 41 1.0)
                             (cons 50 0.0)
                             (cons 51 0.0)
                             (cons 62 256)
                             (cons 70 0)
                             (cons 72 0)
                             (cons 73 0)
                           )
                 )
            )
          (progn
            (foreach bbb '(7 8 10 11 40 41 50 51 72 73)
              (setq
                tmp (subst (cons bbb (cdr (assoc bbb (entget att))))
                           (assoc bbb tmp)
                           tmp
                    )
              )
            )
            (setq nxx (cons tmp nxx))
          )
        )
      )
      (setq nxx        (cons (list (cons 0 "SEQEND")
                            (cons 100 "AcDbEntity")
                            (cons 8 (cdr (assoc 8 blk)))
                      )
                      nxx
                )
      )
      (mapcar 'entmake (reverse nxx))
      (setq rtn (entlast))
      (if (and erase
               (setq bbb -1)
               (entdel (cdr (assoc -1 blk)))
          )
        (repeat        (sslength atx)
          (entdel (ssname atx (setq bbb (1+ bbb))))
        )
      )
    )
  )
  rtn
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: add text to attribute block
« Reply #1 on: September 24, 2014, 03:49:42 AM »
Your code (which doesn't work on BricsCAD) adds attributes to the block reference instead of the block definition. Is that your intention? Note that the prompts for attributes are stored in their definitions (ATTDEF/AcDbAttributeDefinition) belonging to the block definition.

77077

  • Guest
Re: add text to attribute block
« Reply #2 on: September 24, 2014, 04:32:26 AM »
Your code (which doesn't work on BricsCAD) adds attributes to the block reference instead of the block definition. Is that your intention? Note that the prompts for attributes are stored in their definitions (ATTDEF/AcDbAttributeDefinition) belonging to the block definition.

roy, thanks for help ! my intention is adds text to block definition. 

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: add text to attribute block
« Reply #3 on: September 24, 2014, 03:32:29 PM »
roy, thanks for help ! my intention is adds text to block definition.
I would not pursue this if I were you. There are quite a lot of issues to solve and the result will never be a very user-friendly application. Using the block editor (or refedit) will be more convenient.

Some of the issues involved:
1.
Order of the selected text entities and order of existing attdefs.
2.
Translating entities from current drawing space (MS or PS) to block space.
3.
Prompting the user for multiple string values which can be confusing.
4.
Updating existing block references.

But if you really want to do this, using Visual Lisp is probably better (look at the AddAttribute method).
« Last Edit: September 24, 2014, 03:36:29 PM by roy_043 »

77077

  • Guest
Re: add text to attribute block
« Reply #4 on: September 24, 2014, 08:05:36 PM »
roy, thanks for help ! my intention is adds text to block definition.
I would not pursue this if I were you. There are quite a lot of issues to solve and the result will never be a very user-friendly application. Using the block editor (or refedit) will be more convenient.

Some of the issues involved:
1.
Order of the selected text entities and order of existing attdefs.
2.
Translating entities from current drawing space (MS or PS) to block space.
3.
Prompting the user for multiple string values which can be confusing.
4.
Updating existing block references.

But if you really want to do this, using Visual Lisp is probably better (look at the AddAttribute method).


I know , thank you ! roy

danallen

  • Guest
Re: add text to attribute block
« Reply #5 on: September 24, 2014, 08:33:48 PM »
check out for modifying block definitions and updating blocks in place
http://www.lee-mac.com/changeblockinsertion.html

77077

  • Guest
Re: add text to attribute block
« Reply #6 on: September 26, 2014, 08:50:28 AM »
That is not the same

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: add text to attribute block
« Reply #7 on: September 30, 2014, 04:43:47 AM »
im getting this error :

 
Code: [Select]
Erase the attached texts [Yes/No] <Yes>: ; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on unknown exception
"memories fade but the scars still linger"