symoin Posted December 22, 2023 Posted December 22, 2023 Hi all, Is there any ways or any lisp code to select the unique points. 1. Ignoring the duplicates. (same x,y,z and layer) and copy to a new drawing. 2. Another set to copy points having duplicate x,y,z and different layer to another new drawing. or Erase the Duplicates with same x,y,z and layers. Then Prompt to select the Points which has same x,y and z but different layer. Or prompt to select the Unique points without any duplications. Quote
Steven P Posted December 22, 2023 Posted December 22, 2023 I use this to remove duplicated points from a list, it actually works by removing duplicated list items contained within the list. (defun unique ( MyList / MyCount MyResult ) ;; Unique list items (setq Mycount (length MyList)) (setq MyResult (list (last MyList))) (while (> MyCount 0) (setq Mycount (- MyCount 1)) (if (member (nth MyCount MyList) MyResult) () (setq MyResult (append (list (nth MyCount MyList)) MyResult)) ) ) MyResult ) The entity definition is a list so you could use something like this: This gets a selection set, filtered for points only (setq Points_List (list)) ; Blank list (setq SS (ssget '((0 . "POINT")))) ; Seletion set of point (setq acount 0) ; A Counter (while (< acount (sslength SS)) ; Loop each item in selection set (setq MyEnt (entget (ssname SS acount))) ; get entity definition for item n in SS (setq NewEnt (list (assoc 0 MyEnt) (assoc 67 MyEnt) (assoc 8 MyEnt) (assoc 10 MyEnt))) ; extract the important info for points (setq Points_List (append Points_List NewEnt)) ; create a list of important point information for comparison (ignoring entity names) (setq acount (+ acount 1)) ) ; end while (princ (unique Points_List)) ; runs Unique (above) and displays the points list in the command line Combined together something like this: (defun c:test ( / Points_List SS acount MyEnt NewEnt MyCount MyResult MyRemoved Mycount ) (setq Points_List (list)) (setq SS (ssget '((0 . "POINT")))) (setq acount 0) (while (< acount (sslength SS)) (setq MyEnt (entget (ssname SS acount))) (setq NewEnt (list (assoc 0 MyEnt) (assoc 67 MyEnt) (assoc 8 MyEnt) (assoc 10 MyEnt))) (setq Points_List (append Points_List (list NewEnt)) ) (setq acount (+ acount 1)) ) ; end while (setq MyCount (length Points_List)) (setq MyResult (list)) (setq MyRemoved (list)) (while (> MyCount 0) (setq Mycount (- MyCount 1)) (if (member (nth MyCount Points_List) MyResult) (setq MyRemoved (append (list (nth MyCount Points_List)) MyRemoved)) (setq MyResult (append (list (nth MyCount Points_List)) MyResult)) ) ; end if ) ; end while (princ "\n")(princ MyRemoved) (princ "\n")(princ MyResult) (princ) ) The items in the 2 lists, MyRemoved and MyResult are what would be used to create a new point using entmake where (nth 0 MyResult) will create the first point in the list (if that makes sense). So to create these points in a new drawing copy the relevant list to the clipboard in this drawing, and in the new drawing loop through the list and using entmake or entmakex to create the points. I think the below will copy a list to clipboard: ;;Copy text to clipboard ;; (vlax-invoke (vlax-get (vlax-get (vlax-create-object "htmlfile") 'ParentWindow) 'ClipBoardData) 'setData "TEXT" --MYTEXTSTRING-- ) ;;(vlax-release-object html) ;;and release the object ;;Get text from clipboard ;;(vlax-invoke (vlax-get (vlax-get (vlax-create-object "htmlfile") 'ParentWindow) 'ClipBoardData) 'getData "TEXT" ) ;;(vlax-release-object html) For removing the duplicates from the drawing I would work out the list, MyResult, and then if appropriate delete all the existing selected points (command "erase" SS "") and then use entmake or entmakex on each item in the list to create a new point. For duplicate points different layers do the same as above but take out the (assoc 8 MyEnt) text. (answered assuming you know some LISP and can make sense of my ramblings) Quote
Recommended Posts
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.