Author Topic: Adjust the area of a polygon  (Read 8774 times)

0 Members and 1 Guest are viewing this topic.

vladgothe

  • Mosquito
  • Posts: 9
Re: Adjust the area of a polygon
« Reply #30 on: March 11, 2014, 05:23:15 PM »
Thank you ribarm, I will test the code tomorrow. I think I found the errors in my code and I will update it too. I usually don't write the codes so bad, but I wrote it when I was at work and I had very little time at my disposal.

pedroantonio

  • Guest
Re: Adjust the area of a polygon
« Reply #31 on: March 11, 2014, 06:00:44 PM »
I try it but is not working well ,  i think that scf.lsp is better 

ribarm if you can do this changes

1)select polyline
2)Specify desired Length  and Specify desired area
3)Pick two points to avoid the rotation
4)calculate the polygon

it will be perfect

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 20 Ultimate
Re: Adjust the area of a polygon
« Reply #32 on: March 11, 2014, 06:21:16 PM »
Pedro,

Why don't you attempt to make some adjustments on your own, you seem to be quite capable of spotting issues with the code.  It will show the other members here that you are at least willing to try.  Who knows maybe you will learn something in the process or at least gain a greater respect for those willing to share their knowledge.

Bruce

ribarm

  • Gator
  • Posts: 2519
  • Marko Ribar, architect
Re: Adjust the area of a polygon
« Reply #33 on: March 12, 2014, 05:24:43 PM »
For improved accuracy... Test this code :

M.R.

[EDIT : Found some mistake in amount of stretching when multiple points are selected - Tested on square and picked 2 side points to make rectangle - now distances of stretched sides of rectangle are the same - that wasn't the case, that's why I said to test the code... It was total of 2 downloads till I reattached file...]

Hope this is now all OK...
« Last Edit: March 13, 2014, 07:31:09 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 2519
  • Marko Ribar, architect
Re: Adjust the area of a polygon
« Reply #34 on: March 13, 2014, 06:17:45 AM »
Reattached ms.lsp - there was little mistake when multiple points are to be stretched...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: Adjust the area of a polygon
« Reply #35 on: March 13, 2014, 06:26:36 AM »
when i run this lisp my autocad dont respond . why ? Can you give some instractions?
« Last Edit: March 13, 2014, 06:31:58 AM by Topographer »

ribarm

  • Gator
  • Posts: 2519
  • Marko Ribar, architect
Re: Adjust the area of a polygon
« Reply #36 on: March 13, 2014, 07:35:05 AM »
Topographer, there was one more mistake I made while copying pieces of codes... Now is all OK; Redownload file attached now... And for instructions just follow prompts CAD asks you and be sure to pick initial vector that would be smaller for imaginary stretch than desired area (pick small vector in any case - 2 near points)...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: Adjust the area of a polygon
« Reply #37 on: March 13, 2014, 07:47:20 AM »
I try again and my autocad crash again . I dont know

vladgothe

  • Mosquito
  • Posts: 9
