Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Line in the middle of four lines

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
902 Views, 7 Replies

Line in the middle of four lines

Hi, I need lisp that do a line between 4 lines. 

 

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

(defun C:PLOO (/ P1 P2 P3)
  (setq OS (getvar "osmode"))
  (command "_PLINE")
  (setvar "OSMODE" 1)
  (setq P1 (getpoint "\nPick 1st Pline Point ? "))
  (while P1
    (setq P2 (getpoint P1 "\nPick 2nd Pline Point ? "))
    (setq P3 (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0)))
    (setvar "OSMODE" 0)
    (command P3)
    (setvar "OSMODE" 1)
    (setq P1 (getpoint "\nPick 1st Pline Point ? "))
  )
  (setvar "osmode" OS)
  (princ)
)

Message 3 of 8
Anonymous
in reply to: Anonymous

Good but i think there is better way i want,

instead of picking point by point i prefer picking all 4 lines once and immediatly the line is drawn.

can this be done ?

 

 

Message 4 of 8
Lee_Mac
in reply to: Anonymous

This was an interesting program to write, give it a try:

 

(defun c:cline ( / a b i l s x )
    (while
        (progn (setq l nil s (ssget '((0 . "LINE"))))
            (cond
                (   (null s) nil)
                (   (/= 4 (sslength s))
                    (princ "\nPlease select 4 lines only.")
                )
                (   (progn
                        (repeat (setq i (sslength s))
                            (setq x (entget (ssname s (setq i (1- i))))
                                  l (cons (list (cdr (assoc 10 x)) (cdr (assoc 11 x))) l)
                            )
                        )
                        (setq l
                            (LM:groupbyfunction l
                                (lambda ( a b )
                                    (vl-every '(lambda ( x ) (apply 'LM:collinear-p (cons x b))) a)
                                )
                            )
                        )
                        (/= 2 (length l))
                    )
                    (princ "\nPlease select two sets of collinear lines.")
                )
                (   t
                    (setq l
                        (mapcar
                            (function
                                (lambda ( x )
                                    (list
                                        (if (< (distance (caar  x) (caadr x))
                                               (distance (cadar x) (caadr x))
                                            )
                                            (caar  x)
                                            (cadar x)
                                        )
                                        (if (< (distance (caar x) (cadadr x))
                                               (distance (caar x) (caadr  x))
                                            )
                                            (cadadr x)
                                            (caadr  x)
                                        )
                                    )
                                )
                            )
                            l
                        )
                    )
                    (if (< (distance (cadar l) (caadr l))
                           (distance (caar  l) (caadr l))
                        )
                        (setq l (cons (reverse (car l)) (cdr l)))
                    )
                    (entmake
                        (cons '(0 . "LINE")
                            (mapcar
                                (function
                                    (lambda ( a b )
                                        (cons a
                                            (apply 'mapcar
                                                (cons '(lambda ( a b ) (/ (+ a b) 2.0)) b)
                                            )
                                        )
                                    )
                                )
                               '(10 11)
                                (apply 'mapcar (cons 'list l))
                            )
                        )
                    )
                )
            )
        )
    )
    (princ)
)

;; Group By Function  -  Lee Mac
;; Groups items considered equal by a given predicate function

(defun LM:GroupByFunction ( lst fun / tmp1 tmp2 x1 )
    (if (setq x1 (car lst))
        (progn
            (foreach x2 (cdr lst)
                (if (fun x1 x2)
                    (setq tmp1 (cons x2 tmp1))
                    (setq tmp2 (cons x2 tmp2))
                )
            )
            (cons (cons x1 (reverse tmp1)) (LM:GroupByFunction (reverse tmp2) fun))
        )
    )
)

;; Collinear-p  -  Lee Mac
;; Returns T if p1,p2,p3 are collinear

(defun LM:Collinear-p ( p1 p2 p3 )
    (
        (lambda ( a b c )
            (or
                (equal (+ a b) c 1e-8)
                (equal (+ b c) a 1e-8)
                (equal (+ c a) b 1e-8)
            )
        )
        (distance p1 p2) (distance p2 p3) (distance p1 p3)
    )
)

(princ)

 

Message 5 of 8
Anonymous
in reply to: Lee_Mac

Good i enjoy it Thanks Lee_Mac Smiley Wink , is it possible for it to slect multiple 4 lines by ssget  ensel (purpose selecting multiple walls to fill lines once) ?

as optional way for future need can you provide me addition that construct two vertical fill lines usually my colleague trim wall by door block which results in no ending lines (that i need it during exportign to photoshop to quickly fill pattern 🙂 ).

 

Message 6 of 8
Lee_Mac
in reply to: Anonymous

Please understand that my time here is voluntary, I do not participate here to write code at your request. In this case the problem posed yielded an interesting solution which may be of benefit to those learning in the community, however, if you require several programs, I would suggest that you hire a programmer.

Message 7 of 8
stevor
in reply to: Anonymous

Your last appears to be a standard window figure; and there should be several code examples available with some searching. Or learn some autolisp and make it yourself. That is why the autolisp exists. If you solicit a programmer, like Mac, do it after you are aware of the features that would make it economic.
S
Message 8 of 8
Anonymous
in reply to: Lee_Mac

I understood Smiley Surprised

thanks anyway for your time

a few starting question :

Could someone recommend me how to start easily way (i want to enjoy not to be tortured) ?

Is learning multiple language like c# and lisp will be distracting (usually c# is necessary for revit user)?

what is your often reference or how to reach them in help as lisp search only ?

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost