Jump to content


Lisp to calculate area of a polyline


4 replies to this topic

#1 Gabriele Cespuglio

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 06 May 2013 - 12:46 PM

I writing a lisp to read the area of a selected polyline. I tried to use the "measurearea" command, but I can't select any object. How can I do? Where can i find a lisp editor for Nanocad?

#2 ISL

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 07 May 2013 - 03:46 PM

The following TLEN and TAREA commands work well in nanoCAD: http://www.lee-mac.c...thandarea.html. The wide-spread classic ones that use AREA command do not, as AREA is not implemented yet.

There is no built-in LISP editor in nanoCAD. Notepad++ has syntax highlighting for LISP, maybe you will find it useful.
Build your own nanoCAD. Visit the nanoCAD API Blog. Join the nanoCAD Developers' Club.

#3 Gabriele Cespuglio

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 08 May 2013 - 04:42 PM

Ok, it works! Now I have this problem: i want to insert a text with the polyline area value.
This is my code, but it doesn't work:


(defun c:Area (/ p1 p2 p3 e1 e2 K ar TESTO)

(setq p1 (getpoint "\n Selezionare vertice "))
(setq p2 (getpoint p1 "\n Selezionare vertice "))
(command "_pline" p1 p2 "")
(setq e1 (entlast))
(setq p3 (getpoint p2 "\n Selezionare vertice "))
(command "_pline" p2 p3 "")
(setq e2 (entlast))
(command "_pedit" e1 "_J" e2 "" "")
(setq e1 (entlast))


(setq k 1)

(while k

(setq p2 p3)
(setq p3 (getpoint p2 "\n Selezionare vertice "))

(if (/= p3 nil)
(progn


(command "_pline" p2 p3 "")
(setq e2 (entlast))
(command "_pedit" e1 "_J" e2 "" "")
(setq e1 (entlast))


);progn

);if

(if (= p3 nil) (setq k nil))


);while


(command "_pedit" e1 "_C" "")
(setq ar (vlax-curve-getarea e1))

(setq ptx (getpoint "\n Selezionare punto "))
(setq TESTO (strcat "mq " (rtos ar 2 2)))
(command "_text" ptx "0.2" "0" TESTO)
)
(vl-load-com) (princ)

#4 ISL

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 08 May 2013 - 04:49 PM

Just replace "_text" with "-text" to call command-line version of TEXT command.

nanoCAD currently cannot automatically switch commands into command-line mode.
Build your own nanoCAD. Visit the nanoCAD API Blog. Join the nanoCAD Developers' Club.

#5 Gabriele Cespuglio

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 09 May 2013 - 10:06 AM

Thank you, it works fine.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users