Jump to content

How can I calculate area by lisp?


Rain0923

Recommended Posts

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • Rain0923

    14

  • pBe

    9

  • neophoible

    5

  • Alex-77

    1

Top Posters In This Topic

Posted Images

2. total red pline area / black pline area

 

Total RED area value divided by BLACK area value? ---> 0.238058 ?? or the other way around? 4.20066 ??

 

(defun c:demo ( / _total ss ssd TareaRed TareaBlack ComputedArea)
(defun _total (sel / Value)
     (repeat (setq i (sslength sel))
                      (setq Value (cons (vlax-curve-getarea (ssname sel (setq i (1- i)))) Value)))
     (apply '+ Value)
     )
(defun _Rtos (v)(rtos v 2 2))      
     
     
      (if (and  (princ "\nSelect RED pline(s)")
                (setq ss (ssget '((0 . "LWPOLYLINE"))))
                (princ "\nSelect Black pline")
                (setq ssD (ssget '((0 . "LWPOLYLINE"))))
                )
          (progn
                (setq TareaRed (_total ss))
                (setq TareaBlack (_total ssd))
                (setq ComputedArea ( / TareaRed TareaBlack))
                (alert (strcat "\nTotal area for RED pline(s): " (_rtos TareaRed )
                "\nTotal area for BLACK pline(s): " (_rtos TareaBlack )
                "\nTotal RED divided by BLACK: " (_rtos ComputedArea)
                "\nPercentage: "  (_rtos (* 100.00  ComputedArea)) "%"))
                )
          )
      (princ)
      )
      

Edited by pBe
Link to comment
Share on other sites

Thanks

0.238058 is right.

This lisp is good but the layer is not in CSM then it can't use.

Can it change not lock any layer name or color?

 

 

Total RED area value divided by BLACK area value? ---> 0.238058 ?? or the other way around? 4.20066 ??

 

(defun c:demo ( / RED ss s TArea RED_TOTAL BLACK)
      (if (and  (princ "\nSelect RED pline(s)")
                (setq  RED nil ss (ssget '((0 . "LWPOLYLINE")(8 . "CSM"))))
                (princ "\nSelect Black pline")
                (setq s (ssget "_:S" '((0 . "LWPOLYLINE"))))
                )
          (progn
                (repeat (setq i (sslength ss))
                      (setq RED (cons (vlax-curve-getarea (ssname ss (setq i (1- i)))) RED)))
        (setq TArea (/ (setq RED_TOTAL (apply '+ RED))
                               (setq BLACK (vlax-curve-getarea (ssname s 0)))))
                (princ (strcat "\nTotal area for RED pline(s): " (rtos RED_TOTAL 2 2)))
                (princ (strcat "\nBlack Pline area: " (rtos BLACK 2 2)))
                (princ (strcat "\nTotal RED divided by BLACK: " (rtos TArea 2 2)))
                )
          )
      (princ)
      )

Link to comment
Share on other sites

But of course, just remove (8 . "CSM") from the code. What other conditions to you need to add? Is the divisor always one entity?

Link to comment
Share on other sites

Great!!It can use now.

Is any probably show percentage?

No, the divisor is not always one entity.Can it update?

Thanks:)

 

But of course, just remove (8 . "CSM") from the code. What other conditions to you need to add? Is the divisor always one entity?
Link to comment
Share on other sites

Is any probably show percentage?

 

How do you get the percentage Rain0923? Show me so there would be no confusion

 

No, the divisor is not always one entity.Can it update?

Thanks:)

 

Yes

Link to comment
Share on other sites

It like show 0.238058 and 23.81%...

Thanks

 

How do you get the percentage Rain0923? Show me so there would be no confusion

 

 

 

Yes

Link to comment
Share on other sites

Can it do like in the attachment?

 

YES, but are you aware you can do the ADD/Subtract using the native area command?

 

We can go back and forth on this, so take a deep breath write down ALL the conditions, sample drawings, results and all. Then post it here.

 

You should have done all that from the get-go Rain0923. :)

Link to comment
Share on other sites

Yes,sorry bother you again.My English is not good so sometimes I don't know how to explain my question.Sorry again.....

This is another demand. I want separate to two lisp.

1.You give to me already.

2.So.......ask you this question just now.

and I clearly condition more in the attachment.Please

(still need all area answers and percentage)

 

 

YES, but are you aware you can do the ADD/Subtract using the native area command?

 

We can go back and forth on this, so take a deep breath write down ALL the conditions, sample drawings, results and all. Then post it here.

 

You should have done all that from the get-go Rain0923. :)

teat2.dwg

Link to comment
Share on other sites

This is another demand...

2.So.......ask you this question just now.

and I clearly condition more in the attachment.Please

(still need all area answers and percentage)

 

I will look into this, cant seem to wrap my head on how to go about the selection. its definitively doable.

 

EDIT: show us an example where there are two or more green area for divisor.

Edited by pBe
Link to comment
Share on other sites

Please have the file, I add divisor in the file.Thanks:oops:

 

I will look into this, cant seem to wrap my head on how to go about the selection. its definitively doable.

 

EDIT: show us an example where there are two or more green area for divisor.

teat3.dwg

Link to comment
Share on other sites

Please have the file, I add divisor in the file.Thanks:oops:

 

Still thinking of the best way to select the objects. IMO test3.dwg does not represent the whole picture. We need a real world drawing sample Rain0923

 

One question:

Layers.... It would be loads easier for selection if the objects are set to a specific layer but then again maybe not.

 

We can do pairs then toggle between two boundaries to identify which one is to be subtracted. or even prompt selection with Subtract / ADD /Divide mode, much like the native Area command only more user friendly [ maybe :unsure: havent really used Area command myself ]

Link to comment
Share on other sites

pBe, actually, you could use the AREA command in the routine and retrieve the result using (getvar "AREA"), but I doubt that's your preference.

 

razara, it would be best if you show the output you are expecting for the sample drawing you have provided. Type it in just the way you want it to show.

Are you always selecting in pairs, except for the boundary divisors? Can you have more than two divisors?

Why not just explain what you are actually trying to accomplish with these calculations?

Link to comment
Share on other sites

-->The objects are not set to a specific layer.

-->You are right that is really more friendly.

Maybe we can let question more sample that like calculating machine

with Subtract / ADD /Divide mode they can use selection by user.8)

lisp can do?

Thanks

 

Still thinking of the best way to select the objects. IMO test3.dwg does not represent the whole picture. We need a real world drawing sample Rain0923

 

One question:

Layers.... It would be loads easier for selection if the objects are set to a specific layer but then again maybe not.

 

We can do pairs then toggle between two boundaries to identify which one is to be subtracted. or even prompt selection with Subtract / ADD /Divide mode, much like the native Area command only more user friendly [ maybe :unsure: havent really used Area command myself ]

Link to comment
Share on other sites

pBe, actually, you could use the AREA command in the routine and retrieve the result using (getvar "AREA"), but I doubt that's your preference.

 

That is correct neophoible, but might as well use the AREA command itself outside the routine for ADD/SUBTRACT and then run a short code for divide using (getvar 'area) [as you suggested] as an argument.

 

Maybe we can let question more sample that like calculating machine

with Subtract / ADD /Divide mode they can use selection by user.8)

lisp can do?

Thanks

 

Your maybe onto something there Rain0923.

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...