Block attributes vi lisp

Discussion in 'AutoCAD' started by Walid Khalid, Aug 12, 2004.

  1. Walid Khalid

    Walid Khalid Guest

    Hi,

    You can use this basic lisp routine to create block attributes.
    It is reading from text file (which is normaly created on fly) with
    the listed format:


    ODOUR CONTROL <---- refer to prompt
    0 <---- refer to mode
    ODOUR CONTROL <---- refer to tag
    ODOUR CONTROL <---- refer to value
    Work Type
    0
    Replaced
    Replaced
    Owner
    1
    Watercare
    Watercare
    Type
    0
    OverflowStructure-FilterBed
    Overflow Structure - Filter Bed
    Mix of Materials
    0
    Other
    Other


    the proram will read the file to create the defAttributes which could
    be change to block to become block Attributes.



    ;; ! ***************************************************************************
    ;; ! WriteAttr
    ;; ! ***************************************************************************
    ;; ! Function : Create an attribute in ModelSpace
    ;; ! Argument : 'ename' - entity name of the block
    ;; ! 'tag' - tag name of attribute to write
    ;; ! 'Value' - Value to be set for the attribute
    ;; ! Returns :
    ;; ! Updated : Augest 04, 2004
    ;; ! (C) 1999-2004, Geographic Information System, Rodney District
    Council
    ;; ! Contact :Walid Khalid Al-Tiay
    ;; ! e-mail :
    ;; ! Web : www.rodney.govt.nz
    ;; ! Note : You can include information in text file AttFile.log
    ;; ! ***************************************************************************

    (defun C:WriteAttr (/ va);V1.20
    (vl-load-com)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (setq mspace (vla-get-modelspace doc))

    (defun *error* (st) (prompt (strcat "error: " st "\007\n")))

    (defun FA (/ vb vc ve vf vg vh vi)
    (setq vb (read-line va) vc (getstring "\nStyle name <STANDARD>: "))
    (if (= vc "") (setq vc "STANDARD"))

    (sel)

    (setq ve (vlax-3d-point (setq ve (getpoint "\nInsertion point: "))))
    (setq pt (vlax-safearray->list (vlax-variant-value ve)))
    ;(setq pt (list (car pt1) (cadr pt1)))
    (if (= vf nil) (setq vf (getvar "TEXTSIZE")))

    (if (= vg nil) (setq vg 0.0))
    (setq vh (getvar "AUNITS"))
    (setvar "AUNITS" 4)
    (setq vi (getvar "BLIPMODE"))
    (setvar "BLIPMODE" 0)
    (setvar "CMDECHO" 0)
    (setq pr vb ctr 1)

    (while (/= vb nil)

    (setq vb (read-line va))
    ;(setq pt (polar pt (+ vg (* 1.5 pi)) (* (/ 5.0 3.0) vf )))
    ;(setq ve (vlax-3d-point pt))
    (Cond
    ((= ctr 0)
    (setq pr vb)
    ))
    (Cond
    ((= ctr 1)
    ;(if (= (atoi vb) 1) (setvar "AFLAGS" 0))
    (Cond
    ((= (atoi vb) 1)
    (setvar "AFLAGS" 0)
    (setq pt (polar pt (+ vg (* 1.5 pi)) (* (/ 5.0 3.0) vf )))
    (setq ve (vlax-3d-point pt))
    ))

    (if (= (atoi vb) 0) (setvar "AFLAGS" 3))



    ))
    (Cond
    ((= ctr 2)
    (setq Tag vb)
    ))
    (Cond
    ((= ctr 3)
    (setq val vb ctr -1)
    (setq mode (getvar "AFLAGS"))
    (vla-addattribute mspace vf mode pr ve tag val)
    ))

    (setq ctr (+ ctr 1))

    )
    (setq msg (strcat "Add " handi " as prefix for block name"))
    (print msg)

    (setvar "BLIPMODE" vi)
    (setvar "AUNITS" vh)
    (close va))



    ;(setq va (open (getstring "\nName of ASCII file to insert: ") "r"))
    (setq va (open "C:/AttFile.log" "r"))
    (if (/= va nil) (FA) (prompt "File not found - try again\007\n"))

    )

    (prompt "Program loaded. Call by WriteAttr")(princ)


    (defun sel()
    (Prompt "select element want to attach to:")
    (setq ss (ssget))
    (cond
    ((/= ss nil)
    (setq en(ssname ss 0))
    (setq ed (entget en))
    (setq handi (cdr (assoc 5 ed)))
    ))


    )



    regards

    Walid Khalid Al-Tiay
    Rodney District council
    New Zealand
     
    Walid Khalid, Aug 12, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.