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

Perpendicular line from multiple BLOCK BASE POINT to Polyline

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
mint09
2494 Views, 13 Replies

Perpendicular line from multiple BLOCK BASE POINT to Polyline

is it possible to change this lisp to get Perpendicular line from a Point to Perpendicular line from a BLOCK BASE POINT ?

i mean first select the polyline and then select all blocks and it'll create a perpendicular line to the polyline/line/arc ive selected and draw a line. The lisp above creates the same but i can only select points, not blocks.

 

(defun c:ppl ( / ent idx pnt sel )
    (if
        (and (setq sel (LM:ssget "\nSelect points: " '(((0 . "POINT")))))
            (progn
                (while
                    (progn (setvar 'errno 0) (setq ent (entsel "\nSelect curve: "))
                        (cond
                            (   (= 7 (getvar 'errno))
                                (princ "\nMissed, try again.")
                            )
                            (   (null ent) nil)
                            (   (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getclosestpointto ent))
                                (princ "\nInvalid object selected.")
                            )
                        )
                    )
                )
                (setq ent (car ent))
            )
        )
        (repeat (setq idx (sslength sel))
            (setq idx (1- idx)
                  pnt (assoc 10 (entget (ssname sel idx)))
            )
            (entmake (list '(0 . "LINE") pnt (cons 11 (vlax-curve-getclosestpointto ent (cdr pnt)))))
        )
    )
    (princ)
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
    (princ msg)
    (setvar 'nomutt 1)
    (setq sel (vl-catch-all-apply 'ssget arg))
    (setvar 'nomutt 0)
    (if (not (vl-catch-all-error-p sel)) sel)
)
(vl-load-com) (princ)

i don't know much about lisp codes and all, please help if possible.. Thanks..

13 REPLIES 13
Message 2 of 14
dlanorh
in reply to: mint09


@mint09 wrote:

is it possible to change this lisp to get Perpendicular line from a Point to Perpendicular line from a BLOCK BASE POINT ?

i mean first select the polyline and then select all blocks and it'll create a perpendicular line to the polyline/line/arc ive selected and draw a line. The lisp above creates the same but i can only select points, not blocks.

 

(defun c:ppl ( / ent idx pnt sel )
    (if
        (and (setq sel (LM:ssget "\nSelect points: " '(((0 . "POINT,INSERT")))))
            (progn
                (while
                    (progn (setvar 'errno 0) (setq ent (entsel "\nSelect curve: "))
                        (cond
                            (   (= 7 (getvar 'errno))
                                (princ "\nMissed, try again.")
                            )
                            (   (null ent) nil)
                            (   (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getclosestpointto ent))
                                (princ "\nInvalid object selected.")
                            )
                        )
                    )
                )
                (setq ent (car ent))
            )
        )
        (repeat (setq idx (sslength sel))
            (setq idx (1- idx)
                  pnt (assoc 10 (entget (ssname sel idx)))
            )
            (entmake (list '(0 . "LINE") pnt (cons 11 (vlax-curve-getclosestpointto ent (cdr pnt)))))
        )
    )
    (princ)
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
    (princ msg)
    (setvar 'nomutt 1)
    (setq sel (vl-catch-all-apply 'ssget arg))
    (setvar 'nomutt 0)
    (if (not (vl-catch-all-error-p sel)) sel)
)
(vl-load-com) (princ)

i don't know much about lisp codes and all, please help if possible.. Thanks..


 

Make the change in RED above and try that

 

 

I am not one of the robots you're looking for

Message 3 of 14
ВeekeeCZ
in reply to: mint09

... and swapped order of selection...

 

(defun c:ppl ( / ent idx pnt sel )
  (if (progn
	(while
	  (progn (setvar 'errno 0) (setq ent (entsel "\nSelect curve: "))
	    (cond
	      (   (= 7 (getvar 'errno))
	       (princ "\nMissed, try again.")
	       )
	      (   (null ent) nil)
	      (   (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getclosestpointto ent))
	       (princ "\nInvalid object selected.")
	       )
	      )
	    )
	  )
	(setq ent (car ent))
	)
    (while (setq sel (ssget "_:S" '((0 . "POINT,INSERT"))))
      (repeat (setq idx (sslength sel))
	(setq idx (1- idx)
	      pnt (assoc 10 (entget (ssname sel idx)))
	      )
	(entmake (list '(0 . "LINE") pnt (cons 11 (vlax-curve-getclosestpointto ent (cdr pnt)))))
	)
      ))
  (princ)
  )

(vl-load-com) (princ)

 

Message 4 of 14
john.uhden
in reply to: mint09

I see a problem with the code.

vlax-curve-getclosestpointto may easily return a point that's the beginning or end or a vertex, not necessarily perpendicular to the curve object.  Now it's all fine if what you meant by the word "perpendicular" is really the closest point

As far as blocks vs. points, the assoc 10 applies to both.

John F. Uhden

Message 5 of 14
ronjonp
in reply to: mint09

Solution HERE too.

Message 6 of 14
ronjonp
in reply to: john.uhden


@john.uhden wrote:

I see a problem with the code.

vlax-curve-getclosestpointto may easily return a point that's the beginning or end or a vertex, not necessarily perpendicular to the curve object.  Now it's all fine if what you meant by the word "perpendicular" is really the closest point

As far as blocks vs. points, the assoc 10 applies to both.


Maybe something more like this ? 🙂

2019-07-24_11-41-54.gif

Message 7 of 14
dlanorh
in reply to: john.uhden

You can alway use the optional extent parameter, as in

 

(vlax-curve-getclosestpointto ent pt T)

I am not one of the robots you're looking for

Message 8 of 14
mint09
in reply to: dlanorh

Thanks all, its working as i needed.THANK YOU SO MUCH..

 

i got one more from the link it gave, ill paste it here. its from RONJONP,

 

(defun c:foo (/ _dxf _sl a b c e p s x)
  ;; RJP » 2019-01-10
  (defun _sl (s) (cond ((= 'pickset (type s)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))))
  (defun _dxf (c e) (cdr (assoc c (entget e))))
  (cond
    ((setq s (_sl (ssget)))
     (foreach x	s
       (if (wcmatch (_dxf 0 x) "CIRCLE,INSERT,POINT")
	 (setq b (cons (_dxf 10 x) b))
	 (and (= 'real (type (vl-catch-all-apply 'vlax-curve-getendparam (list x))))
	      (setq a (cons x a))
	 )
       )
     )
     (and a
	  b
	  (foreach p b
	    (setq c
		   (car	(vl-sort
			  (mapcar
			    '(lambda (x)
			       (list (setq c (vlax-curve-getclosestpointto x p)) (distance p c) (_dxf 8 x))
			     )
			    a
			  )
			  '(lambda (r j) (< (cadr r) (cadr j)))
			)
		   )
	    )
	    (setq e (entmakex (list '(0 . "line") (cons 10 p) (cons 11 (car c)) (cons 8 (caddr c)))))
	    ;; This line below creates the right example comment out to get left
	    ;; (setq a (cons e a))
	  )
     )
    )
  )
  (princ)
)

 

Message 9 of 14
ВeekeeCZ
in reply to: mint09


@mint09 wrote:

... i got one more from the link it gave, ill paste it here. its from RONJONP, ...


 

aka @ronjonp. He posted a link to his solution... 😉

Message 10 of 14
ronjonp
in reply to: ВeekeeCZ


@ВeekeeCZ wrote:

@mint09 wrote:

... i got one more from the link it gave, ill paste it here. its from RONJONP, ...


 

aka @ronjonp. He posted a link to his solution... 😉


I wish I could change my username to 'ronjonp' for consistency across the interwebs .. do you know any of the moderators / site admin that could do this for me?

Message 11 of 14
ВeekeeCZ
in reply to: ronjonp

I guess the best place is  HERE

Or you could hit the "Report" button and ask.

Or as we talk about it here, I would notify him @Discussion_Admin 

Message 12 of 14
Discussion_Admin
in reply to: ronjonp


@ronjonp 

Just follow the steps here and you can change it yourself.

Note you will have to log out and back in for changes to take effect.

 

DA

Message 13 of 14
john.uhden
in reply to: dlanorh

Why, thank you, Ron.

Don't know when I would use it, but I wasn't aware of that.

Learning is a wonderful thing!

John F. Uhden

Message 14 of 14
ronjonp
in reply to: Discussion_Admin


@Discussion_Admin wrote:

@ronjonp 

Just follow the steps here and you can change it yourself.

Note you will have to log out and back in for changes to take effect.

 

DA


Thanks for the link! I'm going to have to wait until the system recognizes that I just removed an old personal profile that already uses the username I want to change to ..DOH!

 

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report