Jump to content

Recommended Posts

Posted

Hello

I need a routine that allows me to eliminate points from a polyline based on a deflection value or inversion of the direction of the vertices in order to correct its geometry.

I am attaching the code that I generated using some existing routines and also a dwg with the incorrect geometry and how it should look after correction.

 

Thanks to anyone who can help

errogeomlw.dwg corrgeomlw.lsp

Posted

Hi hildevasco_br. Dos sub functions are missing from your lsp routine. Try to locate them.

Posted (edited)

Nevermind - previous comments stricken.

Edited by pkenewell
Posted (edited)

Hi HildeVasco.
After reading Pkenewell, I don't know if I missed something important in the conversation.

Regarding your question, I understand that you need to simplify the geometry of polylines that have too many points.

I did something for this years ago. The algorithm is simple: it analyzes the distance from each point to the line between the previous and subsequent points.

 

I set a default value of 1 centimeter, but you can change it at the beginning of the command execution.

The code is simple and depends entirely on itself.
It works very well.

I think it will be useful for you.

 

;******************* G L A V C V S *******************
;********************* F E C I T *********************
(defun c:simplificaLWPs	(/ toler regen_subNorma cj n)
  (defun regen_subNorma
	 (ent toler / lstent lstpts pto_ortog saca_list10ptos supripuntos)
    (defun supripuntos (lstpts / pt1 pt2 pt3 n lst_pts ptort)
      (setq pt1	    (cdr (nth 0 lstpts))
	    pt2	    (cdr (nth 1 lstpts))
	    n	    2
	    lst_pts (append lst_pts (list (nth 0 lstpts)))
      )
      (while (setq pt3 (nth n lstpts))
	(setq pt3   (cdr pt3)
	      ptort (pto_ortog pt1 pt3 pt2 nil)
	)
	(if (or
	      (and ptort
		   (> (distance ptort pt2) toler)
	      )
	      (and
		(not ptort)
		(> (distance pt2 pt1) toler)
		(> (distance pt2 pt3) toler)
	      )
	    )
	  (setq	lst_pts	(append lst_pts (list (cons 10 pt2)))
		pt1	pt2
		pt2	pt3
		n	(+ n 1)
	  )
	  (setq	pt2 pt3
		n   (+ n 1)
	  )
	)
      )
      (append lst_pts (list (cons 10 pt2)))
    )
    (defun pto_ortog (ptvec1 ptvec2 ptbas infin / ang pt)
      (setq ang (+ (angle ptvec1 ptvec2) (/ pi 2)))
      (if infin
	(setq
	  pt
	   (inters ptvec1 ptvec2 ptbas (polar ptbas ang 30000) nil)
	)
	(if (not
	      (setq
		pt
		 (inters ptvec1 ptvec2 ptbas (polar ptbas ang 30000))
	      )
	    )
	  (setq	pt
		 (inters ptvec1 ptvec2 ptbas (polar ptbas (+ ang pi) 30000))
	  )
	  pt
	)
      )
    )
    (setq lstent
	   (entget ent)
    )
    (setq lstpts (vl-remove-if-not '(lambda (x) (= (car x) 10)) lstent))
    (setq lstpts (supripuntos lstpts))
    (setq lstent (reverse (member (assoc 70 lstent) (reverse lstent))))
    (entmod
      (append (subst (cons 90 (length lstpts)) (assoc 90 lstent) lstent)
	      lstpts
      )
    )
  )

  (if (not (setq toler (getreal "\nTolerancia máxima en metros <0.01>: ")))
    (setq toler 0.01)
  )
  (if (setq cj (ssget '((0 . "LWP*"))))
    (while (setq ent (ssname cj
			     (setq n (if n
				       (1+ n)
				       0
				     )
			     )
		     )
	   )
      (regen_subNorma ent toler)
    )
  )
  (princ (strcat "\nSe han procesado " (itoa n) " polilíneas"))
  (princ)
)

 

 

 

Edited by GLAVCVS
Posted
1 hour ago, GLAVCVS said:

After reading Pkenewell, I don't know if I missed something important in the conversation.

@GLAVCVS No problem. I pulled my comments because I wasn't sure I understood correctly. Sometimes I'm plagued with speaking before thinking 😜

Posted

Weed.lsp, Pldiet.lsp to mention a couple. Maybe try them.

Posted
16 hours ago, pkenewell said:

@GLAVCVS No problem. I pulled my comments because I wasn't sure I understood correctly. Sometimes I'm plagued with speaking before thinking 😜

 

👍🏼... 🙂

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...