Author Topic: LISP to populate attributes in hidden visibility state.  (Read 1961 times)

0 Members and 1 Guest are viewing this topic.

jpcadconsulting

  • Newt
  • Posts: 56
LISP to populate attributes in hidden visibility state.
« on: April 17, 2015, 11:44:05 AM »
Hi folks.

I have a LISP routine that inserts a block and populates its attributes, however it's only populating the attributes that are in the visibility state that is current when the block is inserted.  Heres the code:

Code: [Select]
(defun c:workpoint (/ CRDX CRDY CRDXY ADT P)
(setq atd (getvar 'ATTDIA))
(setvar 'ATTDIA 0)
(while (setq p (getpoint "\n Specify point :"))
(setq CRDX (rtos (car p) 4 0))
(setq CRDY (rtos (cadr p) 4 0))
(setq CRDXY (strcat "(" CRDX ", " CRDY ")"))
  (command "_.-insert"
           "SW Coordinates Tag r00"
           "_none"
           p
           ""
           ""
           ""
           CRDXY
           CRDX
           CRDY
  )
)
(setvar 'ATTDIA atd)
)

The variables CRDX and CRDY are correct but the attributes they populate are in a visibility state that is OFF so... it ain't working.

Anyone know how to assign values to attributes in the "non current" visibility state?

Any help is appreciated, as always.
Technology will save us all! *eyeroll*

ronjonp

  • Needs a day job
  • Posts: 7529
Re: LISP to populate attributes in hidden visibility state.
« Reply #1 on: April 17, 2015, 12:01:31 PM »
Why aren't you using a field for this? Here's some code to get you started .. you'll have to provide the name of the tag you are trying to fill in.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:workpoint (/ b blockname p tag)
  2.   ;; The name of your block
  3.   (setq blockname "SW Coordinates Tag r00")
  4.   ;; The name of the tag you want to fill in
  5.   (setq tag "COORDS")
  6.   (defun _getactivespace (/ ad)
  7.     (if (= (getvar 'cvport) 1)
  8.       (vla-get-paperspace ad)
  9.       (vla-get-modelspace ad)
  10.     )
  11.   )
  12.   ;; (_getactivespace)
  13.   (defun _insertblock (blockname point scale rotation / b blk e spc)
  14.     (if (and blockname
  15.              (setq spc (_getactivespace))
  16.              (if (wcmatch (strcase blockname) "*.DWG")
  17.                (setq b (vl-filename-base blockname))
  18.                (setq b blockname)
  19.              )
  20.              (or (tblobjname "block" b) (findfile (setq b (strcat b ".dwg"))))
  21.         )
  22.       (setq blk (vla-insertblock spc (vlax-3d-point point) b scale scale scale rotation))
  23.     )
  24.     blk
  25.   )
  26.   ;; (_insertblock "foo" (trans (getpoint) 1 0) 5 0)
  27.   (defun _putattvalue (block tag value / att flag)
  28.     (foreach att (vlax-invoke block 'getattributes)
  29.       (if (eq (strcase tag) (strcase (vla-get-tagstring att)))
  30.                  att
  31.                  (if (= (type value) 'str)
  32.                    value
  33.                    (vl-princ-to-string value)
  34.                  )
  35.                )
  36.                (setq flag value)
  37.         )
  38.       )
  39.     )
  40.     flag
  41.   )
  42.   ;; (_putattvalue (car (entsel)) "tagname" "1")
  43.   (while (setq p (getpoint "\n Specify point :"))
  44.     (if (setq b (_insertblock blockname (trans p 1 0) 1 0))
  45.       (_putattvalue b tag (strcat "(" (rtos (car p) 4 0) ", " (rtos (cadr p) 4 0) ")"))
  46.     )
  47.   )
  48.   (princ)
  49. )
« Last Edit: April 17, 2015, 12:27:09 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jpcadconsulting

  • Newt
  • Posts: 56
Re: LISP to populate attributes in hidden visibility state.
« Reply #2 on: April 17, 2015, 12:24:48 PM »
Ah! The crux of the issue.

It seems that using fields will always result in coordinate values in relation to the World Coordinate System, even if a different User Coordiante System is current.

http://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Object-fields-displaying-coordinate-information-relative-to-the-World-UCS.html

My client needs the blocks to represent the X,Y values in relation to 0,0,in the current User Coordinate System.
Technology will save us all! *eyeroll*

jpcadconsulting

  • Newt
  • Posts: 56
Re: LISP to populate attributes in hidden visibility state.
« Reply #3 on: April 17, 2015, 12:26:51 PM »
And thanks for the code ronjonp!!!
Technology will save us all! *eyeroll*