Jump to content

get polyline area by clicking at the polyline itself


Bikey_4

Recommended Posts

Hi there,

 

 

I've got a LisP file which help me to get area value of closed polyline and assign it to a text. It require picking a point inside then it will creat a closest polyline around the picked point.

However, my drawing has already had some polyline, and I want to get their area by clicking at the polyline itself.

Unfortunately, I have no idea about LisP. Hope you guy can help me solve this problem.

Thx a lot!

(Pls see attachment for more details)

DTICH.LSP

Link to comment
Share on other sites

(defun c:test ( / a b c)
 (if (setq a (ssget '((0 . "*polyline"))))
   (progn
     (setq b 0)
     (repeat (setq i (sslength a))
(setq b
       (+ (vla-get-area
	       (vlax-ename->vla-object (ssname a (setq i (1- i))))
	     )
	     b
       )
)
     )
     (setq c (strcat "\nComponent Area : " (rtos b 2 5)))
     (alert c)
     (prompt c)
   )
 )
 (princ)
)

Link to comment
Share on other sites

Seems your LisP is used to get the sum of polyline's areas. Is there any idea for separated polylines?

Thanks for your comment!

Link to comment
Share on other sites

This one marks text with the area at start point of the polyline.

(defun c:test (/ a b c)
 (vl-load-com)
 (if (setq a (ssget '((0 . "*polyline"))))
   (repeat (setq i (sslength a))
     (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
     (setq c (vlax-get b 'coordinates))
     (command ".text"
       "c"
       "_non"
       (list (car c) (cadr c))
       50			; <- change text height here as per your requirement
       0			; <- change text rotation here as per your requirement
       (rtos (vla-get-area b) 2 5)
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Another way to approach is to still use the bpoly get its area then erase Last and write text. I think its code by GP has a brilliant area routine whereby it works out the center of the area for the text position.

Link to comment
Share on other sites

  • 7 years later...
On 7/6/2016 at 4:53 AM, BIGAL said:

think its code by GP has a brilliant area routine whereby it works out the center of the area for the text position.

Could You explain what code You mean? Loking for something that will work out the center of polyline. 

Link to comment
Share on other sites

This may help

(setq pt (osnap (vlax-curve-getStartPoint obj) "gcen")) ; obj is a VL object

 But note if you have say a "U" shape pt may not be inside pline.

Edited by BIGAL
Link to comment
Share on other sites

Thanks @BIGAL.
Thought about that, that geometric center is not always inside polyline. Using QGIS, it also can label in center of polyline but it also have option "force point inside polygon". I'm curious about the algorithm that controls that. For me, most problem is "L" shape polylines.
Thought that algorith in QGIS could be something like that it is finding geometric center or something like here in ATM code:
https://jtbworld.com/autocad-areatext-lsp
After finding center (geometric or like in ATM) it is finding intersection with horizontal (or vertical xlines). After that, sorting X (or Y for vertical) and find if center is before/inside/after X of intersection. After that, choose/calculate new X.

Link to comment
Share on other sites

On 7/6/2016 at 4:53 AM, BIGAL said:

Another way to approach is to still use the bpoly get its area then erase Last and write text. I think its code by GP has a brilliant area routine whereby it works out the center of the area for the text position.

 

 

Edited by GP_
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...