Author Topic: Auto pick a point within last created closed polyline  (Read 2882 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Auto pick a point within last created closed polyline
« on: December 08, 2010, 11:06:10 AM »
Found these links:
http://www.theswamp.org/index.php?topic=7300.msg90367#msg90367
http://www.theswamp.org/index.php?topic=28437.0

I want to auto pick a point within the last created polyline.
Polyline has been created, so using (entlast) how would I pick any point within this polyline without user input?
(getpoint) will not work for me.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Auto pick a point within last created closed polyline
« Reply #1 on: December 08, 2010, 11:27:31 AM »
It's a hack way, but I've used this method before (object must be VLA-OBJECT)...

Code: [Select]
(defun PointInsideCurve (curve)
  ;; Alan J. Thompson, 12.08.10
  (if
    (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getEndParam (list curve))))
         (vlax-curve-isClosed curve)
    )
     ((lambda (area / pt)
        (foreach obj (mapcar '(lambda (o) (car (vlax-invoke curve 'Offset o))) '(0.0001 -0.0001))
          (and (< (vla-get-area obj) area) (setq pt (vlax-curve-getStartPoint obj)))
          (vla-delete obj)
        )
        pt
      )
       (vla-get-area curve)
     )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

GDF

  • Water Moccasin
  • Posts: 2081
Re: Auto pick a point within last created closed polyline
« Reply #2 on: December 08, 2010, 11:48:08 AM »
Thanks Alan

Now how would I use this to select the last created polyline?
(PointInsideCurve...?
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Auto pick a point within last created closed polyline
« Reply #3 on: December 08, 2010, 11:54:04 AM »
Code: [Select]
(PointInsideCurve (vlax-ename->vla-object (entlast)))
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

GDF

  • Water Moccasin
  • Posts: 2081
Re: Auto pick a point within last created closed polyline
« Reply #4 on: December 08, 2010, 12:00:22 PM »
You da man. Thank you.

I am using this to create a polyline tray outine within a ceiling plan using the draw rectangle routine to pick part of the floor plans existing walls. I wanted the least user input as possible.

Thank you again.

Code: [Select]
(defun C:BXX (/ foo _dist p1 p2 p3 ang insrec pnt)
  (prompt "\n* Draw Ceiling Pan *")
  ;;(ARCH:F_S-VAR)
  ;;(ARCH:LYR "A-CLNG-HIDE")
  ;; Draw rectangle based on 2 or 3 picked points
  ;; Alan J. Thompson, 07.26.10
  (defun foo (l)
    (setq foo2
    (entmake
      (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline")(90 . 4)(70 . 1))
              (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l)
      )
    )
  ))
  (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))
  (if (and (setq p1 (getpoint "\n* Specify first point: "))
           (setq p2 (getpoint p1 "\n* Specify second point: "))
           (not (grdraw p1 p2 3 1))
      )
    (if (setq p3 (initget 0 "Left Right")
              p3 (getpoint p2 "\n* Specify third point: ")
        )
      (cond ((vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))))
            ((eq (type p3) 'STR)
             (cond
               ((eq p3 "Left") (setq ang (+ (/ pi 2.) (angle p1 p2))))
               ((eq p3 "Right") (setq ang (+ (* pi 1.5) (angle p1 p2))))
             )
             (foo (list p1 p2 (polar p2 ang (_dist p1 p2)) (polar p1 ang (_dist p1 p2))))
            )
      )
    )
  )
  (setq insrec (entlast))  
  (setq pnt (PointInsideCurve (vlax-ename->vla-object (entlast))))  
  (command "offset" "18" insrec pnt "")  
  (redraw)
  (entdel insrec)
  ;;(ARCH:F_R-VAR)
  (princ)
)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

LE3

  • Guest
Re: Auto pick a point within last created closed polyline
« Reply #5 on: December 08, 2010, 12:03:41 PM »
just did a quick test - and on the attached image pline sample it does not work, and also it leaves some of the auxiliar plines leftovers - :-(

sorry, i said to myself, myself don't get into lisp again, and myself goes and doit again.... slap on my face to myself....

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Auto pick a point within last created closed polyline
« Reply #6 on: December 08, 2010, 12:08:35 PM »
You da man. Thank you.

I am using this to create a polyline tray outine within a ceiling plan using the draw rectangle routine to pick part of the floor plans existing walls. I wanted the least user input as possible.

Thank you again.


LoL, if I had realized you were needing the point for offsetting purposes, I would have just modified accordingly. The hack method actually offsets the curve to get area for comparison. Off to lunch, but I'll scratch out something for you when I get back.

just did a quick test - and on the attached image pline sample it does not work, and also it leaves some of the auxiliar plines leftovers - :-(

sorry, i said to myself, myself don't get into lisp again, and myself goes and doit again.... slap on my face to myself....
Yeah, I knew it wouldn't be 100% - that's the trouble with hack ways.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Auto pick a point within last created closed polyline
« Reply #7 on: December 08, 2010, 04:37:48 PM »
Finally finished what I was working on. Give this a try, Gary...

(I took my original BX code and just changed the functionality of the foo subroutine.)
Code: [Select]
(defun c:BXX (/ foo _dist p1 p2 p3 ang)
  ;; Alan J. Thompson, 12.08.10

  (vl-load-com)

  (defun foo (l / e)
    ((lambda (area)
       (vl-some
         (function (lambda (o / off)
                     (if (> area (vla-get-area (setq off (car (vlax-invoke e 'Offset o)))))
                       (not (vla-delete e))
                       (vla-delete off)
                     )
                   )
         )
         '(-18. 18.)
       )
     )
      (vla-get-area
        (setq e
               (vlax-ename->vla-object
                 (entmakex
                   (append
                     '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 4) (70 . 129))
                     (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l)
                   )
                 )
               )
        )
      )
    )
  )

  (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))

  (if (and (setq p1 (getpoint "\nSpecify first point: "))
           (setq p2 (getpoint p1 "\nSpecify second point: "))
           (not (grdraw p1 p2 3 1))
      )
    (if (setq p3 (initget 0 "Left Right")
              p3 (getpoint p2 "\nSpecify third point or Square box or [Left/Right]: ")
        )
      (cond ((vl-consp p3) (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))))
            ((eq (type p3) 'STR)
             (cond
               ((eq p3 "Left") (setq ang (+ (/ pi 2.) (angle p1 p2))))
               ((eq p3 "Right") (setq ang (+ (* pi 1.5) (angle p1 p2))))
             )
             (foo (list p1 p2 (polar p2 ang (_dist p1 p2)) (polar p1 ang (_dist p1 p2))))
            )
      )
    )
  )
  (redraw)
  (princ)
)

Edited to reverse offset value list (more times that not, the negative offset will be the one - no reason to offset the other if you don't have to.
« Last Edit: December 08, 2010, 04:49:58 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

GDF

  • Water Moccasin
  • Posts: 2081
Re: Auto pick a point within last created closed polyline
« Reply #8 on: December 08, 2010, 06:30:58 PM »
Thanks Alan

Works perfectly.

Changed (70 . 129) to (70 . 1) so the the dashed line type that I use shows up correctly.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Auto pick a point within last created closed polyline
« Reply #9 on: December 08, 2010, 06:50:03 PM »
Good deal. Enjoy.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox