Author Topic: trouble access attributes created in lisp  (Read 2399 times)

0 Members and 1 Guest are viewing this topic.

marcoblanco120

  • Guest
trouble access attributes created in lisp
« on: August 17, 2011, 09:42:31 AM »
Hi all,

I'm slowly learning some lisp and am stuck trying to get my attributes to be accessible from a block I've created using a LISP rountine.  Can anyone show me what I am missing? The attributes are part of the block, but not accessible when you insert it.



here is my code....

Code: [Select]
(defun c:ins ();(/ RAD ptx1 ptx2 pty1 pty2 x1 x y y1 z z1 pt1 pt2 pt3 pt4 blockname)


;--- define block center point
(setq circleCenter '(0 0 0))

;--- define circle radius andmake circle
(Setq RAD 35.0) 

;;;--- Define block name
(setq blockname "plcount")

;;;--- start block creation
(createBlockStart blockname circleCenter)
 
;;;--- open up center point for manipulating 
(pullxyz circleCenter)
 
;--- create boundary working points
(setq RAD ( / RAD 2)
ptx1 (-  X RAD)  ;locates start of line
ptx2 (-  RAD X);locates end of line


      pty1 (+ Y (/ RAD 2));locates attribute no 1
      pty2 (- Y (/ RAD 2));locates attribute no 2
        )
 
;--- create line xyz values
(setq pt1 (replace_xyz pt1 ptx1 Y Z));locates start of line
(setq pt2 (replace_xyz pt2 ptx2 Y Z));locates end of line
(setq pt3 (replace_xyz pt3 X pty1 Z)) ;locates attribute no 1
(setq pt4 (replace_xyz pt4 X pty2 Z)); locates attribute no 2
 
;--- create attribute one
(setq txtht (/ RAD 2)) 
(makeatt  pt3 pt3 "sym" "sym" "Xxx" txtht)

;--- create attribute two
(makeatt  pt4 pt4 "qty" "qty" "0" txtht)

;--- create dividing line
(createline pt1 pt2)
 
 
;--- create boundary circle
(createCircle circleCenter RAD)


;--- Block is Complete 
(Endblock)

  ); defun




;;;
;;;INSERT group codes:
;;;group code 70 = Column count
;;;syntax:  (createBlockStart blockName insertPt)
;;;
(defun createBlockStart (blockName insertPt)
  (entmake (list (cons 0 "BLOCK")
         (cons 2 blockName)
         (cons 70 0)
         (cons 10 insertPt)
         )
       )
  )
;;;
;;;
 

;;;******************************************



(defun EndBlock ()
 (entmake
        (list
          (cons 0 "ENDBLK")
          (cons 8 "0")
        )
      )
  )

;;;    **************************************






;;;
;;;syntax:  (createCircle center radius)
;;;
(defun createCircle (circleCenter circleRadius)
  (entmake (list (cons 0 "CIRCLE")
         '(100 . "AcDbEntity") '(100 . "AcDbCircle")
         (cons 10 circleCenter)
         (cons 40 circleRadius)
         )
       )
  )
;;;

;;;--- Break up XYZ into X Y Z

 (defun pullXYZ (coord / coord1)
   (mapcar 'set '(x y z) coord)
  );

 ;;;--- Replace the XYZ value from a xyz coordinate with X0 y0 z0 variables
 
 (defun replace_XYZ (coord  x y z / coord1)
   (setq XYZ nil
XYZ (list x y z)
)
          );defun

;;;
;;;--- make an attribute
(defun makeatt (origin location att1def att1tag att1name txtht ); / origin location att1def att1tag att1name)

(setq vl
   (list (cons 0 "ATTDEF")
      (cons 8 "0")
      (cons 10 Origin);origin
      (cons 11 Location); placement
      (cons 1 att1def );Default attribute value
      (cons 2 att1tag);;Attribute tag (string; cannot contain spaces)
      (cons 3 att1name);attribute name
      (cons 40 txtht);Text Height
      (cons 41 1.0)
      (cons 50  0.0)
      (cons 70 0)
      (cons 71 0)
      (cons 72 4)
      (cons 73 2))
      )

  (entmake vl );make the attribute
);defun


(defun createLine (p1 p2)
  (entmakex (list (cons 0 "LINE")
                  (cons 10 p1)
  (cons 11 p2)
  (cons 6 "bylayer")
  (cons 8 "0")
  (cons 39 0.0)
  (cons 62 256)
    ))
  );defun
« Last Edit: August 17, 2011, 11:32:58 AM by marcoblanco120 »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: trouble access attributes created in lisp
« Reply #1 on: August 17, 2011, 10:11:34 AM »
Uhm, first would you please use code tags to surround you code. In the post editor there's a button with a hash (#) which will insert such for you.

