Calculating areas of closed Plines of different linetypes

Calculating areas of closed Plines of different linetypes

Anonymous
Not applicable
1,528 Views
11 Replies
Message 1 of 12

Calculating areas of closed Plines of different linetypes

Anonymous
Not applicable

Hi There,

 

I was wondering if it is possible to calculate an area of multiple closed plines that belong to multiple custom linetypes?  I would also like to populate the result into a table.  I am calculating different areas of a room, and want to make this process a standard.  Any help would be greatly appreciated!

0 Likes
Accepted solutions (1)
1,529 Views
11 Replies
Replies (11)
Message 2 of 12

john.uhden
Mentor
Mentor

Are the polylines of differing linetypes on the same layer, or are they on differing layers defined with differing linetypes?

  IOW, does each of the polylines have a linetype that overrides its layer's linetype?

Are the polylines all lightweight?

Are they really closed or just appear to be closed (where the last vertex is drawn at the first vertex)?

Is the list of linetypes always the same, or do you want to type in the linetype names or pick them from a list each time you run the routine?

I presume you want a table that shows the total area per linetype, right?  That could be two rows by many columns or 2 columns by many rows.

John F. Uhden

Message 3 of 12

Anonymous
Not applicable

Hi John! Thank you for responding to my cry for help!

 

The linetypes would just be in one layer, let's say we'll name it "Area_Calc", no specific lineweight on it, just default, and they are closed.  The linetypes however are custom, let's say one linetype is named "area-a" and the other linetype will be "area-b", and the linetype list will always be the same.

 

I would like to use the results to be inserted into an existing table.  Can we use an example of a 3 x 3 table? I would like to insert the number for Area for linetype "area-a" in cell B3, and "area-b" on cell C1.

 

I was looking into using fields, but not too sure how to use it, or even know if fields will be relevant.

0 Likes
Message 4 of 12

ActivistInvestor
Mentor
Mentor
Have you tried using the DATAEXTRACTION command?
0 Likes
Message 5 of 12

Ranjit_Singh
Advisor
Advisor

Hi @Anonymous, try below code. No error check performed. Call the function passing a list of linetype names; like this (somefunc3 '("dashed2" "center2" "center"))

;;; created by Ranjit Singh 03/15/2017
(defun somefunc3  (x / celldir cellpt ind tab tblobj)
 (setq tblobj (car (entsel "\nSelect table Object to edit :")))
 (and (= "ACAD_TABLE" (cdr (assoc 0 (entget tblobj))))
      (setq celldir (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 2)) '(1 1 1)))
            tblobj  (vlax-ename->vla-object tblobj))
      (mapcar '(lambda (x)
                (setq cellpt (vlax-3d-point (getpoint (strcat "\nPick cell in table to add \"" x "\" area :"))))
                (vla-hittest tblobj cellpt celldir 'tab 'ind)
                (vla-settext tblobj tab ind (somefunc33 x)))
              x)))


