Edit Lisp routine to snap to pointcloud nodes?

Edit Lisp routine to snap to pointcloud nodes?

dlbsurveysuk
Collaborator Collaborator
1,544 Views
6 Replies
Message 1 of 7

Edit Lisp routine to snap to pointcloud nodes?

dlbsurveysuk
Collaborator
Collaborator

Hi, I've got a lot of Lisp routines that I use mainly for annotation work on Autocad survey drawings. They're all 10+ years old and a lot of them weren't working on the latest Autocad. I've managed to diagnose the problem which involved removing all the QUICK commands. All the routines seem to be working fine now.

 

A lot of the routines involve snapping to nodes and extracting the z values for levelling annotation (spot levels, cill and head heights, beam levels etc.). The additional problem I now have is that I've started working with pointcloud data and none of the routines seem to want to snap to pointcloud nodes. These routines were all written by a previous work colleague and my programming skills are very rudimentary so I'm a bit lost as to how to proceed. I'm not entirely certain if it's even a Lisp problem, or some other setting I've got wrong in Autocad, or just a fundamental misunderstanding on my part.

 

here's an example - the command LP allows me to pick a node, then a cross and level text from the z value of the node is automatically inserted. If I try to pick the node of a pointcloud it doesn't work. It only seems to recognise cad points, not pointcloud points. Anyone got any ideas? Thanks in advance.

 

 

(defun C:LP (/ pt tat Y olderr)
   (setq olderr  *error*             ; Initialize variables
         *error* cterr
   )
(setvar "cmdecho" 0)
(SETQ OSM (GETVAR"OSMODE"))
(SETQ lll (GETVAR"CLAYER"))
(setq a(getvar "textsize"))
(COMMAND "OSNAP" "NODE")
(setq pt(getpoint "Whereabouts...?"))
(COMMAND "OSNAP" "NONE")
(SETQ X (CAR PT))
(setq Y (cadr pt))
 (SETQ Z (RTOS (CADDR PT) 2 2))
(setq XYPT(LIST (CAR PT)(CADR PT)))
(setq Tat (LIST X (- Y (* 2 a))))
(command "layer" "M" "LX" "")
   (COMMAND "INSERT" "CROSS" XYpt a "" 0.0)
(command "layer" "M" "LTEXT" "")
   (COMMAND "TEXT" tat "" 0.0 Z)
 (SETVAR "OSMODE" OSM)
 (COMMAND "LAYER" "S" lll "")
   (setq *error* olderr)             ; Restore old *error* handler
   (princ)
)

 

 

0 Likes
Accepted solutions (1)
1,545 Views
6 Replies
Replies (6)
Message 2 of 7

CodeDing
Advisor
Advisor

@dlbsurveysuk ,

 

To snap to points in point clouds, you must use 3D object snap. Not the normal OSMODE.

The vaiable is 3DOSMODE.

 

Best,

~DD

0 Likes
Message 3 of 7

dlbsurveysuk
Collaborator
Collaborator

Thanks for the reply.

 

I changed the line (SETQ OSM (GETVAR"OSMODE")) to (SETQ OSM (GETVAR"3DOSMODE")) but nothing has changed. It still works with cad nodes but still not with pointcloud nodes.

 

(please bear in mind that I don't really know what I'm doing with Lisp)

 

Thanks

0 Likes
Message 4 of 7

CodeDing
Advisor
Advisor

@dlbsurveysuk ,

 

No worries. Implement something like this:

;.....
(setq osm3D (getvar '3DOSMODE))
(setvar '3DOSMODE 128)
;... have user select point cloud node ...
(setvar '3DOSMODE osm3D)
;.....

 

Best,

~DD

0 Likes
Message 5 of 7

dlbsurveysuk
Collaborator
Collaborator

Thanks again, but when I said I don't know really know what I'm doing, that was a bit of an understatement. I don't know where in the above routine I would implement the code you provided, or even what all the code means exactly. I don't want all the work doing for me but I was hoping to get the above routine working, gain a very rough understanding of the changes, and then be able to edit all the other routines I have myself.

 

Thanks.

0 Likes
Message 6 of 7

CodeDing
Advisor
Advisor
Accepted solution

@dlbsurveysuk ,

 

Lol, ok yeah no issues with trying to learn. I haven't tested this but it should work for you.

Just let me know.

 

(defun C:LP (/ lyr txtSize osm3D pt ptXY ptXY2 zStr)
  ;;initial prep
  (setvar 'CMDECHO 0)
  (setq lyr (getvar 'CLAYER))
  (setq txtSize (getvar "textsize"))
  ;;user select point
  (setq osm3D (getvar '3DOSMODE))
  (setvar '3DOSMODE 128)
  (initget 1) (setq pt (getpoint "\nSelect Point in Point Cloud: "))
  (setvar '3DOSMODE osm3D)
  ;;prep for work
  (setq ptXY (list (car pt) (cadr pt)))
  (setq ptXY2 (list (car pt) (- (cadr pt) (* 2 txtSize))))
  (setq zStr (rtos (caddr pt) 2 2))
  ;;block/text creation
  (command "-LAYER" "M" "LX" "")
  (command "-INSERT" "CROSS" "non" ptXY txtSize "" 0.0)
  (command "-LAYER" "M" "LTEXT" "")
  (command "TEXT" "non" ptXY2 "" 0.0 zStr)
  ;;finish up
  (setvar 'CLAYER lyr)
  (setvar 'CMDECHO 1)
  (princ)
);defun

 

Best,

~DD

0 Likes
Message 7 of 7

dlbsurveysuk
Collaborator
Collaborator

Fantastic. That works perfectly. Thanks very much for your time and effort. I'll try and make sense of the code now and edit the other routines.

 

Thanks again, much appreciated.

0 Likes