Author Topic: Create line perpendecular to a polyline  (Read 3109 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Create line perpendecular to a polyline
« on: September 07, 2007, 12:11:14 AM »
Here my code to create line from point at red line to perpendecular of white color line, but that code is still trouble, it can not work
and look at attach file for clear information
Code: [Select]
(defun c:test ()
  (if
    (setq ssc (car (entsel "\nClick red color line")))
    (progn
      (setq ssw (entsel "\nClick white color line"))
      (setq dis 25)
      (command "_divide" ssc dis "")
      (setq ssp (ssget "x" (list (cons 0 "POINT"))))
      (setq sslp (sslength ssp))
      (setq cnt1 0)
      (repeat
sslp
(setq pn (ssname ssp cnt1))
(setq sse_pn (entget pn))
(setq sp_pn (cdr (assoc 10 sse_pn)))
(setq lst_pkn (append lst_pkn (list sp_pn)))
(setq cnt1 (1+ cnt1))
)  ; repeat
      (setq lst_pn (reverse lst_pn))
      (setq len1 (length lst_pn))
      (setq cnt2 0)
      (repeat
len1
(setq pt1 (nth cnt2 lst_pkn))
(setq om (getvar "osmode"))
(setvar "osmode" 128)
(setq pt2 (osnap (cadr ssw) "_perp"))
(command "_line" pt pt2 "")
(setvar "osmode" om)
(setq cnt2 (1+ cnt2))
)   ; repeat
      )     ; progn
    )       ; if
  (princ)
  )         ; defun
« Last Edit: September 07, 2007, 12:21:59 AM by Adesu »

LUCAS

  • Newt
  • Posts: 32
Re: Create line perpendecular to a polyline
« Reply #1 on: September 07, 2007, 01:11:54 AM »
Code: [Select]
(defun C:TEST (/      CNT1   CNT2   DIS    LEN1   LST_PKN OM
       PN     PT1    PT2    SP_PN  SSC   SSE_PN SSLP SSP
       SSW
      )
  (setq OM (getvar "osmode"))
  (setvar "osmode" 0)
  (if
    (setq SSC (car (entsel "\nClick red color line")))
     (progn
       (setq SSW (vlax-ename->vla-object
   (car (entsel "\nClick white color line"))
)
       )
       (setq DIS 25)
       (command "_divide" SSC DIS)
       (setq SSP (ssget "x" (list (cons 0 "POINT"))))
       (setq SSLP (sslength SSP))
       (setq CNT1 0)
       (repeat SSLP
(setq PN (ssname SSP CNT1))
(setq SSE_PN (entget PN))
(setq SP_PN (cdr (assoc 10 SSE_PN)))
(setq LST_PKN (append LST_PKN (list SP_PN)))
(setq CNT1 (1+ CNT1))
       ) ; repeat
       (setq LST_PKN (reverse LST_PKN))
       (setq LEN1 (length LST_PKN))
       (setq CNT2 0)
       (repeat LEN1
(setq PT1 (nth CNT2 LST_PKN))
(setq PT2 (vlax-curve-getclosestpointto SSW PT1 ))
(command "_line" PT1 "PER" PT2 "")
(setq CNT2 (1+ CNT2))
       ) ; repeat
     ) ; progn
  ) ; if
  (setvar "osmode" OM)
  (princ)
) ; defun
<edit: Code tags Added by CAB>
« Last Edit: September 07, 2007, 11:42:58 AM by CAB »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Create line perpendecular to a polyline
« Reply #2 on: September 07, 2007, 01:31:18 AM »
Hi Adesu,

Look around the vlax-curve... functions :

(vlax-curve-getDistAtParam ssc (vlax-curve-getEndParam ssc)) ; to get the ssc pline length.

(setq pt (vlax-curve-getPointAtDist ssc ...)) ; instead of divide command

(vlax-curve-getClosestPointTo ssw pt) ; to get the perpendicular at ssw from each pt
Speaking English as a French Frog

Adesu

  • Guest
Re: Create line perpendecular to a polyline
« Reply #3 on: September 07, 2007, 01:57:45 AM »
Hi LUCAS,
it's great, thanks you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Create line perpendecular to a polyline
« Reply #4 on: September 07, 2007, 12:34:42 PM »
Just an observation but there are Dead Zones where there are no areas on white line that are perpendicular
and the Red Line has areas where two areas on white line that are perpendicular.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.