AllExperts > AutoCAD 
Search      
AutoCAD
Volunteer
Answers to thousands of questions
 Home · More AutoCAD Questions · Answer Library  · Encyclopedia ·
More AutoCAD Answers
Question Library

Ask a question about AutoCAD
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Scott Cook
Expertise
I`ve been using AutoCAD since 1987 and programming AutoLISP nearly as long. I can answer questions about programming AutoCAD (except ARX) and production enhancement techniques. I cannot answer questions about AutoCAD crashes or DWG corruption. AutoCAD PROGRAMMING (menus, lisp) related questions only!

Experience
Since 1987. Author of Plot2000 software for for AutoCAD, http://www.plot2000.com. PROGRAMMING QUESTIONS ONLY PLEASE. Questions that are NOT related to programming or AutoCAD customization (menus and lisp only please) are outside the scope of my volunteer services and will NOT BE ANSWERED.
 
   

You are here:  Experts > Computing/Technology > Computer-Aided Design > AutoCAD > PolyCen(ter) lisp question

AutoCAD - PolyCen(ter) lisp question


Expert: Scott Cook - 9/18/2007

Question
Hello; I am not a Lisp programmer. I found this lisp program on the internet a few years back, and used it in AutoCAD 2000 without a problem. Now we have converted to AutoCAD 2006 and I can't use this; I get an error message:

Command: _appload PolyCen.lsp successfully loaded.
Command: ; error: malformed string on input

This is the program:
***********************
;;; A new osnap \'PolyCen\'. Code by SanganakSakha 10/02/02
;;; No comprehensive data validation or error-checking done
;;; Finds the \'center\' of a regular polygon by clicking it.
;;; Works only with polygons drawn using \'Polygon\' command.
;;; May give erroneous results if user does not select
;;; a polygon.
;;; Can be used transparently and hence as a osnap.

(defun c:PolyCen ()
(setq prmpt \"Select a regular polygon\")
(if (= (getvar \"cmdnames\") \"\")
(setq prmpt (strcat \"n\" prmpt \": \"))
(setq prmpt (strcat \" of (\" prmpt \") \"))
) ;_ end of if
(setq p (entget (car (entsel prmpt))))
(setq sides (cdr (assoc 90 p)))
(setq pt1 (cdr (setq l1 (assoc 10 p))))
(setq mp (cdr (member l1 p)))
(if (= (* 2 (/ sides 2)) sides)
(progn ; even
(repeat (/ sides 2)
(setq mp (cdr (member (setq l1 (assoc 10 mp)) mp)))
) ;_ end of repeat
(setq pt2 (cdr l1))
(setq cen (list (/ (+ (car pt1) (car pt2)) 2)
(/ (+ (cadr pt1) (cadr pt2)) 2)
) ;_ end of list
) ;_ end of setq
) ;_ end of progn
(progn ; odd
(setq pt2 (cdr (setq l1 (assoc 10 mp))))
(repeat (/ sides 2)
(setq mp (cdr (member (setq l1 (assoc 10 mp)) mp)))
) ;_ end of repeat
(setq pt3 (cdr l1))
(setq mp (cdr (member (setq l1 (assoc 10 mp)) mp)))
(setq pt4 (cdr l1))
(setq mp (cdr (member (setq l1 (assoc 10 mp)) mp)))
(setq pt5 (cdr l1))
(setq mp (cdr (member (setq l1 (assoc 10 mp)) mp)))
(setq cen (inters pt1
(list (/ (+ (car pt3) (car pt4)) 2)
(/ (+ (cadr pt3) (cadr pt4)) 2)
) ;_ end of list
pt2
(list (/ (+ (car pt5) (car pt4)) 2)
(/ (+ (cadr pt5) (cadr pt4)) 2)
) ;_ end of list
) ;_ end of inters
) ;_ end of setq
) ;_ end of progn
) ;_ end of if
) ;_ end of defun
(defun c:pCen ()
(c:PolyCen)
) ;_ end of defun
(setq msg \"Finds the \'center\' of a regular polygon by clicking it.\")
(setq msg
(strcat msg
\"nnWorks only with polygons drawn using \'Polygon\' command.\"
) ;_ end of strcat
) ;_ end of strcat
(setq msg
(strcat msg
\"nMay give erroneous results if the user does not select\"
;;;\"
) ;_ end of strcat
) ;_ end of strcat
(setq msg
(strcat msg
\" a regular polygon drawn using the \'Polygon\' command.\"
) ;_ end of strcat
) ;_ end of strcat
(setq msg
(strcat msg
\"nnCan be used transparently and hence as an osnap.\"
) ;_ end of strcat
) ;_ end of setq
;;;
(setq msg
(strcat msg
\"nnType PolyCen or PCEN at the Command prompt to execute.\"
) ;_ end of strcat
) ;_ end of setq
(setq msg
(strcat msg
\"nType \'PolyCen or \'PCEN when using transparently. \"
) ;_ end of strcat
) ;_ end of setq
(alert msg)


************************************
I submitted this to someone else; and their reply was:
"The backslash ahead of the quotes is not required throughout the routine, it is only required ahead of special characters you wish to escape inside the strings. start by getting rid of those, leave them in front of things inside the strings."

I tried to follow these rules but I am getting nowhere as I don't know lisp programming.
Can you help me?
Thanks,
David.


Answer
someone asked me the same question before (was it you?). the answer is the same. get rid of the backslashes at the start and end of the strings (the stuff in double quotes). also get rid of the single quotes inside the strings. the only place you need the backslash is in front of the newline character, \n

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.