"Uncrop last" for pointcloud in LISP

"Uncrop last" for pointcloud in LISP

denys_gorkovchuk
Contributor Contributor
1,712 Views
8 Replies
Message 1 of 9

"Uncrop last" for pointcloud in LISP

denys_gorkovchuk
Contributor
Contributor

Hi All,

 

I am writing a LISP, which make some processing with the pointcloud and I need to use "Uncrop last" command.

The problem is that normal command

(command "_POINTCLOUDCROP" cloud "R")

gives an error.

I have checked the macros of "Uncrop last" button in ACAD customization file and it has following:

^C^C_pointcloudcrop;$M=$(if,$(eq,$(getvar,cmdactive),1),_remove;)^Z

Can somebody explain how it works and how to make it work within LISP?

Thanks!

0 Likes
Accepted solutions (1)
1,713 Views
8 Replies
Replies (8)
Message 2 of 9

devitg
Advisor
Advisor
(if,$(eq,$(getvar,cmdactive),1)

Ask for the cmdactive = 1 

 So, and maybe, you have to check for it  , and set to 1 if it is 0 

 

(setq cmdactive (getvar 'cmdactive))
(setvar 'cmdactive 1)

(command "_POINTCLOUDCROP" cloud "R")

(setvar 'cmdactive cmdactive)

As I have any clue about cloud points or so , it is all I can guess . 

If you could upload a sample.dwg , I will try to check . After I pay a visit to the customize , command shall be 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 3 of 9

denys_gorkovchuk
Contributor
Contributor

Thanks for your suggestion, but it doesn't work. It gives following erorr:

; error: AutoCAD variable setting rejected: CMDACTIVE 1

Here is the bigger part of the code:

 (setq cloud (car (entsel)))
(setq Vlaobject-Cloud (vlax-ename->vla-object cloud)) ;convert cloud selection to vla-object (setq cloudlockstate (vlax-get-property Vlaobject-Cloud 'Locked)) ;read "Locked" property value (vlax-put-property Vlaobject-Cloud 'Locked 0) ;set "Locked" value to FALSE (command "_POINTCLOUDCROP" cloud "R") (vlax-put-property Vlaobject-Cloud 'Locked cloudlockstate) ;set "Locked" value to previous

As you see, the idea of lisp is working with locked point clouds. I have just noticed following thing:

LISP works if I start it with empty selection. So nothing is selected, I run LISP. It asks to select pointcloud and makes correct cropping.

If my pointcloud is already selected then it gives error at (command "_POINTCLOUDCROP" cloud "R") stage.

I have attached DWG with the test pointcloud.

 

0 Likes
Message 4 of 9

CodeDing
Advisor
Advisor

@denys_gorkovchuk ,

 

Here, I believe this is the direction you are hoping to go? Let me know if this helps.

(defun c:UNCROPLAST ( / cloud wasLocked)
;initial cloud retrieval
(setq cloud nil
      cloud (while (not cloud)
	      (initget 1)
	      (if (not (eq "ACDBPOINTCLOUDEX" (cdr (assoc 0 (entget (setq cloud (car (entsel "\nSelect Point Cloud: "))))))))
		(progn (prompt "...invalid.") (setq cloud nil))
		cloud)))
;check if cropped
(if (> (getpropertyvalue cloud "CroppingCount") 0)
  (progn
    ;unlock if locked
    (if (= 1 (getpropertyvalue cloud "Locked"))
      (progn
	(vlax-put-property (vlax-ename->vla-object cloud) 'Locked 0)
	(setq wasLocked t)
      );progn
    );if
    ;remove last crop
    (setvar 'CMDECHO 0)
    (command "_POINTCLOUDCROP" cloud "r")
    (setvar 'CMDECHO 1)
    ;restore lock
    (if wasLocked (vlax-put-property (vlax-ename->vla-object cloud) 'Locked 1))
    (prompt "\nUncropping successful...")
  );progn
;else
  (prompt "\n...no cropping found for point cloud.")
);if
(princ);finish quietly
);defun

Best,

~DD

Message 5 of 9

denys_gorkovchuk
Contributor
Contributor

Hi CodeDing,

Thanks for your lisp-code improvement. Now it is much more clear and correct than my code.

Unfortunately the problem is still the same. Despite of the fact, that Lisp doesn't check the active selection set and promt user to select the point cloud, if I run it with selected point cloud it doesn't work.

I would ignore this, but I need to put a button for this Lisp on Pointcloud contextual tab, which is active only if pointcloud is selected.

0 Likes
Message 6 of 9

CodeDing
Advisor
Advisor
Accepted solution

@denys_gorkovchuk ,

 

I apologize, sometimes I miss the overall objective. Perhaps this is more the direction you seek?

This will inherit items selected before the command is ran, save the point clouds to a selection set, then run the  command you're inquiring about.

(defun c:UNCROPLAST ( / ssCloud cloud wasLocked)
;initial cloud retrieval
(setq ssCloud (ssget "_I" '((0 . "ACDBPOINTCLOUDEX"))))
;if point cloud(s) found in Implied selection
(if ssCloud
  (progn
    ;deselect ss
    (sssetfirst nil nil)
    (repeat (setq cnt (sslength ssCloud))
      (setq cloud (ssname ssCloud (setq cnt (1- cnt))))
      ;check if cropped
      (if (> (getpropertyvalue cloud "CroppingCount") 0)
  	(progn
    	  ;unlock if locked
    	  (if (= 1 (getpropertyvalue cloud "Locked")) (setq wasLocked t))
(vlax-put-property (vlax-ename->vla-object cloud) 'Locked 0) ;remove last crop (setvar 'CMDECHO 0) (command "_POINTCLOUDCROP" cloud "r") (setvar 'CMDECHO 1) ;restore lock (if wasLocked (vlax-put-property (vlax-ename->vla-object cloud) 'Locked 1)) (prompt "\nUncropping successful...") );progn ;else (prompt "\n...no cropping found for point cloud.") );if );repeat ;re-select ss (sssetfirst nil ssCloud)
(prompt "\nComplete...") );progn ;else (prompt "\n...no Point Cloud selected.") );if (princ);finish quietly );defun

Best,

~DD

Message 7 of 9

denys_gorkovchuk
Contributor
Contributor

@CodeDing 

Thanks, that works perfectly!

Can I ask for one more advice? I also would like to add promt to select pointcloud if nothing is selected. There might be a need for it if user just want to repeat the uncrop command with Enter button.

Now your code tells "no point cloud selected".

I can add ssget with point cloud filtering and then just copy the same part of the code, which works for implied selection. But I believe there should be more pretty way, without copying of same code part. Is my suggestion correct?

0 Likes
Message 8 of 9

CodeDing
Advisor
Advisor

@denys_gorkovchuk wrote:

... but I need to put a button for this Lisp on Pointcloud contextual tab, which is active only if pointcloud is selected ...


What you are requesting directly contradicts what you requested earlier. The reason for this command is to be available only when a point cloud is selected?

0 Likes
Message 9 of 9

denys_gorkovchuk
Contributor
Contributor

@CodeDing 

I would say, that in 95% of time command should work from PointCloud contextual tab when the point cloud is selected. Another 5% - from command line (or just by repeating command with Enter).

In my first version of LISP command was working ONLY from command line when point cloud is NOT selected. That was the reason why I was looking for another solution.

0 Likes