Re: Adjust the area of a polygon
« Reply #38 on: March 13, 2014, 10:06:23 AM »
Marko, AutoCAD 2007 gives an error message: INTERNAL ERROR CMD UNDO 2 every time I run the lisp, then crashes. What could the problem be?
I started working on a new routine, but unfortunately I have very much work to do and I don't have time to finish it now. Maybe someone can help?
Here is the start of the routine:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ms (/ obj arieinitiala arieobj ariedor lista lista2)
  2. (setvar "CMDECHO" 0)
  3. (setq os_old (getvar "OSMODE"))
  4. (setvar "OSMODE" 1)
  5. (setq lista '())
  6. (setq lista2 '())
  7. (setq obj (car (entsel "\nSelect a closed polyline: ")))
  8. (while (not obj)
  9. (setq obj (car (entsel "\nSelect a closed polyline: ")))
  10. )
  11. (while (not (wcmatch (cdr (assoc 0 (entget obj))) "*POLYLINE"))
  12. (alert "The selected object is not a polyline!")
  13. (setq obj (car (entsel "\nSelect a closed polyline: ")))
  14. (while (not obj)
  15. (setq obj (car (entsel "\nSelect a closed polyline: ")))
  16. )
  17. )
  18. (setq pl (vlax-ename->vla-object obj))
  19. (if (zerop (cdr (assoc 70 (entget obj))))
  20. (vla-put-closed pl :vlax-true)
  21. )
  22. ;;we make the list with polyline vertices
  23. (foreach x (setq e (entget obj))
  24.         (if (= 10 (car x)) (setq l (cons (cdr x) l)))
  25.     )  
  26. (setq arieinitiala (vla-get-Area pl))
  27. (setq ariedor (getreal (strcat "\nWrite the area you want to achieve <" (rtos arieinitiala 2 0) " sq meters> ")))
  28. ;;daca aria dorita este egala cu aria initiala
  29. (if (= (rtos ariedor 2 0) (rtos arieinitiala 2 0))
  30. (alert "\nThe selected area is equal with polyline area!")
  31. (setq pt (getpoint "\nSelect the vertex you want to be stretched: "))
  32. (setq xpt (car pt))
  33. (setq ypt (cadr pt))
  34. (if (not (member (list xpt ypt) l))
  35. (alert "\nThe selected point must be a vertex on polyline!")
  36. (setq lista (append (list (list xpt ypt)) lista))
  37. (setq dir (getpoint "\nChoose the direction you want to stretch the vertex: "))
  38. (setq xdir (car dir))
  39. (setq ydir (cadr dir))
  40. (setq lista2 (append (list (list xdir ydir)) lista2))
  41. )
  42. )
  43. )
  44. (setq lista (reverse lista))
  45. (setq lista2 (reverse lista2))
  46. (setq lista (LI_MakeUnique lista))
  47. (setq lista2 (LI_MakeUnique lista2))
  48. (setq arieobj arieinitiala)
  49. (setq cont 0)
  50. (setq offset 0)
  51. ;;here goes the code to verify area and stretch every vertex on selected directions
  52. ;;.................
  53. ;;..................
  54. )
  55. )
  56. (setvar "OSMODE" os_old)
  57. )
  58.  
  59. (defun LI_MakeUnique( Lst / Lst1 tmp )
  60.  
  61. (setq Lst1 '())
  62. (foreach tmp Lst
  63.         (if (not (member tmp Lst1))
  64.                 (setq Lst1 (cons tmp Lst1))
  65.         )
  66. )
  67. (reverse Lst1)
  68. )
  69.  
  70.  

ribarm

  • Gator
  • Posts: 2519
  • Marko Ribar, architect
Re: Adjust the area of a polygon
« Reply #39 on: March 13, 2014, 10:31:18 AM »
vladgothe and Topographer,

It seems that you don't have luck with version of ACAD... I've tested on my machines and the oldest version I am using is A2008 on 32 bit system, and it works fine... Guess, you both should update your hardware and software... The newest version of ACAD can be found on www and it's A2014... Just remember that during installation avoid to download service pack, for you won't be able to activate it correctly...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: Adjust the area of a polygon
« Reply #40 on: March 13, 2014, 10:41:03 AM »
i use Autocad 2012  64 bit and this lisp crash ... it starts  but  after few seconds autocad not respond

ribarm

  • Gator
  • Posts: 2519
  • Marko Ribar, architect
Re: Adjust the area of a polygon
« Reply #41 on: March 13, 2014, 11:07:01 AM »
You are driving me nuts... I've tested the code once again on A2014 and A2012 64 bit and it's working fine... Can someone else confirm that I am not laying... It's impossible that only my ACAD's work fine... Topographer, as I said - pick closed polyline; enter desired area; pick vertices on polyline - be careful to pick only vertices (osnap will be automatically turned on to END snap) and when done right click with mouse or ENTER; pick small vector in direction you want stretch to be processed - 2 near points (must be small vector)... And that's it - you have to be patient to be sure routine finish... No crashes on my computers and no endless loops - it finishes correctly...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: Adjust the area of a polygon
« Reply #42 on: March 13, 2014, 11:16:00 AM »
ribarm can you upload a gif to see the steps. Maybe i do something wrong.

Thanks

ribarm

  • Gator
  • Posts: 2519
  • Marko Ribar, architect
Re: Adjust the area of a polygon
« Reply #43 on: March 13, 2014, 11:30:11 AM »
Here is the MS.gif
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: Adjust the area of a polygon
« Reply #44 on: March 13, 2014, 12:08:59 PM »
Now some some times work. Perhaps it's my fault .

thank you ribarm