(defun somefunc33  (x / lst)
 (mapcar '(lambda (x) (setq lst (cons (getpropertyvalue x "Area") lst)))
         (mapcar 'cadr (ssnamex (ssget "_x" (list (cons 0 "*POLYLINE") (cons 6 x) (cons -4 "&") (cons 70 129))))))
 (rtos (apply '+ lst) 2 2))

 

I am still trying to work out the visibility state issue from your last post. I will post more on that in that thread sometime this week, assuming no one provides a solution before that.

Message 6 of 12

john.uhden
Mentor
Mentor

You are SOO good.  It's so much fun watching you rattle off these small works of art.

With what release did 'getpropertyvalue get introduced?  It's not here in 2002.  Though there is vlax-get-property which I think is no different from (vlax-get object 'property)

John F. Uhden

Message 7 of 12

john.uhden
Mentor
Mentor

You are SOO good.  It's so much fun watching you rattle off these small works of art.

With what release did 'getpropertyvalue get introduced?  It's not here in 2002.  Though there is vlax-get-property which I think is no different from (vlax-get object 'property)

 

BTW, I've tried posting 3 times but keep getting an error (which I'm sure is due to my sick laptop).

Anyway, my apologies if my response shows up multiple times.

John F. Uhden

Message 8 of 12

Ranjit_Singh
Advisor
Advisor

Thanks John. This came in 2012 and the idea was to add more LISP power to MAC. See this link. I find it very useful and easy to use 🙂

Message 9 of 12

Anonymous
Not applicable

Hi @Ranjit_Singh! Thank you very much for responding to my cry for help...again! I'm just a beginner with this LISP, trying to learn from the pros.

 

The script is perfect! thank you!  I was wondering if it is possible to incorporate the results into a fixed cell? for example, once I click that table object initially, it would automatically input it in specific coordinates, like, for example, I have two closed plines with two different linetypes, and I want to input one named "area1" into cell A2, and "area2" into cell C1?

 

Also, how do I divide the result automatically by 144, so that it'll come out as square feet?

 

and last (so sorry!) would it be possible to execute the command from the command line, and request the name of the linetype?

 

 

Thank you very much!

 

PS. regarding the dynamic block count with visibility states, I found a lisp created by the great Lee Mac.  However, I've been trying really hard to figure out how it could also calculate each visibility states that does not appear, and give a "0" numeric value.  I am also trying hard to figure out how to input these results into a table.  so, yes, my head is almost about to explode, but I'm learning a lot, thanks to you, this forum, and afralisp.net 🙂

0 Likes
Message 10 of 12

Ranjit_Singh
Advisor
Advisor
Accepted solution

ok try below. It is hard coded to put first line type in cell A2 and second line type in cell C1. I also noticed that in the previous code I had missed catching entities only on layer "Area_Calc". I have fixed it now. But you did not say anything about me missing that, so maybe you don't need entities only on that layer? If so, delete the '(8 . "Area_Calc") portion in somefunc33

;;; created by Ranjit Singh 03/15/2017
(defun c:somefunc3  ( / ctr linenames tblobj)
(setq ctr 1 )
(repeat 2 (setq linenames (cons (getstring t (strcat "\nEnter linetype " (itoa ctr) ": ")) linenames)) (setq ctr (1+ ctr)))
 (setq tblobj (car (entsel "\nSelect table Object to edit :")))
 (and (= "ACAD_TABLE" (cdr (assoc 0 (entget tblobj))))
      (setq    tblobj  (vlax-ename->vla-object tblobj))
      (mapcar '(lambda (x y z)
               (vla-settext tblobj y z (somefunc33 x)))
               (reverse linenames) '(1 0) '(0 2))))


(defun somefunc33  (x / lst)
 (mapcar '(lambda (x) (setq lst (cons (getpropertyvalue x "Area") lst)))
         (mapcar 'cadr (ssnamex (ssget "_x" (list '(0 . "*POLYLINE") (cons 6 x) '(8 . "Area_Calc") '(-4 . "&") '(70 . 129))))))
 (rtos (/ (apply '+ lst) 144.0) 2 2))
Message 11 of 12

Anonymous
Not applicable

Hi Ranjit,

 

first of all, my sincerest apologies for not commenting right away about your response to my questions, I have been away from the internet for a little while.  Second, thank you for this script, I really appreciate it! I like the first script's ability to let me select the cell, but I like how this script lets me change the cell location... I think with this? reverse linenames then the row and column?

(mapcar '(lambda (x y z)
               (vla-settext tblobj y z (somefunc33 x)))
               (reverse linenames) '(1 0) '(0 2)))

Please let me know, I am really green with lisp.  Pretty much in the long run, I would like to somewhat provide a list of area calculations for a list of unique linetypes, and input them into a table with specific cell locations through the line above.

 

Would it be possible for you to describe each lines of the routine? I would just like to learn the process, especially coming from an expert such as yourself.  I use autocad help to search for lisp commands, but it would also definitely be very helpful if I could somehow know your strategy into approaching the request.

 

 

once again, thank you very much!

0 Likes
Message 12 of 12

Ranjit_Singh
Advisor
Advisor

Hi @Anonymous, you are correct. Those are the lines to pick the row and column. The code is pretty self explanatory. Somefunc3 lets you enter linetypes and select the table and calls somefunc33. Somefunc33 uses the linetype names (that is passed by calling function to somefunc33) and gets a selection set of the linetypes and calculates the total area for the entities in selection set and returns it to the calling function, which then feeds the values in the appropriate cells. I don't have a particular strategy. It depends on what the problem is. Mostly all solutions require breaking the request into Autolisp terms: identify input needed, determine steps needed to process data and decide how to output results. As I had mentioned in one of  your last post, anytime you want to understand how a code works, fire-up vlide and debug the code, see how it is evaluated.

 

And of corse, post your questions. Everyone here is eager to help. Good luck.

0 Likes