Can anyone please help translate this code for Intellicad?

Topics relating to AutoLisp and SDS.

Moderators: CMS Inc, avaernes

Danielm103
Valued Contributor
Posts: 54
Joined: Mon Aug 07, 2006 11:01 pm
Location: Albuquerque,NM,USA

Post by Danielm103 » Thu Oct 04, 2007 11:36 pm

You could do “all” but you might pickup unwanted items. Else you could just add the names to the selection set

i.e

Code: Select all

(defun c:pexpxl (/ en fil fname)
 (setq fname (getfiled "Select Excell file" "" "xls" 1))
 (setq fil (open fname "w"))
 (write-line "Object\tPerimeter" fil)
 (foreach en (pxl:getlength)
  (write-line (strcat (car en) "\t" (rtos (cdr en) 2 12)) fil)
 )
 (close fil)
 (princ "\ndone")
 (princ)
)
(defun pxl:getlength ( / c elist ename retlist s)
 (setq retlist '())
 (setq s (ssget '((0 . "CIRCLE,*POLYLINE,ELLIPSE,REGION,SPLINE,LINE,ARC"))))
 (setvar "CMDECHO" 0)
 (if s
  (progn
   (setq c 0)
   (while (< c (sslength s))
    (setq elist (entget (ssname s c))
	  ename (cdr (assoc 0 elist))
    )
    (command "_AREA" "_Object" (cdr (car elist)))
    (setq retlist (cons (cons ename (getvar "PERIMETER")) retlist))
    (setq c (1+ c))
   )
  )
 )
 retlist
)
beyond
Contributor
Posts: 11
Joined: Mon Oct 01, 2007 10:53 pm

Post by beyond » Fri Oct 05, 2007 2:57 am

Thanks Danielm103,

I added arc and line which worked good, how do I write the file out with all selected automatically without selscting from the menu?

I also want to include in the output a count of shapes, for instance in the attached sample the number of shapes would be 14

http://www.divshare.com/download/2222051-d92
beyond
Contributor
Posts: 11
Joined: Mon Oct 01, 2007 10:53 pm

Post by beyond » Sun Oct 07, 2007 7:03 am

I got this 'latest' code but it does not count shapes (as in previous post) or write direct to the file, any help please?

(defun C:PEXPXL ( / ss lst fname fil sel2lst dst ed)
(defun sel2lst ( sel / l len )
(if (= 'PICKSET (type sel))
(repeat (setq len (sslength sel))
(setq len (1- len)
l (cons (ssname sel len) l)
) ;setq
) ;repeat
) ;if
)
(setvar "CMDECHO" 0)
(princ "\nSelect Circle,Polyline,Ellipse,Spline,Line,Arc or Region")
(if
(and
(setq ss (ssget '((0 . "CIRCLE,*POLYLINE,ELLIPSE,REGION,SPLINE,LINE,ARC"))))
(setq lst (sel2lst ss))
(setq fname (getfiled "Select Excell file" "" "xls" 1))
)
(progn
(setq fil (open fname "w"))
(write-line "Object\tPerimeter" fil)
(foreach en lst
(cond ((= (cdr(assoc 0 (setq ed (entget en)))) "LINE")
(command "_LENGTHEN" en "")
)
((= (cdr(assoc 0 ed)) "ARC")(command "_LENGTHEN" en ""))
(t(command "_AREA" "_Object" en))
)
(command)(command)(setq dst (getvar "PERIMETER"))
(write-line (strcat (cdr(assoc 0 ed))"\t" (rtos dst 2 12)) fil)
)
(close fil)
(princ "\nPerimeter of ")(princ (length lst))
(princ " object export to ")(princ fname)
)
)
(princ)
)
(princ "\nType PEXPXL to run")
Danielm103
Valued Contributor
Posts: 54
Joined: Mon Aug 07, 2006 11:01 pm
Location: Albuquerque,NM,USA

Post by Danielm103 » Sun Oct 07, 2007 9:26 am

Beyond,

I really don’t follow what you consider a “shape”, there are 51 separate entities in the DXF you posted. Most are Arcs and lines. To get the count of the entities, just use your len variable

Dan
beyond
Contributor
Posts: 11
Joined: Mon Oct 01, 2007 10:53 pm

Post by beyond » Sun Oct 07, 2007 3:40 pm

Danielm103 wrote:Beyond,

I really don’t follow what you consider a “shape”, there are 51 separate entities in the DXF you posted. Most are Arcs and lines. To get the count of the entities, just use your len variable

Dan
I called them shapes because I did not know how else to describe them, it is actually 'pierce points I am after for a laser to cut out the profile in the dxf supplied it would be one for the outer profile and one each for the holes total of 14.

I don't know if that is even possible in Intellicad since the outer profile is made up of lines?

If it is possible how ould I add it to the code, someone has given me the auto write to xls below if I could get teh pierce point I would be complete.

(defun C:PEXPXL ( / ss lst fname fil sel2lst)
(defun sel2lst ( sel / l len )
(if (= 'PICKSET (type sel))
(repeat (setq len (sslength sel))
(setq len (1- len)
l (cons (ssname sel len) l)
) ;setq
) ;repeat
) ;if
)
(setvar "CMDECHO" 0)
(princ "\nSelect Circle,Polyline,Ellipse,Spline or Region")
(if
(and
(setq ss (ssget '((0 . "CIRCLE,*POLYLINE,ELLIPSE,REGION,SPLINE"))))
(setq lst (sel2lst ss))
(setq fname (getfiled "Select Excell file" "" "xls" 1))
)
(progn
(setq fil (open fname "w"))
(write-line "Object\tPerimeter" fil)
(foreach en lst
(command "_AREA" "_Object" en)
(write-line (strcat (cdr(assoc 0 (entget en)))"\t" (rtos (getvar "PERIMETER") 2 12)) fil)
)
(close fil)
(princ "\nPerimeter of ")(princ (length lst))
(princ " object export to ")(princ fname)
)
)
(princ)
)
(princ "\nType PEXPXL to run")
Danielm103
Valued Contributor
Posts: 54
Joined: Mon Aug 07, 2006 11:01 pm
Location: Albuquerque,NM,USA

Post by Danielm103 » Sun Oct 07, 2007 10:47 pm

Right, because even your circles are Arcs, so you would get two pierce points for each hole. The way I see it is, you need to define what entities are a shape by either marking each entity with XData or by having each entity belong to a collection (A Group , or Block). Since your laser cutter is probably reading the DXF for it’s translation to G-code, blocks probably won’t work for you. But before you design your program, I would consider trying each of the methods on your machine. I would assume that your cutter would ignore the XData and Group DXF code, so one of these two might be your best bet.

Another option I just thought of, would be to convert the Entities to polylines and join them using the PEDIT command.

Dan
Post Reply