Next, you're using entmake to create the INSERT. The ATTRIB needs to follow that, and finally you need to create a SEQEND to stop. It's much simpler just inserting the block using command, or even just through vla.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trouble access attributes created in lisp
« Reply #2 on: August 17, 2011, 11:41:37 AM »
Example of making an INSERT
Code: [Select]
;; *** with attributes ***
(entmake (list (cons 0 "INSERT") ;***
               (cons 8 "0")
               (cons 66 1) ; ***  with attributes  <---<<  This is required
               (cons 2 "CPD") ; ***
               (cons 10 (list 0 0 0)) ; ***
               (cons 41 1)
               (cons 42 1)
               (cons 50 0)
               (cons 43 1)
               (cons 70 0)
               (cons 71 0)
               (cons 44 0)
               (cons 45 0)
               (cons 210 (list 0 0 1))
               (cons 62 256)
               (cons 39 0)
               (cons 6 "BYLAYER")))
                 
(entmake (list (cons 0 "ATTRIB") ;***
              ;;(cons 100 "AcDbEntity")
              ;;(cons 100 "AcDbText")
              ;;(cons 100 "AcDbAttribute")
              (cons 8 "0")
               (cons 10 (list 0 0 0)) ;*** Insert Pt
               (cons 40 1) ;***  Height
               (cons 1 "TESTING 123") ;*** Str
               (cons 2 "TAGNAME") ;*** Tag
               (cons 70 0)
               (cons 73 0)
               (cons 50 0)  ; Rot
               (cons 41 1)
               (cons 51 0)
               (cons 7 "STANDARD") ;***
               (cons 71 0)
               (cons 72 0)  ; Just
               (cons 74 0)  ; Just
               (cons 11 (list 0 0 0)) ;***  Align Pt
               (cons 210 (list 0 0 1))
               (cons 62 256)
               (cons 39 0)
               (cons 6 "BYLAYER")))  ; 256

                 
(entmake (list (cons 0 "SEQEND") ;***
               (cons 8 "0")))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trouble access attributes created in lisp
« Reply #3 on: August 17, 2011, 11:44:12 AM »
You should test for the BLOCK definition first & make it if it does not exist.
Here is an example of making a BLOCK (not the same as the insert given above though)
Code: [Select]
    (entmake  (list '(0 . "BLOCK")            ; required
             '(100 . "AcDbEntity")     ; recommended
             '(100 . "AcDbBlockBegin") ; recommended
              (cons 2 blockname)        ; required
             '(8 . "0")                ; recommended
             '(70 . 2)                 ; required [NOTE 0 if no attributes]
             '(10 0.0 0.0 0.0)         ; required
      ))

    (entmake '((0 . "ATTDEF")  ;***
               (100 . "AcDbEntity")
               (67 . 0)
               (410 . "Model")
               (8 . "0")
               (100 . "AcDbText")
               (10 0 0 0)  ;***
               (40 . 0.1)  ; Text height ;***
               (1 . "")       ; Default value (string)  ;***
               (3 . "ELEV...."); Prompt string  ;***
               (2 . "ELEV")  ; Tag string ;***
               (50 . 0.0)    ; Text rotation
               (41 . 0.7)
               (51 . 0.0)
               (7 . "Standard")  ; Text style ;***
               (71 . 0)   
               (72 . 1)        ; Horizontal text justification
               (11 0 0 0)  ;***
               (100 . "AcDbAttributeDefinition")
               (70 . 0)            ;Attribute flags: CAB -can cause problems with entmake INSERT if they are incorrect
                                   ;1 = Attribute is invisible (does not appear).
                                   ;2 = This is a constant attribute.
                                   ;4 = Verification is required on input of this attribute.
                                   ;8 = Attribute is preset (no prompt during insertion).
               (73 . 0)
               (cons 210 (list 0 0 1))
               (74 . 2)
               (cons 6 "BYLAYER")))
                 

    (entmake (list '(0 . "ENDBLK")         ; required
                   '(100 . "AcDbBlockEnd") ; recommended
                   '(8 . "0")              ; recommended
                   ))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: trouble access attributes created in lisp
« Reply #4 on: August 17, 2011, 11:56:38 AM »
It would be offical if CAB or someone else did this since i do not count but,
 
Welcome to the Swamp!!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: trouble access attributes created in lisp
« Reply #5 on: August 17, 2011, 12:04:45 PM »
As part of the community you count as much as anyone else.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: trouble access attributes created in lisp
« Reply #6 on: August 17, 2011, 02:01:30 PM »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox