Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 1 of 8 (394 Views)
Accepted Solution

What is the problem with the entmake in this?

394 Views, 7 Replies
10-10-2012 11:32 PM

Hi,

Just learning a bit of Autolisp but I can't work out why this entmake doesn't work. The error says it is a bad DXF group: (0.0 "CIRCLE") which I assume means that the 0.0 is a real number instead of an integer. But why has it taken it in as a real number?

It is just a quick program to change a group of points into circles with a radius from two selected points.

Here is my code:

 

;Function for replacing points with circles of a given radius
(defun c:smileytongue:2c()
  (setq radpt1 (getpoint "\nKlick första punkten: "))
  (setq radpt2 (getpoint "\nKlick andra punkten: "))
  (setq diffx (- (car radpt1) (car radpt2)))
  (setq diffy (- (cadr radpt1) (cadr radpt2)))
  (setq radius (sqrt (+ (expt diffx 2) (expt diffy 2))))
  (princ (strcat "\n" (rtos radius)))

  (if (setq pointset(ssget (list (Cons 0 "POINT")))) ;get set of points
    (progn
      (setq cntr 0) ;set counter to first item in set
      (while (< cntr (sslength pointset)) ;while counter is less than the length of the set
    (setq item(ssname pointset cntr)) ;get entity name of the item indexed
    (setq itemcodes(entget item)) ;get items group codes
;    (entdel item) ;delete point
    (setq cpnt (assoc 10 itemcodes)) ;get center point of item
    (entmake (append '((0."CIRCLE")(100."AcDbEntity")(8."0")(100."AcDbCircle"))
             (list cpnt)
             (list (cons 40 radius))
             '((210 0.0 0.0 1.0))
             ) ;end append
         );end entmake
    (setq cntr (+ cntr 1)) ;increment counter
    ) ;close while
;      (princ (strcat "\nCircles changed: " (itoa cntr))) ;print the number of circles after new line
      ) ;close progn
    (alert "No points selected")
    ) ;close if
  (princ)
  ) ;close defun

 

Thanks for your critic and help.

Ozitag.

IV 2010
(entmake (append '((0 . "CIRCLE")
(100 . "AcDbEntity")
(8 . "0")
(100 . "AcDbCircle")
)
(list cpnt)
(list (cons 40 radius))
'((210 0.0 0.0 1.0))
) ;end append
)

 

See the diffrerence? 

 

((0. "CIRCLE")<--- no space between 0 and .  hence the error
(100. "AcDbEntity")
(8. "0")
(100. "AcDbCircle")
)

 

 

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 2 of 8 (386 Views)

Re: What is the problem with the entmake in this?

10-11-2012 12:39 AM in reply to: ozitag
(entmake (append '((0 . "CIRCLE")
		       (100 . "AcDbEntity")
		       (8 . "0")
		       (100 . "AcDbCircle")
		      )
		     (list cpnt)
		     (list (cons 40 radius))
		     '((210 0.0 0.0 1.0))
	     )				;end append
    )

 

See the diffrerence? 

 

((0. "CIRCLE")<--- no space between 0 and .  hence the error
(100. "AcDbEntity")
(8. "0")
(100. "AcDbCircle")
)

 

 

Distinguished Mentor
_Tharwat
Posts: 627
Registered: ‎07-02-2010
Message 3 of 8 (385 Views)

Re: What is the problem with the entmake in this?

10-11-2012 12:40 AM in reply to: ozitag

In regard to your question with entmake , you should keep space between the code that feed the entmake function

 

'((0."CIRCLE")(100."AcDbEntity")(8."0")(100."AcDbCircle"))

 

Like this

'((0 . "CIRCLE")(100 . "AcDbEntity")(8 . "0")(100 . "AcDbCircle"))

 

Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 4 of 8 (370 Views)

Re: What is the problem with the entmake in this?

10-11-2012 01:10 AM in reply to: pbejse

Thanks guys.

Hopefully I'll remember this.

Regards,

Ozitag

IV 2010
*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 5 of 8 (357 Views)

Re: What is the problem with the entmake in this?

10-11-2012 02:26 AM in reply to: ozitag

ozitag wrote:

Thanks guys.

Hopefully I'll remember this.

Regards,

Ozitag


Good for you, I see that you have taken the entmake route this time. That is good.

 

BTW:

(setq diffx (- (car radpt1) (car radpt2)))
(setq diffy (- (cadr radpt1) (cadr radpt2)))
(setq radius (sqrt (+ (expt diffx 2) (expt diffy 2))))

 

and this

(distance radpt1 radpt2)

 

Will give you the same result.

 

Might as well use getdist  wherein you can input a value or pick two points for radius

 

(setq radius (getdist "\Enter Radius value/Pick two points: "))

 

HTH

 

Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 6 of 8 (353 Views)

Re: What is the problem with the entmake in this?

10-11-2012 03:25 AM in reply to: pbejse

Great, thanks for the tip. It would be great to know all the functions huh :smileyvery-happy:

IV 2010
Distinguished Contributor
wkiernan
Posts: 150
Registered: ‎12-08-2003
Message 7 of 8 (324 Views)

Re: What is the problem with the entmake in this?

10-14-2012 10:20 AM in reply to: pbejse

Only if they have the same Z value.  If the Z value differs then (distance radpt1 radpt2) will be larger than the value those three lines of code assign to the "radius" variable.  As surveyor's measurements between coordinate pairs are generally not the 3D distance but the distance between the 2D projections, this came up so often in my programs that I have a subroutine called 2ddist which does the same thing

 

; 2DDIST(POINT1 POINT2), given two 3D (or 2D) points, returns the 2D distance
; between them.  Note that if either arg to DISTANCE is 2D, Z coord of other
; arg is ignored;

(defun-q 2ddist (point1 point2)
 (distance (2dvect point1) point2)
)

; 2DVECT(POINT), given 3D vector POINT = (X Y Z) returns a 2D point (X Y)

(defun-q 2dvect(point)
 (if point
  (list (car point)(cadr point))
 )
)

 

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 8 of 8 (312 Views)

Re: What is the problem with the entmake in this?

10-14-2012 07:50 PM in reply to: wkiernan

wkiernan wrote:

Only if they have the same Z value.  If the Z value differs then (distance radpt1 radpt2) will be larger than the value those three lines of code assign to the "radius" variable.  As surveyor's measurements between coordinate pairs are generally not the 3D distance but the distance between the 2D projections, this came up so often in my programs that I have a subroutine called 2ddist which does the same thing

 

 


wouldnt be easier if

(setvar 'osnapz 1 ) <------- set value to 1  prior to picking the points  :smileyhappy:

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!