Lisp for combining multiple block attributes into a main block

Lisp for combining multiple block attributes into a main block

timothy.birdwell
Enthusiast Enthusiast
3,046 Views
26 Replies
Message 1 of 27

Lisp for combining multiple block attributes into a main block

timothy.birdwell
Enthusiast
Enthusiast

                I am looking for a lisp either already created or help with creating. What it needs to do is gather data from other blocks and incorporate that data into one block. In this situation my main block would be Fiber_Ped, I need to incorporate the data from the other blocks into it. A test drawing will be supplied. All I need from the second block is the assignment number and the address.

368

916 WACO OAKDALE LA 71463

369

 

370

 

371

 

372

 

403

 

 

                So essentially the Lisp would need create a new attribute system, that can house the information stored from the other blocks up to 12 assignment numbers.

0 Likes
3,047 Views
26 Replies
Replies (26)
Message 21 of 27

timothy.birdwell
Enthusiast
Enthusiast

That worked so beautiful! I am going to try and tweak it, instead of a new block insertion have it recall that and place in the existing fiber ped box. I'll link a new test drawing to show you. The fields I would like to populate on the fiber ped block is ASSIGNMENT_I, ASSIGNMENT_II.....etc

0 Likes
Message 22 of 27

Sea-Haven
Mentor
Mentor

Ask admin to merge your other post with this one. 

 

There is a simple way to do this as Fibre ped has like 21 attributes you can take advantage of populate item 10+ in the attributes with the OD data. You dont need to worry about Tagnames. When you use 'getattributes it retrieves in creation order so can skip 1st 11, Content x. Need to edit the code previously provided to check item number. 

 

0 Likes
Message 23 of 27

timothy.birdwell
Enthusiast
Enthusiast

On line 70, 

70. (command "-insert" "FIBER_PED" (getpoint "\nPick insertion point ") 9 9 0)

is there a way to make it not come in as a fiber ped but as mtext? I am trying to combine this code with it 

(defun c:MTTB ( / LM:str->lst lstProps eMtext lstMtext eBlock)
  ;;MText - To - Block
  (defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
      (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
      (list str)
    )
  )
  (setq lstProps '("ASSIGNMENT_I" "ASSIGNMENT_II" "ASSIGNMENT_III" "ASSIGNMENT_IV" "ASSIGNMENT_V" "ASSIGNMENT_VI"
                   "ASSIGNMENT_VII" "ASSIGNMENT_VIII" "ASSIGNMENT_IX" "ASSIGNMENT_X" "ASSIGNMENT_XI" "ASSIGNMENT_XII"))
  (if (and (setq eMtext (car (entsel "\nSelect MText: ")))
           (eq "MTEXT" (cdr (assoc 0 (entget eMtext))))
           (setq lstMtext (LM:str->lst (getpropertyvalue eMtext "Text") "\r")
                 lstMtext (vl-remove "" (apply 'append (mapcar '(lambda (x) (LM:str->lst x "\n")) lstMtext))))
      );and
    (if (and (setq eBlock (car (entsel "\nSelect Block for MText Values: ")))
             (eq "INSERT" (cdr (assoc 0 (entget eBlock))))
             (eq "FIBER_PED" (strcase (getpropertyvalue eBlock "BlockTableRecord/Name")))
        );and
      (mapcar
        '(lambda (prop str) (setpropertyvalue eBlock prop str))
        lstProps
        lstMtext
      );mapcar
    ;else
      (prompt "\nBad BLOCK entity...")
    );if
  ;else
    (prompt "\nBad MTEXT entity...")
  );if
  (prompt "\nMTTB Complete.")
  (princ)
);defun

so I don't have to purge the block, then turn dtext into mtext then use the c:dfoo command to populate the existing block

 

0 Likes
Message 24 of 27

timothy.birdwell
Enthusiast
Enthusiast

Could you explain this part of the code 

(setq odname (ade_odgettables ent))
(setq Stnum (ade_odgetfield ent odname "STREET_NUMBER" 0))
(setq Stname (ade_odgetfield ent odname "STREET_NAME" 0))
(setq state (ade_odgetfield ent odname "STATE" 0))
(setq Pcode (ade_odgetfield ent odname "POSTAL_CODE" 0))

if I am following it right, stnum, stname, state,  and pcode, belong to the variable of odname correct? When I try to add another to the string it comes back as nil

0 Likes
Message 25 of 27

timothy.birdwell
Enthusiast
Enthusiast

@Sea-Haven @paullimapa

   So this is my revision of the code after breaking it down and trying to understand what every thing is doing. I was able to debug the errors. I can now produce a list the way I need it. Next step Is to use this list to autofill a block with assigned tables. I have a lisp that will grab mtext and place the values in. Which I will add as well. I would like to find a way to use this stored information already to bypass placing a block; this has me purge it and convert text to mtext, and then I use the lisp to fill the block.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-combining-multiple-block-attributes-into-a-main-block/td-p/11637019
