Author Topic: Change Z value of point after using VLA-GetPoint  (Read 8206 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Change Z value of point after using VLA-GetPoint
« on: August 21, 2014, 03:36:06 PM »
I cant seem to find where I can change a variant if I use vla-getpoint.  In VBA, I have a point called InsPT1, and I can change the Z value using InsPT1(2) = WhateverNumber.  How can I do something similiar in Vlisp? 


Actually, let me tell you what I have done, so you can see the nasty version of poor code.
Code: [Select]
(setq INSPT (getpoint "INSERTION POINT: "))
      (setq INSPT (vlax-3d-point  (list (car INSPT) (cadr INSPT) (atof BUSHEIGHT))
  )
      )
      (setq ROT (vla-getangle UTIL INSPT "SELECT ROTATION: "))
The only way I could figure it out was to use getpoint, then pull car and cadr out, and put my Z in and then make a vlax-3d-point
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Change Z value of point after using VLA-GetPoint
« Reply #1 on: August 21, 2014, 03:53:19 PM »
Use (vlax-get (vlax-ename->vla-object (car (entsel))) 'insertionpoint) it will return a point list.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #2 on: August 21, 2014, 04:50:14 PM »
But is there a way to use vla-getpoint and pull out the Z value?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Z value of point after using VLA-GetPoint
« Reply #3 on: August 21, 2014, 05:37:32 PM »
But is there a way to use vla-getpoint and pull out the Z value?

Try something like this David

Code - Auto/Visual Lisp: [Select]
  1.  
  2.       doc     (vla-get-activedocument acadobj)
  3. )
  4.  
  5. (setq ppt     (vla-getpoint (vla-get-utility doc) nil "Enter a point: ")
  6.       mypoint (vlax-variant-value ppt)
  7.       zvalue  (vlax-safearray-get-element mypoint 2)
  8. )
  9.  
  10. (vlax-safearray-put-element mypoint 2 1.66)
  11.  
  12. (setq new-zvalue (vlax-safearray-get-element mypoint 2))
  13.  
  14.  
« Last Edit: August 21, 2014, 05:47:58 PM by Kerry »
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.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #4 on: August 22, 2014, 09:53:14 AM »
Thanks Kerry, That was the missing piece I was looking for.  I kept seeing references to safe arrays, but wasn't sure what to do with it.  I 'm off to try this out.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #5 on: August 22, 2014, 11:01:17 AM »
Perfect Kerry, that was what I needed!  As a test I used addline to text the variables, and it worked perfectly
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Change Z value of point after using VLA-GetPoint
« Reply #6 on: August 22, 2014, 11:04:49 AM »
Most excellent!
In that case, I'll go to bed now.
g'night.
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.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #7 on: August 22, 2014, 03:23:28 PM »
So now I'm stuck trying to make a region.  I used this code
Code - Auto/Visual Lisp: [Select]
  1.         DOC     (vla-get-activedocument ACADOBJ)
  2.         UTIL    (vla-get-utility DOC)
  3.         MSPACE  (vla-get-modelspace DOC)
  4.   )
  5.   (setq WALL_LENGTH
  6.          (vla-getreal
  7.            UTIL
  8.            "Enter Wall Length: "
  9.          )
  10.   )
  11.   (setq WALL_LENGTH_IN (cvunit WALL_LENGTH "ft" "in"))
  12.   (if (/= (rem WALL_LENGTH_IN 8) 0)
  13.     (setq WALL_LENGTH_IN
  14.            (+ WALL_LENGTH_IN (- 8 (rem WALL_LENGTH_IN 8)))
  15.     )
  16.   )
  17.   (setq WALL_WIDTH
  18.          (vla-getreal
  19.            UTIL
  20.            "Enter Wall Width: "
  21.          )
  22.   )
  23.   (setq WALL_WIDTH_IN (cvunit WALL_WIDTH "ft" "in"))
  24.   (if (/= (rem WALL_WIDTH_IN 8) 0)
  25.     (setq WALL_WIDTH_IN (+ WALL_WIDTH_IN (- 8 (rem WALL_WIDTH_IN 8))))
  26.   )
  27.   (setq WALL_HEIGHT
  28.          (vla-getreal
  29.            UTIL
  30.            "Enter Wall Height: "
  31.          )
  32.   )
  33.   (setq WALL_HEIGHT_IN (cvunit WALL_HEIGHT "ft" "in"))
  34.   (if (/= (rem WALL_HEIGHT_IN 8) 0)
  35.     (setq WALL_HEIGHT_IN
  36.            (+ WALL_HEIGHT_IN (- 8 (rem WALL_HEIGHT_IN 8)))
  37.     )
  38.   )
  39.  
  40.  
  41.   (setq INSPT (getpoint "Pick Upper Left Wall Corner: "))
  42.   (setq WALLULO (list (car INSPT) (cadr INSPT))
  43.         WALLULI
  44.                 (list (+ (car INSPT) 8) (- (cadr INSPT) 8))
  45.  
  46.  
  47.         WALLURO
  48.                 (list (+ (car INSPT) WALL_LENGTH_IN) (cadr INSPT))
  49.  
  50.  
  51.         WALLURI
  52.                 (list (- (+ (car INSPT) WALL_LENGTH_IN) 8)
  53.                       (- (cadr INSPT) 8)
  54.  
  55.  
  56.                 )
  57.  
  58.  
  59.         WALLLLO
  60.                 (list (car INSPT) (- (cadr INSPT) WALL_WIDTH_IN))
  61.  
  62.  
  63.         WALLLLI
  64.                 (list (+ (car INSPT) 8)
  65.                       (+ (- (cadr INSPT) WALL_WIDTH_IN) 8)
  66.  
  67.  
  68.                 )
  69.  
  70.  
  71.         WALLLRO
  72.                 (list (+ (car INSPT) WALL_LENGTH_IN)
  73.                       (- (cadr INSPT) WALL_WIDTH_IN)
  74.  
  75.  
  76.                 )
  77.  
  78.  
  79.         WALLLRI
  80.                 (list (- (+ (car INSPT) WALL_LENGTH_IN) 8)
  81.                       (+ (- (cadr INSPT) WALL_WIDTH_IN) 8)
  82.  
  83.  
  84.                 )
  85.  
  86.   )

