Author Topic: Select Inside the Closed polyline & Get Layerwise Length of the Polyline  (Read 413 times)

0 Members and 1 Guest are viewing this topic.

manivanchi

  • Mosquito
  • Posts: 11
Dear All,

        Is there any lisp to Select all the lines inside the closed polyline and get the length Layer Wise.

        Please let me know your suggestions

Thanks in Advance

Regards,

Manikandan S V

BIGAL

  • Newt
  • Posts: 83
  • 30 + years of using Autocad
This is a simple request and I am sure there is multiple code out there, in a nutshell using lisp ssget "WP" ie get all objects inside a pline. Then just loop through them all and get their lengths.

Have a look also at www.lee-mac.com

Search also for "total length" here and at cadtutor as well.

This an example pointing you in the right direction.

Code: [Select]

; By Alan H may 2013
(vl-load-com)
(defun getcoords (ent)
  (vlax-safearray->list
    (vlax-variant-value
      (vlax-get-property
    (vlax-ename->vla-object ent)
    "Coordinates"
      )
    )
  )
)
 
(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
) ; end defun


; program starts here
; choose output file change acdatemp to what you want
(setq fname (strcat "c:/alan/" (getstring "\nEnter file name ")))
(setq fout (open fname "w"))
(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)
(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
(co-ords2xy)
; write pline co-ords here
(setq numb3 (length co-ords))
(setq z numb3)
(setq ansco-ords "")
(repeat numb3
(setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
)
(setq ans (strcat "Pline " ansco-ords))
(write-line ans fout)
(setq ansco-ords "")
(setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
(if (= ss nil)
(princ "\nnothing inside")
(progn
(setq coordsxy nil) ; reset for next time
(setq numb2 (sslength ss))
(setq y numb2)
(repeat numb2
(setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
(princ anstext) ; change to write text to file
(write-line (strcat "text " anstext) fout)
(princ "\n")
) ; end repeat2
(setq ss nil) ; reset for next poly
)
)
) ; end repeat1
(close fout)
(princ)
« Last Edit: July 17, 2017, 12:30:13 am by BIGAL »
A man who never made a mistake never made anything

manivanchi

  • Mosquito
  • Posts: 11
Dear BIGAl,

Thanks for the reply.

The WP Command not working Properly. When I run the WP it Selecting only inside the Polygon. Not Within the Polygon.

Means Suppose a Polyline touched the boundary polygon. The WP Command not Selecting the polygon.

is there any other way to select Objects Within the Polygon?

Regards,
Manikandan

kh001058

  • Mosquito
  • Posts: 3
Try replace : (ssget "WP" ...
with : (ssget "CP" ....

manivanchi

  • Mosquito
  • Posts: 11
Dear KH,

Thanks for the reply.

If we use CP it Will Select All the polyine touched inside and outside of the polygon also.

I need to select the all objects only within polygon and touched the polygon boundary from Inside. Not from the Outside.

Regards,

Manikandan

jvillarreal

  • Bull Frog
  • Posts: 293
Offset the boundary and use WP.

BIGAL

  • Newt
  • Posts: 83
  • 30 + years of using Autocad
You can use (ssget "F" pts)  using the same list of points as "WP" this will find anything that touches the pline, then add the two selection sets together.

A man who never made a mistake never made anything

manivanchi

  • Mosquito
  • Posts: 11
but its not coming in proper way. can i get the complete code?

mailmaverick

  • Bull Frog
  • Posts: 358
Please share your AutoCAD drawing so that we may give you correct code