Need Help with Attribute Routine

Discussion in 'AutoCAD' started by WashCaps37, Nov 24, 2004.

  1. WashCaps37

    WashCaps37 Guest

    Hello,

    I am a LISP newbie and I am seeking help because I am having difficulty trying to write a routine that will obtain the values of Attributes and add them together and then replace one of them with the new value. For example, I have blocks with 10 total attributes, I want to get the value of Attribute #7 and Attribute #8 and add them together and replace Attribute #8 with the sum. The Attribute values are real numbers. Here is what I have so far.

    Thanks for your help!

    ;Populate Ending U

    (defun c:endingu ()

    ;select equipment that needs ending U populated
    (initget)
    (setq equipment (entsel "Select Equipment to Populate Ending U:")))

    ;Obtain Starting U
    (setq equipunumrreal (entget (entnext (entnext (entnext (entnext (entnext (entnext (entnext enameequip)))))))))
    (setq equipunum (cdr (assoc 1 entlistequipunum)))

    ;obtain number to determine ending u
    (setq equipenumreal (entget (entnext (entnext (entnext (entnext (entnext (entnext (entget (entnext enameequip))))))))))
    (setq equipenum (cdr (assoc 1 entlistequipenum)))

    ;Calculate ending u and populate ending u attribute
    (setq entlistequipendnum (+ (equipunum equipenum)))
    (setq entlistequipendnum (entget (entnext (entnext (entnext (entnext (entnext (entnext (entget (entnext enameequip))))))))))
    (setq equipendnum (cdr (assoc 1 entlistequipendnum)))
    (entmod (subst (cons 1 equipenum) (assoc 1 entlistequipendnum) entlistequipendnum))
    (princ)
     
    WashCaps37, Nov 24, 2004
    #1
  2. WashCaps37

    Dann Guest

    Try this one.

    (defun objsel ($prompt / ent)
    (vl-load-com)
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (setq obj (vlax-ename->vla-object ent))
    (setq obj nil)
    )
    )

    (defun C:endingu ()
    (setq $prompt "Select Equipment to Populate Ending U:")
    (objsel $prompt)
    (setq atts (vlax-safearray->list
    (vlax-variant-value (vla-getattributes obj))
    )
    )
    (setq att7val(vla-get-textstring (nth 6 atts)))
    (setq att8val(vla-get-textstring (nth 7 atts)))
    (setq endval(+ (atof att7val)(atof att8val)))
    (vla-put-textstring (nth 7 atts) endval)
    (princ)
    )
     
    Dann, Nov 24, 2004
    #2
  3. WashCaps37

    WashCaps37 Guest

    Dann,

    Thank you very much for your help. I have a real appreciation for all help since learning LISP has been a real challenge for me.

    One question regarding your routine. If the values for Attribute 7 and Attribute 8 are real numbers (i.e. 15.0), how would your routine be modified to return a real number in Attribute 8?

    Thanks again!!!!!
     
    WashCaps37, Nov 24, 2004
    #3
  4. WashCaps37

    Dann Guest

    In the vla-put-textstring line change endval to (rtos endval 2 2)
    see rtos in the help files.
     
    Dann, Nov 24, 2004
    #4
  5. WashCaps37

    WashCaps37 Guest

    Dann, Thank You, Thank You, Thank You!!!!!!! the routine works perfectly, just the way I need it to work. I'll definitely read up on the rtos in the help files.
     
    WashCaps37, Nov 24, 2004
    #5
  6. WashCaps37

    Dann Guest

    Or you can (setvar "Dimzin" 1)
    Then (rtos endval) returns the string formated using the Luprec setting.
    "Dann" <NoneSpecified> wrote in message In the vla-put-textstring line change endval to (rtos endval 2 2)
    see rtos in the help files.
     
    Dann, Nov 24, 2004
    #6
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.