; an attempt by AlanH Dec 2022
;itteration by TCB Jan 2023
(defun c:fiber ()
  (princ "\n Pick 1 block object for block name ")
  (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))
    (if (= ss nil)
      (alert "You may not have picked a block please try again")
      (progn
        (setq blk (vlax-ename->vla-object (ssname ss 0)))
        (setq bname (vla-get-name blk))
        (if (wcmatch bname "*U#*")
          (setq bname (vla-get-effectivename blk))
        );end if
        (princ "\nSelect the blocks ")
        (setq ss (ssget '((0 . "INSERT"))))
          (if (= ss nil)
            (alert "No blocks picked will exit")
            (progn
              (setq lst '())
              (repeat (setq x (sslength ss))
                (setq ent (ssname ss (setq x (- x 1))))
                (setq blk (vlax-ename->vla-object ent))
                (setq blkname (vla-get-name blk))
                (if (wcmatch blkname "*U#*")
                  (setq blkname (vla-get-effectivename blk))
                );end if       
                (if (= blkname bname)
                  (progn
                    (setq atts (vlax-invoke blk 'Getattributes))
                    (if (= atts nil)
                      (princ "No Atts")
                      (progn
                        (foreach att atts
                          (setq lst2 (cons (vla-get-textstring att) lst2))
                        )
                        (setq odname (ade_odgettables ent))
                        (setq Fbss (ade_odgetfield ent odname "FIBER_ASSIGNEMENT" 0))
                        (setq Stnum (ade_odgetfield ent odname "STREET_NUMBER" 0))
                        (setq Stname (ade_odgetfield ent odname "STREET_NAME" 0))
                        (setq state (ade_odgetfield ent odname "STATE" 0))
                        (setq Pcode (ade_odgetfield ent odname "POSTAL_CODE" 0))
                        (setq lst (cons (list (strcat Fbss " | " stnum " " stname " " state " " pcode)) lst))
                      ); end prog
                    );end if
                  );end prog
                );end if
              );end repeat
            );end prog
          );end if
      );end progn
);end if
);end fun

Mtext to block

 

;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/mtext-to-block-data/td-p/11593844
;ronjonp Dec 2022
(defun c:MTTB ( / LM:str->lst lstProps eMtext lstMtext eBlock)
  ;;MText - To - Block
  (defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
      (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
      (list str)
    )
  )
  (setq lstProps '("ASSIGNMENT_I" "ASSIGNMENT_II" "ASSIGNMENT_III" "ASSIGNMENT_IV" "ASSIGNMENT_V" "ASSIGNMENT_VI"
                   "ASSIGNMENT_VII" "ASSIGNMENT_VIII" "ASSIGNMENT_IX" "ASSIGNMENT_X" "ASSIGNMENT_XI" "ASSIGNMENT_XII"))
  (if (and (setq eMtext (car (entsel "\nSelect MText: ")))
           (eq "MTEXT" (cdr (assoc 0 (entget eMtext))))
           (setq lstMtext (LM:str->lst (getpropertyvalue eMtext "Text") "\r")
                 lstMtext (vl-remove "" (apply 'append (mapcar '(lambda (x) (LM:str->lst x "\n")) lstMtext))))
      );and
    (if (and (setq eBlock (car (entsel "\nSelect Block for MText Values: ")))
             (eq "INSERT" (cdr (assoc 0 (entget eBlock))))
             (eq "FIBER_PED" (strcase (getpropertyvalue eBlock "BlockTableRecord/Name")))
        );and
      (mapcar
        '(lambda (prop str) (setpropertyvalue eBlock prop str))
        lstProps
        lstMtext
      );mapcar
    ;else
      (prompt "\nBad BLOCK entity...")
    );if
  ;else
    (prompt "\nBad MTEXT entity...")
  );if
  (prompt "\nMTTB Complete.")
  (princ)
);defun

 

0 Likes
Message 26 of 27

timothy.birdwell
Enthusiast
Enthusiast

Ok here is where I am at so far, I can call up each string of data now, so if x=(assignement_I) and y=(653 | 145 KRISTY LN LA 70634). How do I make them update the value on the new block?


(defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
      (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
      (list str)
    )
  )
 (setq lstProps '("ASSIGNMENT_I" "ASSIGNMENT_II" "ASSIGNMENT_III" "ASSIGNMENT_IV" "ASSIGNMENT_V" "ASSIGNMENT_VI"
                   "ASSIGNMENT_VII" "ASSIGNMENT_VIII" "ASSIGNMENT_IX" "ASSIGNMENT_X" "ASSIGNMENT_XI" "ASSIGNMENT_XII"))
  (if (and (setq eName (car (entsel "\n Select object for OD: ")))
(setq eData (entget eName))
(setq ss (ssget '((0 . "INSERT"))))
(progn
(setq lst '())
  (repeat (setq x (sslength ss))
  (setq ent (ssname ss (setq x (- x 1))))
(setq odname (ade_odgettables ent))
(setq Fber (ade_odgetfield ent odname "FIBER_ASSIGNEMENT" 0))
(setq Stnum (ade_odgetfield ent odname "STREET_NUMBER" 0))
(setq Stname (ade_odgetfield ent odname "STREET_NAME" 0))
(setq state (ade_odgetfield ent odname "STATE" 0))
(setq Pcode (ade_odgetfield ent odname "POSTAL_CODE" 0)) 
    (setq lst (cons (list (strcat fber " | " stnum " " stname " " state " " pcode)) lst))
  )
)
);and
    (if (and (setq eBlock (car (entsel "\nSelect Block for MText Values: ")))
             (eq "INSERT" (cdr (assoc 0 (entget eBlock))))
             (eq "FIBER_PED" (strcase (getpropertyvalue eBlock "BlockTableRecord/Name")))
   (mapcar
        '(lambda (prop str) (setpropertyvalue eBlock prop str))
        lstProps
        lstMtext
      );mapcar
    ;else
      (prompt "\nBad BLOCK entity...")
    );if
  ;else
    (prompt "\nBad Block entity...")
  );if
  (prompt "\nMTTB Complete.")
  (princ)
  )
  ;);defun
  

 

0 Likes
Message 27 of 27

Sea-Haven
Mentor
Mentor

On holidays at moment may be a week before I get to it. Some one else may jump in.

0 Likes