Jump to content

vla-get-utility


cadman6735

Recommended Posts

I think I understand this function but...

 

Can someone explain in layman turms a more general how to use this function. (vla-get-utility)

 

 

I have figured out how to use this function with vla-zoomwindow to zoom.

 

I started out just using (getpoint) but did not work, I can only assume to use the (getpoint) function with (vla-zoomwindow) is to first change the getpoint symbol to (vlax-ename->vla-object). {which I did not try} because I found (vla-get-utility) which led me to believe that I have first change the lisp element to a vlisp element.

 

sorry for my long explaination.... Just want to know if I am on the right thought process...

 

Thanks

Link to comment
Share on other sites

CADMan,

 

You may find getpoint a lot easier to use than vla-getpoint, since, with getpoint, if the user fails to pick a point, the function will return nil, whereas the vla-getpoint function will error upon a null pick.

 

I'll show you both ways and let you decide which looks easier:

 

[color=RED]([/color][color=BLUE]defun[/color] c:zw1 [color=RED]([/color] [color=BLUE]/[/color] _CatchApply _acad _util v1 v2 [color=RED])[/color] [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]

 [color=RED]([/color][color=BLUE]defun[/color] _CatchApply [color=RED]([/color] _function _args [color=RED])[/color]
   [color=RED]([/color][color=BLUE]if[/color]
     [color=RED]([/color][color=BLUE]not[/color]
       [color=RED]([/color][color=BLUE]vl-catch-all-error-p[/color]
         [color=RED]([/color][color=BLUE]setq[/color] result
           [color=RED]([/color][color=BLUE]vl-catch-all-apply[/color] _function _args[color=RED])[/color]
         [color=RED])[/color]
       [color=RED])[/color]
     [color=RED])[/color]
     result
   [color=RED])[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]setq[/color] _acad [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED])[/color]
       _util [color=RED]([/color][color=BLUE]vla-get-Utility[/color] [color=RED]([/color][color=BLUE]vla-get-ActiveDocument[/color] _acad[color=RED]))[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]if[/color]
   [color=RED]([/color][color=BLUE]and[/color]
     [color=RED]([/color][color=BLUE]setq[/color] v1 [color=RED]([/color]_CatchApply [color=DARKRED]'[/color][color=BLUE]vla-getPoint[/color] [color=RED]([/color][color=BLUE]list[/color] _util [color=BLUE]nil[/color] [color=#a52a2a]"\nSpecify First Point: "[/color][color=RED])))[/color]
     [color=RED]([/color][color=BLUE]setq[/color] v2 [color=RED]([/color]_CatchApply [color=DARKRED]'[/color][color=BLUE]vla-getPoint[/color] [color=RED]([/color][color=BLUE]list[/color] _util v1  [color=#a52a2a]"\nSpecify Next Point: "[/color][color=RED])))[/color]
   [color=RED])[/color]
   [color=RED]([/color][color=BLUE]vla-ZoomWindow[/color] _acad v1 v2[color=RED])[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
[color=RED])[/color]

[color=RED]([/color][color=BLUE]defun[/color] c:zw2 [color=RED]([/color] [color=BLUE]/[/color] p1 p2 [color=RED])[/color] [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]

 [color=RED]([/color][color=BLUE]if[/color]
   [color=RED]([/color][color=BLUE]and[/color]
     [color=RED]([/color][color=BLUE]setq[/color] p1 [color=RED]([/color][color=BLUE]getpoint[/color] [color=#a52a2a]"\nSpecify First Point: "[/color][color=RED]))[/color]
     [color=RED]([/color][color=BLUE]setq[/color] p2 [color=RED]([/color][color=BLUE]getpoint[/color] [color=#a52a2a]"\nSpecify Next Point: "[/color] p1[color=RED]))[/color]
   [color=RED])[/color]
   [color=RED]([/color][color=BLUE]vla-ZoomWindow[/color] [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]vlax-3D-point[/color] p1[color=RED])[/color] [color=RED]([/color][color=BLUE]vlax-3D-point[/color] p2[color=RED]))[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
[color=RED])[/color]

One final thing: note that the vlax-3D-point function is a 'convenience' to create a 1-dimensional safearray variant of length 3, and is equivalent to:

 

[color=RED]([/color][color=BLUE]defun[/color] _vlax-3D-point [color=RED]([/color] l [color=RED])[/color]
 [color=RED]([/color][color=BLUE]vlax-make-variant[/color]
   [color=RED]([/color][color=BLUE]vlax-safearray-fill[/color]
     [color=RED]([/color][color=BLUE]vlax-make-safearray[/color] [color=BLUE]vlax-vbDouble[/color] [color=DARKRED]'[/color][color=RED]([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#009900]2[/color][color=RED]))[/color]
     l
   [color=RED])[/color]
 [color=RED])[/color]
[color=RED])[/color]

Link to comment
Share on other sites

ahhhh, I see...

 

(vlax-3D-point) I did not add that to my (getpoint) version. This is where vanila lisp gets converted to a visual lisp point?

 

Why do you add the P1 at the end here?

 

(setq p2 (getpoint "\nSpecify Next Point: " p1))

 

 

 

What is the nil for?

 

(setq v1 (_CatchApply 'vla-getPoint (list _util nil "\nSpecify First Point: ")))

 

 

Edit

 

I am wondering how do you zoom in vanilla lisp without using the command zoom? I can't find an example on the web, they all use command zoom.

 

Thanks

Link to comment
Share on other sites

Ok, I told a lie

 

I did use (vlax-3D-point) on my original try but I only used one and wrongly at that too, very wrong...

 

Here is my wrong code that did not work:

 

 
(defun C:test ( / )
 (vl-load-com)
 (setq
   acadObject   (vlax-get-acad-object)
   acadActiveDocument  (vla-get-ActiveDocument acadObject)
 )
;-----------------------------------------------------------------------------------------
   (vla-StartUndoMark acadActiveDocument) ;Start of UNDO
;-----------------------------------------------------------------------------------------
 (setq
   plt1 (getpoint "\nPlace First Plot Point")
   plt2 (getpoint "\nPlace Second Plot Point")
 )
 (vla-zoomwindow acadObject (vlax-3D-point (plt1 plt2)))

 ;(print plt1)
 ;(print plt2)




;-----------------------------------------------------------------------------------------
   (vla-EndUndoMark acadActiveDocument) ;End of UNDO
;-----------------------------------------------------------------------------------------
   (princ)
)

 

 

 

Now my alterd code, using your example lee, and it works... cool stuff

 

 

 
(defun C:test ( / )
 (vl-load-com)
 (setq
   acadObject   (vlax-get-acad-object)
   acadActiveDocument  (vla-get-ActiveDocument acadObject)
 )
;-----------------------------------------------------------------------------------------
   (vla-StartUndoMark acadActiveDocument) ;Start of UNDO
;-----------------------------------------------------------------------------------------
 (setq
   plt1 (getpoint "\nPlace First Plot Point")
   plt2 (getpoint "\nPlace Second Plot Point")
 )
 (vla-zoomwindow acadObject (vlax-3D-point plt1) (vlax-3D-point plt2))

 ;(print plt1)
 ;(print plt2)




;-----------------------------------------------------------------------------------------
   (vla-EndUndoMark acadActiveDocument) ;End of UNDO
;-----------------------------------------------------------------------------------------
   (princ)
)

 

 

 

you add a bunch of other stuff that I don't understand yet but I do enjoy reading your code...

 

Thanks for the help lee

Link to comment
Share on other sites

(vlax-3D-point) I did not add that to my (getpoint) version. This is where vanila lisp gets converted to a visual lisp point?

 

It converts the point to a SafeArray Variant - 'safe' in that you can't overrun the bounds of the array. vlax-3D-point returns the same as the alternative version I posted - have a read about safearrays/variants in the VLIDE Help for more info on this - it'll explain it far better than I could.

 

Why do you add the P1 at the end here?

 

Look up getpoint in the help and you tell me :)

 

What is the nil for?

 

Look at the list of arguments for the vla-getpoint function in the help and see if you can tell me :)

 

I am wondering how do you zoom in vanilla lisp without using the command zoom? I can't find an example on the web, they all use command zoom.

 

Without using VL, just use the command call.

Link to comment
Share on other sites

Look up getpoint in the help and you tell me :)

 

P1 is acting as the pt (getpoint [pt] [msg]) rubber-band line.

 

I remember this from the example AlanJT gave me when I asked about how to draw a line and show the line, but I associated it with the line command not getpoint. (way too much info to digest at one time sometimes. I forget where and for what reason I see things) but at each new level of understanding, I get those "aaahhhhaaaa" moments. This is one of them.

 

 

Look at the list of arguments for the vla-getpoint function in the help and see if you can tell me :)

 

This one has me still stumped. I am looking at getpoint method and I don't see anything with nil in it. I can only assume you are clearing out v1 before selecting the point.

 

Without using VL, just use the command call.

 

 

So how does zoom work then, it has to be programmed somewhere, unless zoom is the function itself?

 

 

Thanks for having me look up the answers (and guiding me to where to look)... I am not looking for easy answers, I am looking to learn programming and as always, on every journey looking for one answer I find 10 more answers to questions I didn't know I had yet.

 

Thanks lee...

Link to comment
Share on other sites

I forget where and for what reason I see things) but at each new level of understanding, I get those "aaahhhhaaaa" moments. This is one of them.

 

But when that moment comes, I find it certainly spurs you on to learn more... :)

 

This one has me still stumped. I am looking at getpoint method and I don't see anything with nil in it. I can only assume you are clearing out v1 before selecting the point.

 

If we look at the reference for the getpoint method, it takes three arguments:

 

(vla-getpoint <Utility> <Basepoint> <Prompt>)

For the first prompt, we don't have a , so this argument is nil. I supply the function and list of arguments to my subfunction which evaluates these arguments using vl-catch-all-apply. This is necessary as the VL getpoint method will error should the user not pick a point - of course, coding it into a subfunction wasn't necessary, but I don't like to repeat code.

 

So how does zoom work then, it has to be programmed somewhere, unless zoom is the function itself?

 

I'm guessing it runs from a .dll / .arx that comes as part of the AutoCAD software. But, unlike the Express Tools, its inner workings are certainly not accessible to view or through LISP.

 

Thanks for having me look up the answers (and guiding me to where to look)... I am not looking for easy answers, I am looking to learn programming and as always, on every journey looking for one answer I find 10 more answers to questions I didn't know I had yet.

 

I'm glad you appreciate the way I approached the help I provided - I'm always wary that members might just think I'm being awkward for the sake of it, but pointing people in the right direction usually means the information sticks better (at least it does for me), otherwise, if people don't have to work for the answer I tend to think that they just read the reply, it sticks for a second, then they move on...

Link to comment
Share on other sites

If we look at the reference for the getpoint method, it takes three arguments:

 

(vla-getpoint <Utility> <Basepoint> <Prompt>)

For the first prompt, we don't have a , so this argument is nil. I supply the function and list of arguments to my subfunction which evaluates these arguments using vl-catch-all-apply. This is necessary as the VL getpoint method will error should the user not pick a point - of course, coding it into a subfunction wasn't necessary, but I don't like to repeat code.

I think cadman6735 is reading that you're referring to the normal lisp getpoint function. The vla-getpoint is actually calling the GetPoint method of the Utility ActiveX object of the current document. You can find the help on that method in the developer help (ActiveX and VBA Reference > Object Model) then click on the Utility object under the Document object. This should show you all the methods available to the utility object, click on the GetPoint to see what arguments are needed.

 

Edit, sorry, forgot ... ADesk was excessively smart in omitting the ActiveX part from their "awesome" on-line help system. Doing a quick google I did come across this: http://www.kxcad.net/autodesk/autocad/AutoCAD_2008_Developer_Help/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...