Author Topic: Asking for a lisp to delete shorter line of 2 parallel lines  (Read 2454 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1423
Asking for a lisp to delete shorter line of 2 parallel lines
« on: September 19, 2012, 06:24:12 AM »
In the file what I am working on there are a lot of parallel lines
Is there a lisp to delete the shorter one?

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: Asking for a lisp to delete shorter line of 2 parallel lines
« Reply #1 on: September 19, 2012, 06:50:18 AM »
Select lines and entget 1st line, search the rest of lines and compare their unit vector with unit vector from 1st line... If unit vectors are the same or opposite then compare distances of vector from 1st line and 2nd line... If one distance is smaller then entdel smaller line, then compare distances of 1st line and 3rd line (entdel smaller line)... Proceed to next loop to search next pair of lines with the same or opposite unit vectors... Loop until all unit vectors are different...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Asking for a lisp to delete shorter line of 2 parallel lines
« Reply #2 on: September 19, 2012, 07:47:47 AM »
If unit vectors are the same or opposite...

Alternatively, you could test whether the cross product of the line vectors is zero, or whether the dot product of the unit vectors is one, removing the need for the 'opposite' test.

ribarm

  • Gator
  • Posts: 3312
  • Marko Ribar, architect
Re: Asking for a lisp to delete shorter line of 2 parallel lines
« Reply #3 on: September 19, 2012, 09:44:30 AM »
Here is my quick and dirty - you have to repeat routine as many times as you have more pairs of parallel lines :

Code - Auto/Visual Lisp: [Select]
  1. (defun unit (vec)
  2.   (mapcar '(lambda (v) (/ v (distance '(0.0 0.0 0.0) vec))) vec)
  3. )
  4.  
  5. (defun c:delshortparallines ( / ss ent entdst entdstlst entlstsort entlst entlstun )
  6.   (prompt "\nSelect LINE objects")
  7.   (setq ss (ssget ":L" '((0 . "LINE"))))
  8.   (while (setq ent (ssname ss 0))
  9.     (setq entdst (distance (cdr (assoc 10 (entget ent))) (cdr (assoc 11 (entget ent)))))
  10.     (setq entdstlst (cons (cons entdst ent) entdstlst))
  11.     (ssdel ent ss)
  12.   )
  13.   (setq entlstsort (vl-sort entdstlst '(lambda (a b) (> (car a) (car b)))))
  14.   (foreach e entlstsort
  15.     (setq entlst (cons (cdr e) entlst))
  16.   )
  17.   (foreach e entlst
  18.     (setq entlstun (cons (cons (unit (mapcar '- (cdr (assoc 11 (entget e))) (cdr (assoc 10 (entget e))))) e) entlstun))
  19.   )
  20.   (foreach e entlstun
  21.     (foreach x (setq entlstun (cdr entlstun))
  22.       (if (and (entget (cdr x)) (or (equal (car x) (car e) 1e-8) (equal (list (- (caar x)) (- (cadar x)) (- (caddar x))) (car e) 1e-8))) (entdel (cdr x)))
  23.     )
  24.   )
  25.   (princ)
  26. )
  27.  
  28. (defun c:dspls nil (c:delshortparallines))
  29. (prompt "\nShortcut for c:delshortparallines is c:dspls - to invoke : Command : dspls")
  30.  

[EDIT : code changed to operate as required - no need to repeat it, it should clean it completely in one turn]

M.R.
« Last Edit: September 19, 2012, 11:44:09 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

HasanCAD

  • Swamp Rat
  • Posts: 1423
Re: Asking for a lisp to delete shorter line of 2 parallel lines
« Reply #4 on: September 20, 2012, 08:44:08 AM »
Here is my quick and dirty
M.R.

In fact that exactly what i am looking for. but is it possible to deal with couple of line only not all selected lines