to make a list of points.  Then trying to figure out how to make a region, I made this list

Code - Auto/Visual Lisp: [Select]
  1. (setq A (list WALLULO WALLURO WALLLRO WALLLLO))

But now I'm stuck with what to do next.  I tried making a safearray with this

Code - Auto/Visual Lisp: [Select]
  1.  (setq sa (vlax-make-safearray vlax-vbdouble '(1 . 2) '(1 .4)))
  2.   (setq sa (vlax-safearray-fill sa (list WALLULO WALLURO WALLLRO WALLLLO)))

which seemed to work, meaning no error was returned, but when I tried to make a region, it fails

Code - Auto/Visual Lisp: [Select]
  1. (setq OW (vla-addregion (list MSPACE sA) ))
« Last Edit: August 22, 2014, 04:25:39 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Change Z value of point after using VLA-GetPoint
« Reply #8 on: August 22, 2014, 04:41:52 PM »
David,

The ActiveX addregion method requires one or more objects from which the region will be created, therefore, you would need to construct a temporary polyline perhaps, and then create the region from the polyline, before deleting the polyline.

Lee

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #9 on: August 22, 2014, 04:44:41 PM »
I tried that too, but to no avail.  I cant seem to get the syntax correct
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Change Z value of point after using VLA-GetPoint
« Reply #10 on: August 22, 2014, 04:50:38 PM »
I tried that too, but to no avail.  I cant seem to get the syntax correct

Give me a minute, I'll post an example for you   :-)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #11 on: August 22, 2014, 04:52:28 PM »
thanks Lee, I am struggling with learning this VLisp syntax.  I read the VBA examples (oh this is so easy in VBA) but cant seem to translate it to VLisp
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Change Z value of point after using VLA-GetPoint
« Reply #12 on: August 22, 2014, 05:10:18 PM »
No worries David :-)

Try the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / *error* roundup8 doc hgt len lli llp lri lrp pl1 pl2 rg1 rg2 spc uli ulp uri urp wid )
  2.  
  3.     (defun *error* ( msg )
  4.         (foreach obj (list pl1 pl2 rg1 rg2)
  5.             (if (and obj (vlax-write-enabled-p obj)) (vla-delete obj))
  6.         )
  7.         (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  8.             (princ (strcat "\nError: " msg))
  9.         )
  10.         (princ)
  11.     )
  12.  
  13.     (defun roundup8 ( n / r )
  14.         (setq r (rem n 8))
  15.         (if (or (equal 0.0 r 1e-8) (equal 8.0 r 1e-8)) (atof (rtos n 2 0)) (+ n (- 8 r)))
  16.     )
  17.           spc (vla-get-modelspace doc)
  18.     )
  19.     (initget 6)
  20.     (if (setq len (getdist "\nEnter wall length: "))
  21.         (progn
  22.             (setq len (roundup8 (* len 12.0)))
  23.             (initget 6)
  24.             (if (setq wid (getdist "\nEnter wall width: "))
  25.                 (progn
  26.                     (setq wid (roundup8 (* wid 12.0)))
  27.                     (initget 6)
  28.                     (if (setq hgt (getdist "\nEnter wall height: "))
  29.                         (progn
  30.                             (setq hgt (roundup8 (* hgt 12.0)))
  31.                             (if (setq ulp (getpoint "\nPick upper-left wall corner: "))
  32.                                 (progn
  33.                                     (setq ulp (list (car ulp) (cadr ulp))
  34.                                           lrp (mapcar '+ ulp  (list len (- wid)))
  35.                                           uli (mapcar '+ ulp '( 8 -8))
  36.                                           lri (mapcar '+ lrp '(-8  8))
  37.                                           urp (list (car lrp) (cadr ulp))
  38.                                           llp (list (car ulp) (cadr lrp))
  39.                                           uri (list (car lri) (cadr uli))
  40.                                           lli (list (car uli) (cadr lri))
  41.                                           pl1 (vlax-invoke spc 'addlightweightpolyline (append ulp urp lrp llp))
  42.                                           pl2 (vlax-invoke spc 'addlightweightpolyline (append uli uri lri lli))
  43.                                     )
  44.                                     (vla-put-closed pl1 :vlax-true)
  45.                                     (vla-put-closed pl2 :vlax-true)
  46.                                     (setq rg1 (car (vlax-invoke spc 'addregion (list pl1)))
  47.                                           rg2 (car (vlax-invoke spc 'addregion (list pl2)))
  48.                                     )
  49.                                     (vla-delete pl1)
  50.                                     (vla-delete pl2)
  51.                                     (vla-boolean rg1 acsubtraction rg2)
  52.                                     (vlax-invoke spc 'addextrudedsolid rg1 hgt 0.0)
  53.                                     (vla-delete rg1)
  54.                                 )
  55.                             )
  56.                         )
  57.                     )
  58.                 )
  59.             )
  60.         )
  61.     )
  62.     (princ)
  63. )

Feel free to ask if you have any questions about the code  :-)

EDIT: Changed the point calculations.
« Last Edit: August 22, 2014, 06:17:15 PM by Lee Mac »

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Change Z value of point after using VLA-GetPoint
« Reply #13 on: August 22, 2014, 05:23:10 PM »
much appreciated!!!  But why/How this -  pl1 (vlax-invoke spc 'addlightweightpolyline (append ins uro lro llo))
instead of vla-addlightweightpolyline?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Change Z value of point after using VLA-GetPoint
« Reply #14 on: August 22, 2014, 05:28:36 PM »
much appreciated!!!  But why/How this -  pl1 (vlax-invoke spc 'addlightweightpolyline (append ins uro lro llo))
instead of vla-addlightweightpolyline?

You're welcome  :-)

I use the undocumented vlax-invoke function (there is also vlax-get/vlax-put for properties, though, vlax-put can be temperamental) to avoid the use of variants & safearrays - these functions accept arguments in native AutoLISP data types, such as lists.

I'll post another example using variants/safearrays for comparison.

Lee