AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update Block Attribute with LISP

3 REPLIES 3
Reply
Message 1 of 4
TomTom111
2007 Views, 3 Replies

Update Block Attribute with LISP

Hello,

 

I am trying to update my Title Block with a LISP routine (As the title implies).

 

So far, this is what i have...

 

(defun c:aTest (/ ss att)
  (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "TB_PARAMOUNT_ELC")
       (cons 66 1)(if (getvar "CTAB")(cons 410 (getvar "CTAB"))
              (cons 67 (- 1 (getvar "TILEMODE")))))))
    (progn
      (foreach ent (mapcar 'cadr (ssnamex ss))
    (setq att (entnext ent))
    (while (not (eq "SEQEND" (cdadr (entget att))))
      (cond ((eq "DWG" (cdr (assoc 2 (entget att))))
         (entmod (subst (cons 1 "-101") (assoc 1 (entget att)) (entget att)))))
      (setq att (entnext att))))
      (C:AENEXT))
    (princ "\n<!> No Blocks Found <!>"))
  (princ))

 

The title block, block name is static.

The attribute name is static.

 

My ultimate goal is to copy the value of one attribute and "paste" that into the value of another attribute, and itterate this through the entire project.

 

Any help is appreciated.

 

Thomas Walls

CADMASTER TECHNOLOGIES, LLC

www.cadmastertech.com

3 REPLIES 3
Message 2 of 4
vladop
in reply to: TomTom111

Look in ACADE API Help:click question mark in the upper right corner -> Additional Resources->API Help.

API function for attribute modification is:

(c:wd_modattrval ben attnam newval noupd)

 

Here are two examples from ACADE API Help that are used to map next and previous drawing number 

to title block attributes, if that is what you want to do.

 

This is Nate Holt's explaination fot these programs:

The two programs below return the WD_M block's SHEET attribute value
assignment of the next and the previous drawing relative to the current
active drawing. You can set up your title block update utility (via the
".wdt" mapping file) to call each of these small utilities and automatically
update each title block with the SHEET number of the next and previous
drawings.

 

Example 1
Find SHEET number of next drawing past the currently displayed drawing. Find previous drawing's SHEET number as well (using AutoLISP). Note: these values can then be mapped to title block attributes. See example under the section "Invoking API calls from Title Block ".wdt" mapping file."

(defun c:nextsheet ( / ix sheet_lst x sheet)
; Return the WD_M block's SHEET attribute value of "next" dwg in project.
; This embedded in a global called GBL_wd_prj_ixlst.
; If global doesn't exist, make call to refresh it.

(if (not GBL_wd_prj_ixlst)
(setq GBL_wd_prj_ixlst (c:ace_proj_data nil)))
; GBL_wd_cip holds index of current drawing in
; the overall project drawing list.
(setq ix GBL_wd_cip) ; index
; If index not defined for current drawing, then
; trigger a refresh of the global.
(if (OR (not ix)(= ix 0))
(setq ix (c:wd_is_cur_dwg_in_proj))
)
(setq sheet "")
(if (> ix 0)
(progn ; current drawing is in the project,
; increment to next dwg in list
(setq ix (1+ ix)) ; increment index
; Get list of SHEET numbers assigned to
; all dwgs in the project dwg set.
(setq sheet_lst (nth 3 GBL_wd_prj_ixlst))
; Use index number to pull out the
; target drawing's SHEET value. This is
; done by first finding the index
; number is a list of index numbers
; (nth 1 GBL_wd_prj_ixlst), and then
; using the position in this list to
; pull SHEET number from a parallel list
; of sheet numbers in (nth 3 GBL_wd_prj_ixlst)
(if (setq x (member ix (nth 1 GBL_wd_prj_ixlst)))
; found relative position of next
; dwg's data in parallel lists
(setq sheet (nth (- (length (nth 1 GBL_wd_prj_ixlst))(length x))
(nth 3 GBL_wd_prj_ixlst)))
)
))
sheet ; return "" or next SHEET value
)


Example 2
Same as previous example, but find previous drawing.

(defun c:prevsheet ( / ix sheet_lst x sheet)
; Return the WD_M block's SHEET attribute value
; of "next" dwg in project. This embedded in a
; global called GBL_wd_prj_ixlst. If global
; doesn't exist, make call to refresh it.
(if (not GBL_wd_prj_ixlst)
(setq GBL_wd_prj_ixlst (c:ace_proj_data nil)))
; GBL_wd_cip holds index of current drawing in
; the overall project drawing list.
(setq ix GBL_wd_cip) ; index
; If index not defined for current drawing, then
; trigger a refresh of the global.
(if (OR (not ix)(= ix 0))
(setq ix (c:wd_is_cur_dwg_in_proj))
)
(setq sheet "")
(if (> ix 1)
(progn ; current drawing is in the project,
; increment to next dwg in list
(setq ix (1- ix)) ; decrement index
; Get list of SHEET numbers assigned to
; all dwgs in the project dwg set.
(setq sheet_lst (nth 3 GBL_wd_prj_ixlst))
; Use index number to pull out the
; target drawing's SHEET value. This is
; done by first finding the index
; number is a list of index numbers
; (nth 1 GBL_wd_prj_ixlst), and then
; using the position in this list to
; pull SHEET number from a parallel list
; of sheet numbers in (nth 3 GBL_wd_prj_ixlst)
(if (setq x (member ix (nth 1 GBL_wd_prj_ixlst)))
; found relative position of next
; dwg's data in parallel lists
(setq sheet (nth (- (length (nth 1 GBL_wd_prj_ixlst))
(length x))
(nth 3 GBL_wd_prj_ixlst)))
)
))
sheet ; return "" or previous SHEET value
)

 

Message 3 of 4
email2dineshpawar
in reply to: vladop

@vladop, @TomTom111

 

Hello ,

 

I am facing similar kind of problem in my current task I need to go resequencing. for that I want to change attribute "P_Item" of every block in drawing. the program in work fine it change attribute value as per program but it happen only back end, the balloon attached with that block not update atomically as per "P_Item" attribute of that block, but if we change attribute value from UI then balloon can automatically update

 

I tried following command for that as you mention 

(setq aa (car (entsel)))

(c:wd_modattrval aa "P_ITEM" "311" nil)

 

also for 

 

(c:wd_modattrval aa "P_ITEM" "311" 1)

 

but it not update balloon for block aa.

 

Can you help me in that case how can I refresh balloon, drawing through lisp.

 

Message 4 of 4

You must look at the XDATA of the block, and check for the VIA_WD_BALLPTR value. This will give you the handle of the balloon, and then you'll have to update the attribute in balloon also.

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost