Author Topic: last drawn point coordinates?  (Read 1242 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
last drawn point coordinates?
« on: October 03, 2020, 10:21:24 AM »
Hi there,

Is there anyway to automatically get hold of the x y and z coordinates of the last drawn point?

As I then wish to feed these coordinates into a lisp to insert a level block at the correct position with an attribute filled with the z coordinate value.

Why?  Because the pointcloud add-on software I use has implememnted a point cloud node snap that works in 3D wireframe mode, but it is tied to only a few functions.

Namely:
LINE [ L ]; PLINE [ PL ]; INSERT [ I ]; POINT [ PO ];  3DPOLY [ 3P ];  MTEXT [ MT ]; TEXT [ T ];  CIRCLE [ C ]; ARC [ ARC ]; MOVE [ M ];  COPY [ CO ];  “Move&Add Vertex”; EXTRUDE [ EXT ]; [PRESPULL ];  [ DIMLINEAR ];  [ DIMALIGNED ];  [ DIM ]; DIST [ DI ].


I have a lisp that does the rest, I just need to be able to grab the coordinates of the last point drawn into a variable using the point command.
Once the lisp is complete I then aim to delete the original temporary point.


The original lisp just uses getpoint      (setq pt1 (getpoint "\nPick point:"))
but the pointcloud snap will not function with this.

The full lisp is below

Many thanks
Pads

Code - Auto/Visual Lisp: [Select]
  1. (defun C:inspl2 ( / *error* osm )
  2.  
  3. ;;;;;;;; Error Handler
  4.  
  5.     (defun *error* ( msg )
  6.         (if osm (setvar 'osmode osm))
  7.         (if (not (member msg '("Function cancelled" "quit / exit abort")))
  8.             (princ (strcat "\nError: " msg))
  9.         )
  10.         (princ)
  11.     )
  12.  
  13.     (setq osm (getvar 'osmode))
  14. ;;;;;;;;
  15.  
  16.  
  17.   (if (= 2d3d nil)
  18.     (progn
  19.       (setq 2d3d
  20.              (getstring "\n 2d or 3d  2/3")
  21.       )
  22.     )
  23.   )
  24.   (if (= decpla nil)
  25.     (progn
  26.       (setq decplac
  27.              (getstring "\n How many decimal places will you require?")
  28.       )
  29.       (setq decpla (atoi decplac))
  30.  
  31.     )
  32.   )
  33.   (if (= scal nil)
  34.     (progn
  35.       (setq scal (getreal "\nEnter drawing scale:"))
  36.       ;;get drawing scale
  37.     )
  38.   )
  39.  
  40.  
  41.  
  42. (command "regen")
  43.   (while (setvar "osmode" 8)
  44.          (setq pt1 (getpoint "\nPick point:"))
  45.  
  46. ;; pb trans
  47. (setq ptz (trans pt1 1 0))
  48.  
  49.          (setq blk "PL")
  50.  
  51. ;; pb trans
  52.          (setq lev (caddr ptz))
  53.  
  54.          (setq insx (car pt1))
  55.          (setq insy (cadr pt1))
  56.  
  57.     (if (= 2d3d "2")
  58.       (progn
  59.         (setq ins (list insx insy 0.0))
  60.  
  61.       )
  62.     )
  63.     (if (= 2d3d "3")
  64.       (progn
  65.         (setq ins pt1)
  66.       )
  67.     )
  68.     (setq val (rtos lev 2 decpla))
  69.     (setq ht (/ scal 571.428557))
  70.     (setq old_lay (getvar "clayer"))
  71.     (setvar "clayer" "levels")
  72.  ;   (setvar "osmode" 16384)
  73.     (command "insert" blk ins ht ht "" val "" "")
  74.     (setvar "clayer" old_lay)
  75.     ;;insert new PL block
  76.     (setvar "osmode" 8)
  77.     (command "regen")
  78.   )
  79.  
  80.     (setvar 'osmode osm)
  81.     (princ)
  82. )

ribarm

  • Gator
  • Posts: 3287
  • Marko Ribar, architect
Re: last drawn point coordinates?
« Reply #1 on: October 03, 2020, 11:43:22 AM »
Just my opinion :
Try to store points you acquire with (getpoint) into point list : something like (setq *ptlst* (cons pt *ptlst*)) - *ptlst* is global variable... Then when you finish and need last point - you can get it with (car *ptlst*) - I'd suggest that you do it through separate routine just called after your primary one, or implement additional operations as last procedure inside your master routine... In both cases strong advice is to nil global *ptlst* upon finish of insertion of your point cloud - IMHO good idea is to somehow avoid creating global variables and do everything in single routine - of course all variables used should be localized within main (defun)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1420
  • 40 + years of using Autocad
Re: last drawn point coordinates?
« Reply #2 on: October 03, 2020, 08:09:25 PM »
As you say car is 1st as cons adds to start, depending on list if actually want last point can use (last *ptlst*)
A man who never made a mistake never made anything

Pad

  • Bull Frog
  • Posts: 342
Re: last drawn point coordinates?
« Reply #3 on: October 04, 2020, 05:56:47 AM »
Thank you for your replies.
Yes I do need to spend a bit of time localising variables on the lisp, thanks for the tips.

I do not need to capture the coords using 'getpoint', I'm hoping to find a way of getting over a point cloud snapping limitation with lisp.

I can snap to the point cloud using the native autocad 'point' command, is there a way then to get hold of the coordinates of this point to feed into the lisp?
Currently I have to draw the point using the point command, then run 'inspl.lsp' and then pick the previously drawn point.  I would love to be able to streamline this so that only one pick is required for the same outcome.

Here is a screencast that illustrates the issue, having to pick twice, I would like to have the same outcome but only pick once.

https://autode.sk/34n9nRt

And the drawing file is attached.

Thank you
P
« Last Edit: October 04, 2020, 06:08:34 AM by Pad »

ribarm

  • Gator
  • Posts: 3287
  • Marko Ribar, architect
Re: last drawn point coordinates?
« Reply #4 on: October 04, 2020, 06:16:06 AM »
Have you tried 'LASTPOINT system variable - (getvar 'lastpoint) after you draw point with command POINT and then (entdel (entlast))...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Pad

  • Bull Frog
  • Posts: 342
Re: last drawn point coordinates?
« Reply #5 on: October 04, 2020, 06:58:56 AM »
Ah yes!  That is it.  I hoped it would be something simple.  Thank you very much for that!
Cheers
P

Pad

  • Bull Frog
  • Posts: 342
Re: last drawn point coordinates?
« Reply #6 on: October 04, 2020, 07:27:00 AM »
All done I think.

I need to keep variables 2d3d, decpla and scal set so that they do not need re-inputing the next time the lisp is run within the current drawing.

Any comments would be appreciated.  Many thanks P

Code - Auto/Visual Lisp: [Select]
  1. (defun C:inspl4 ( / pt1 blk lev insx insy ins val ht old_lay clayer)
  2.  
  3.   (if (= 2d3d nil)
  4.     (progn
  5.       (setq 2d3d
  6.              (getstring "\n 2d or 3d  2/3")
  7.       )
  8.     )
  9.   )
  10.   (if (= decpla nil)
  11.     (progn
  12.       (setq decplac
  13.              (getstring "\n How many decimal places will you require?")
  14.       )
  15.       (setq decpla (atoi decplac))
  16.  
  17.     )
  18.   )
  19.   (if (= scal nil)
  20.     (progn
  21.       (setq scal (getreal "\nEnter drawing scale:"))
  22.       ;;get drawing scale
  23.     )
  24.   )
  25.  
  26. (prompt "\nPick point:")
  27. (command "point" pause)
  28. (setq pt1 (getvar 'lastpoint))
  29. )
  30.  
  31. ;; pb trans
  32. (setq ptz (trans pt1 1 0))
  33.  
  34.          (setq lev (caddr ptz))
  35.  
  36.          (setq insx (car pt1))
  37.          (setq insy (cadr pt1))
  38.  
  39. (setq blk "PL")
  40.  
  41.     (if (= 2d3d "2")
  42.       (progn
  43.         (setq ins (list insx insy 0.0))
  44.       )
  45.     )
  46.     (if (= 2d3d "3")
  47.       (progn
  48.         (setq ins pt1)
  49.       )
  50.     )
  51.     (setq val (rtos lev 2 decpla))
  52.     (setq ht (/ scal 571.428557))
  53.     (setq old_lay (getvar "clayer"))
  54.     (setvar "clayer" "levels")
  55.     (command "insert" blk ins ht ht "" val "" "")
  56.     (setvar "clayer" old_lay)
  57.     ;;insert new PL block
  58.     (command "regen")
  59.   )
  60.     (princ)