Author Topic: Visual Lisp Getinput Help  (Read 7242 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
Visual Lisp Getinput Help
« on: October 29, 2005, 05:26:26 AM »
Hi all;

I am learning to use the utility objects and am trying to write a task using the initializeuserinput and the getinput function but run into an error-automation error user input is a keyword. I need the user to either select a point or key in one of those keywords.
Any assitance is much appreciated. Thank you.
My code
Code: [Select]
(defun c:test1(/ acadObj ActivedocumentObj utilityObj ssobj pt1 pt2)
  (vl-load-com)
  (setq acadObj           (vlax-get-acad-object)
        ;; acad Object
        ActivedocumentObj (vla-get-Activedocument acadObj)
        ;; the current dwg
        UtilityObj (vla-get-Utility ActivedocumentObj)
        ;; the utility
  )
 (setq keywordlist "Layer STyle")
 (setq KeyWord?(vla-InitializeUserInput utilityObj 128 keywordlist))
 (setq pt1 (vla-getpoint utilityObj nil "LAyer / STyle / <enter base point> "))
 (if (= pt1 NIL)
  (progn
   (setq user? (vla-getinput utilityObj))
   (print "USER")(princ user?)
  )
  (and (print "POINT")(print pt1)(print "OK"))
 )
; (setq pt2 (vla-getinput pt1))
; (print "pt2 ")(princ pt2)
);test1

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Visual Lisp Getinput Help
« Reply #1 on: October 29, 2005, 07:37:35 AM »
Hi csgoh. I'm trying to figure what is the value in going this route (as opposed to using the vanilla getpoint function), and I just come up empty. Is it because you want a variant when you're done? If so, why not just wrap the vanilla getpoint function in a vlax-3D-point call?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

csgoh

  • Newt
  • Posts: 176
Re: Visual Lisp Getinput Help
« Reply #2 on: October 29, 2005, 08:27:17 AM »
Hi MP;
I rewrote my code. The idea is to let the user either select a point or LA or ST as the keyword.
And when I type LA or ST when prompted, an error message Automation error. User input is a keyword. I believe that I am missing a code somewhere after the prompt but I just could not figure it out. Like I said earlier, I am learning to write using utility objects using Vuisual Lisp, so please do not ask me to use vanilla lisp. Thanks in advance.

Code: [Select]
(defun c:test1(/ acadObj ActivedocumentObj utilityObj temp pt1 keywordlist
                 keyword?
              )
  (vl-load-com)
  (setq acadObj           (vlax-get-acad-object)
        ;; acad Object
        ActivedocumentObj (vla-get-Activedocument acadObj)
        ;; the current dwg
        UtilityObj (vla-get-Utility ActivedocumentObj)
        ;; the utility
        temp T
  )
(while temp
 (setq keywordlist "LAyer STyle")
 (setq KeyWord?(vla-InitializeUserInput utilityObj 128 keywordlist))
 (setq pt1 (vla-getpoint utilityObj nil "LAyer / STyle / <enter base point> "))
 (cond
   ((= pt1 "LAyer")
    (setq newlayer (getint "\nEnter layer number"))
   )
   ((= pt1 "STyle")
    (setq newstyle (getint "\nEnter style number"))
   )
   (T
    (setq temp nil)
   ) 
 )
);while

);test1


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Visual Lisp Getinput Help
« Reply #3 on: October 29, 2005, 08:39:21 AM »
Not being snotty, but (repeating myself) I see no value in using vla-utility functions to achieve this. If you want a vanilla solution let me know. Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

csgoh

  • Newt
  • Posts: 176
Re: Visual Lisp Getinput Help
« Reply #4 on: October 29, 2005, 09:13:06 AM »
Quote
Not being snotty, but (repeating myself) I see no value in using vla-utility functions to achieve this
If that's being the case, I might as well learn vanilla lisp too and discard the visual lisp. In comparison, which is better, vanilla lisp or visual lisp? So, what you are trying to say is that, some routines are better off written in vanilla lisp rather than visual lisp. But to a beginner, how can we accomplish that? Unless with guidance from the gurus out there, and comparing a same routine written in both types of lisp can enlighten us very much.

Amsterdammed

  • Guest
Re: Visual Lisp Getinput Help
« Reply #5 on: October 29, 2005, 09:19:51 AM »
Code: [Select]
(initget   "Layer Style")
;userinput
(setq pt (getpoint "\nenter basepoint or <Layer, Style>:"))

(cond (( = (type pt 'list))
       ;your funtion for  point input
       )
      (( = pt "Layer")
       ;your funtion for  Layer input
       )
      (( = pt "Style")
       ;your funtion for  Layer input
       )
      (( null pt )
       ;your funtion for  nil input
       )
)




That is what will do what you wantend (in my opinion).

Bernd

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Visual Lisp Getinput Help
« Reply #6 on: October 29, 2005, 09:24:19 AM »
It's more of a case of what's the right tool for the job. Visual LISP, or active functions serve a specialized and vital role -- I use them by the truck load, but to use them just for the sake of using it? I'll pass. In the context you provided there is no benefit (to me) to use the utility object. I understand if you want to learn it, but in production it serves no additional leverage or advantage that I can see, though I welcome enlightenment.

Anyway, here's a vanilla skeleton to start you off --

Code: [Select]
(defun c:Test ( / message response )

    (setq message "Layer/Style/<enter base point>: ")

    (initget 128 "Layer Style")
   
    (cond
        (   (null
                (setq response
                    (getpoint message)                   
                )
            )
            ;;  is null logic
        )
        (   (eq "Layer" response)
            ;;  is layer logic
        )
        (   (eq "Style" response)
            ;;  is style logic
        )
        (   (and
                (listp response)
                (eq 3 (length response))
                (vl-every 'numberp response)               
            )
            ;;  is point logic
        )
       
        (   t
            ;;  da'hell? logic
        )
   
    )
   
    (princ)

)

Hope it helps.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Visual Lisp Getinput Help
« Reply #7 on: October 29, 2005, 09:35:06 AM »
Anyway, here's a vanilla skeleton ...

That right there is purdy, I don't care who ya are.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Visual Lisp Getinput Help
« Reply #8 on: October 29, 2005, 09:36:20 AM »
Did ya notice the "branch ala Se7en"?

:-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Visual Lisp Getinput Help
« Reply #9 on: October 29, 2005, 09:52:07 AM »
Did ya notice the "branch ala Se7en"?

Roger that....   :-D
TheSwamp.org  (serving the CAD community since 2003)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Lisp Getinput Help
« Reply #10 on: October 29, 2005, 02:11:51 PM »
        (   (and
                (listp response)
                (eq 3 (length response))
                (vl-every 'numberp response)               
            )
            ;;  is point logic
        )



hehehe .. I feel better about my belt and braces philosophy now :)

csgoh,
Personal opinion/observation : Some things in the ActiveX interface for VLisp leave a bit to be desired regarding implementation.
Dont forgo access to the object Model and some really neat functionality because of that though. Continue what you are doing .. learn the language as a whole, and work around those portions that are less than perfect.
[/soapbox]

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Lisp Getinput Help
« Reply #11 on: October 29, 2005, 02:24:07 PM »
unsolicited homily as an afterthought.

I often see the comment " I'll have to learn the VLA-stuff one day .. "
You shouldn't learn it 'one day', just do it 'every day'.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

csgoh

  • Newt
  • Posts: 176
Re: Visual Lisp Getinput Help
« Reply #12 on: October 29, 2005, 08:41:58 PM »
Thanks, guys.
I will keep your advice and explanation in mind as my learning process continues. Anyway, you guys are great. I am glad to be here.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Visual Lisp Getinput Help
« Reply #13 on: November 01, 2005, 12:18:39 PM »
csgoh,
Since you said you wanted to learn, I took the liberty of modifying Michael's code to use the ActiveX counterparts. Note how complex it gets to accomplish the same thing, which is why MP asked "Why?"
Code: [Select]
(defun c:Test ( / message response )

    (setq message "Layer/Style/<enter base point>: "
  util (vla-get-utility
(vla-get-activedocument
   (vlax-get-acad-object)
   )
)
  )

    ;(initget 128 "Layer Style")
  ;ActiveX counterpart
  (vla-initializeuserinput util 128 "Layer Style")
   
    (cond
        (   (null
                (progn
  (setq err?
                    (vl-catch-all-apply '(lambda ()
   (setq response
  (vlax-invoke util 'getpoint nil message)
)
   )
      )
)
  (if (and (vl-catch-all-error-p err?)
   (eq (vl-catch-all-error-message err?) "AutoCAD: User input is a keyword")
   )
    (if (eq (setq response
   (vla-getinput util)
  )
    "")
      (setq repsonse nil)
      )
    response
    )
  )
                )
            ;;  is null logic
        )
        (   (eq "Layer" response)
            ;;  is layer logic
        )
        (   (eq "Style" response)
            ;;  is style logic
        )
        (   (and
                (listp response)
                (eq 3 (length response))
                (vl-every 'numberp response)               
            )
            ;;  is point logic
        )
       
        (   t
            ;;  da'hell? logic
        )
   
    )
   
    (princ)

)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Visual Lisp Getinput Help
« Reply #14 on: November 01, 2005, 06:56:35 PM »
Good to see you haven't lost your touch during your holiday Jeff  :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Visual Lisp Getinput Help
« Reply #15 on: November 01, 2005, 07:00:07 PM »
Excellent job noting the differences (and underscoring my point).

Many thanks Jeff.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

csgoh

  • Newt
  • Posts: 176
Re: Visual Lisp Getinput Help
« Reply #16 on: November 02, 2005, 08:40:39 AM »
Thanks, Jeff.
I guess I still have a long way to learn and with support from you guys, its going to be interesting.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Visual Lisp Getinput Help
« Reply #17 on: November 02, 2005, 09:29:16 AM »
csgoh, glad I could help.
Just keep asking questions and we'll all do our best to steer you along. And you're right, it IS interesting (and even fun at times most of the time).

MP, you're welcome. It just seemed logical to use your excellent example for the comparison.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Visual Lisp Getinput Help
« Reply #18 on: November 02, 2005, 10:08:04 AM »
If all posts were as gracious as yours Jeff mods would have nothing to do but twiddle their thumbs and talk knitting patterns.

Not that there's anything wrong with that.

 :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst