How read text on command line into lisp?

Discussion in 'AutoCAD' started by Scott Mcfarren, Jun 28, 2004.

  1. Some functions (ie Area) return info to the command line - does anybody
    know how to grab the string (or values) from there ?

    Thanks

    Scott
     
    Scott Mcfarren, Jun 28, 2004
    #1
  2. Scott Mcfarren

    randy benson Guest

    But it's getting easier all the time to roll your own routines...

    ; GA - Get Area property from an entity that has one.
    ; by Randy Benson
    ; June, 2004

    (vl-load-com)
    (defun c:ga ( / en )
    (setq en (vlax-ename->vla-object (car (entsel "\nPick entity: "))))
    (cond
    ( (not (vlax-property-available-p en 'area ))
    (princ "\nEntity does not have an area property. Try again. ")
    )
    ( t
    (princ
    (strcat
    "\nArea="
    (rtos (vlax-get-property en "area") 2 2)
    "sq.ft."
    )
    )
    )
    )
    (princ)
    )
     
    randy benson, Jun 28, 2004
    #2
  3. Scott Mcfarren

    randy benson Guest

    Or better...
    ; GA - Get Area property from an entity that has one.

    ; by Randy Benson
    ; June, 2004

    (vl-load-com)
    (defun c:ga ( / en )
    (setq en (vlax-ename->vla-object (car (entsel "\nPick entity: "))))
    (cond
    ( (not en)
    (princ "\nMissed. Try again. ")
    )
    ( (not (vlax-property-available-p en 'area ))
    (princ "\nEntity does not have an area property. Try again. ")
    )
    ( t
    (princ
    (strcat
    "\nArea="
    (rtos (vlax-get-property en "area") 2 2)
    "sq.ft."
    )
    )
    )
    )
    (princ)
    )
     
    randy benson, Jun 28, 2004
    #3
  4. Randy,

    Using: (setq en (vlax-ename->vla-object (car (entsel "\nPick entity:
    "))))
    as a "one liner" will puke on a missed pick and your (not en)
    condition statement would never be evaluated. You could use something
    like this, but then the user would have to start the function again.
    I would set up a while loop like the second function below.

    (defun c:ga ( / en )
    (setq en (car (entsel "\nPick entity: ")))
    (cond
    ( (not en)
    (princ "\nMissed. Try again. ")
    )
    ( (not (vlax-property-available-p (vlax-ename->vla-object en)
    'area ))
    (princ "\nEntity does not have an area property. Try again. ")
    )
    ( t
    (princ
    (strcat
    "\nArea="
    (rtos (vlax-get-property (vlax-ename->vla-object en)
    "area") 2 2)
    "sq.ft."
    )
    )
    )
    )
    (princ)

    )

    The method I like to use.

    (defun c:ga2 ( / en vla-obj)
    (while
    (not (and
    (setq en (entsel "\nPick entity: "))
    (setq vla-obj (vlax-ename->vla-object (car en)))
    (vlax-property-available-p vla-obj 'area)
    (princ (strcat "\nArea="
    (rtos (vlax-get-property vla-obj "area") 2 2)
    "sq.ft."))))
    (princ "\nMissed pick or Entity does not have an area property.
    Try again. ")
    )
    (princ)
    )

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jun 28, 2004
    #4
  5. Scott Mcfarren

    randy benson Guest

    Yep. Better!
     
    randy benson, Jun 29, 2004
    #5
  6. Scott Mcfarren

    randy benson Guest

    Interesting -- both routines handle most mis-picked entities, but choke
    on a heavy polyline AND mis-report the polyline as an LWPolyline.

    <pick a heavy polyline>:

    Pick entity: *Cancel*
    Automation Error. Invalid class

    Command: (entget (car ep))
    ((-1 . <Entity name: 7ef9e920>) (0 . "POLYLINE") (330 . <Entity name:
    7ef8e008>) (5 . "99BC") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8
    .. "LA20") (100 . "AcDb2dPolyline") (66 . 1) (10 0.0 0.0 0.0) (70 . 0)
    (40 . 0.0) (41 . 0.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73 . 0) (74 .
    0) (75 . 0))

    Command: (setq vo (vlax-ename->vla-object (car ep )))
    #<VLA-OBJECT IAcadLWPolyline 1a1b2e14>


    ; GA - Get Area property from an entity that has one.

    ; by Randy Benson
    ; June, 2004

    (vl-load-com)
    (defun c:ga ( / ep vo)
    (cond
    ( (not (setq ep (entsel "\nPick entity: ")))
    (princ "\nMissed. Try again. ")
    )
    ( (not
    (vlax-property-available-p
    (setq vo (vlax-ename->vla-object (car ep ))) 'area
    )
    )
    (princ "\nEntity does not have an area property. Try again. ")
    )
    ( t
    (princ
    (strcat
    "\nArea="
    (rtos (vlax-get-property vo "area") 2 2)
    "sq.ft."
    )
    )
    )
    )
    (princ)
    )
     
    randy benson, Jun 29, 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.