Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/10/2022 in all areas

  1. Just convert them to strings before adding to the list (itoa (for whole numbers) (rtos (for other numbers) 2) (defun C:SSAEXT4 (/ output Mainoutput SS ent P1 P2 P3 P4 P5 P6 P7 P8 P9 P10) ;best to name variables (vl-load-com) (if (setq SS (ssget '((0 . "LWPOLYLINE,LINE,POINT")))) (foreach obj (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq ent (vlax-ename->vla-object obj) P1 (vla-get-Objectname ent) ) (cond ((eq "AcDbPoint" P1) (setq P2 (vlax-get ent 'layer) P3 (itoa(vlax-get ent 'color)) P10 (rtos(caddr (vlax-get ent 'Coordinates))2) output (list P1 P2 P3 "-" "-" "-" "-" "-" "-" P10) ) ;setq ) ;eq ((eq "AcDbLine" P1) (setq P2 (vlax-get ent 'layer) P3 (itoa(vlax-get ent 'color)) P4 (rtos(vlax-get ent 'length)2) P5 (vlax-get ent 'linetype) P6 (rtos(vlax-get ent 'Lineweight)2) P7 (rtos(vlax-get ent 'thickness)2) P8 "0" P9 "VOID" P10 (rtos(caddr (vlax-get ent 'Startpoint))2) ;assumes flat line output (list P1 P2 P3 P4 P5 P6 P7 P8 P9 P10) ) ; setq ) ; eq ((eq "AcDbPolyline" P1) (setq P2 (vlax-get ent 'layer) P3 (itoa(vlax-get ent 'color)) P4 (rtos(vlax-get ent 'length)2) P5 (vlax-get ent 'linetype) P6 (rtos(vlax-get ent 'Lineweight)2) P7 (rtos(vlax-get ent 'thickness)2) P8 (rtos(/ (vlax-get ent 'area) 1000000)2) P9 (rtos(vlax-get ent 'closed)) P10 (rtos(vlax-get ent 'Elevation)2) output (list P1 P2 P3 P4 P5 P6 P7 P8 P9 P10) ) ;setq ) ; eq ) ; cond (setq Mainoutput (cons output Mainoutput)) ) (prompt "/nNothing Selected") ) (if ss (progn (setq file (open (getfiled "Name output file" (getvar "DWGPREFIX") "CSV" 1) "w")) (write-line "Name,Layer,Color,Length-mm,Linetype,Lineweight,Thickness,Area-sqm,Closed,DeltaZ" file) ;;writes the headers to the .CSV (foreach row Mainoutput (write-line (lst2str "," row) file) ) (close file) ) ) (princ) ) ;;----------------------------------------------------------------------------;; ;; Function to convert list to string ;; (lst2str "," lst) (defun lst2str (dlim lst / rtn) (setq rtn (car lst) lst (cdr lst)) (repeat (length lst) (setq rtn (strcat rtn dlim (car lst)) lst (cdr lst) ) ) rtn )
    1 point
  2. @Steven P You can either use condition to avoid evaluating each line of your IFs statements or just use vl-princ-to-string function and this should be enough since you are not controlling the decimals with rtos function within your last reply.
    1 point
  3. Yes you need to convert variables into strings to use them with strcat function. Colour "ByLayer" = 256 as an integer value. Use itoa function to convert from integer to string and use rtos function to convert from real ( decimal ) to string. As soon as you know the type return of your function then it would be very easy to you to know how to deal with it.
    1 point
  4. (defun c:ordercolor ( / *error* sel scolor selcount selnum selname sellist check ) (setvar "cmdecho" 0) (setq sel (ssget '((0 . "*LINE")))) (command "_undo" "_be") (defun *error*(e) (command "_undo" "_e") (princ) ) (setq scolor 0) (setq selcount (sslength sel)) (setq selnum 0) (repeat selcount (setq selname (ssname sel selnum)) (setq sellist (vlax-ename->vla-object selname)) (setq check (vlax-property-available-p sellist "Color" T)) (if check (vlax-put-property sellist 'Color scolor) ) (setq selnum (+ selnum 1)) (setq scolor (+ scolor 1)) (if (> scolor 255) (setq scolor 0)) ) (command "_undo" "_e") );end_defun (defun c:randomcolor ( / *error* sel scolor selcount selnum selname sellist check ) (setvar "cmdecho" 0) (setq sel (ssget '((0 . "*LINE")))) (command "_undo" "_be") (defun *error*(e) (command "_undo" "_e") (princ) ) (setq scolor 0) (setq selcount (sslength sel)) (setq selnum 0) (repeat selcount (setq selname (ssname sel selnum)) (setq sellist (vlax-ename->vla-object selname)) (setq check (vlax-property-available-p sellist "Color" T)) (if check (vlax-put-property sellist 'Color scolor) ) (setq selnum (+ selnum 1)) (setq scolor (LM:randrange 0 255)) ) (command "_undo" "_e") );end_defun ;; Random in Range - Lee Mac ;; Returns a pseudo-random integral number in a given range (inclusive) (defun LM:randrange ( a b ) (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))) ) ;; Rand - Lee Mac ;; PRNG implementing a linear congruential generator with ;; parameters derived from the book 'Numerical Recipes' (defun LM:rand ( / a c m ) (setq m 4294967296.0 a 1664525.0 c 1013904223.0 $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m) ) (/ $xn m) ) RANDOMCOLOR to set random (0 to 255) ORDERCOLOR to set order (0 to 255) it changes according to the order of ssget.
    1 point
  5. Just a random idea if speed is problem maybe look at using lists rather than comparing within selection sets, the list would be a simple ((string pointxyz) then vl-sort so a new list would be made that is the strings in order in the list. (("string1" pointxyz)("string1" pointxyz) ("string2" pointxyz)... I know over at Theswamp there has been a number of posts about manipulating lists into matching sublist using mapcar which is very fast, so maybe the end result is a ((point1 point2 point3)(point4 point5)....the list can be passed to the entmake a pline. If talking micro seconds then why convert XYZ to XY ? if 3d than can do 3dpline.
    1 point
  6. Did you code in lisp before signing up here? because your killing it. With my text find lisp it only does one at a time so the screen doesn't get to cluttered. tho the changing of color is a nice touch. one note is that the dxf code 10 in AutoCAD only shows cords if its left justification. all other justifications the point are in 11, and 10 becomes (0 0 0) or nil. Also look at this post from ronjonp its changed how it search for things. basically builds a list in memory then steps thought them. Use these to dump properties of entity's in cad. ;;----------------------------------------------------------------------------;; ;; Dump all methods and properties for selected objects (defun C:VDumpIt (/ ent) (if (setq SS (ssget)) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (vlax-Dump-Object (vlax-Ename->Vla-Object ent) t) ) ) (textscr) (princ) ) ;;----------------------------------------------------------------------------;; ;; Dump all DXF Group Data (defun c:DumpIt (/ e) (if (setq SS (ssget)) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (mapcar 'print (entget ent '( "*"))) ) ) (textscr) (princ) ) ;;---------------------------
    1 point
  7. No problem, sometimes you can look at a problem too long and you need a fresh of eyes to see what is happening
    1 point
  8. Updated code above: ("Enter name of file to overlay" "InitialDirectory")
    1 point
  9. It has been over 16 years since Autodesk decided to ignore this user request. Best thing I did: abandon autocad and switch to "BIM" (Archicad). It's extremely faster, easier, intuitive and well accepted in the eyes of my customers.
    -1 points
×
×
  • Create New...