Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/14/2023 in all areas

  1. Here is one way to use grdraw function to create temporary rubber band. (defun c:Test (/ ins lst tmp len) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (while (setq ins (getpoint "\nSpeicy point : ")) (setq len (* 0.5 (/ (getvar "VIEWSIZE") 10))) (foreach pt (setq lst (cons ins lst)) (setq tmp (* pi 0.25)) (grdraw (polar pt tmp len) (polar pt (setq tmp (+ pi tmp)) len) 1 0 ) (grdraw (polar pt (setq tmp (* (* pi 0.25) 3.0)) len) (polar pt (setq tmp (+ pi tmp)) len) 1 0 ) ) ) (redraw) (princ) )
    1 point
  2. The thing is called "quickmeasure"... Here is the link : https://www.cadtutor.net/forum/topic/73952-room-info-table-measure-length-from-objects-to-roomcorner-delta-xdelta-y-and-write-into/#comment-586021 HTH. M.R.
    1 point
  3. The way of randomly selecting a paver can be improved. I should do a weighed randomizer. So the user can select whether they want more or fewer big pavers as opposed to the smaller ones.
    1 point
  4. Nice, I was thinking something similar to fill in the drive - mine above only worked for the edges which was easy enough. Random place a rectangle and check it fits. My thought was to start with the largest paver, place a random number of them, then the next sizes down to the smallest size - which might have worked to change the proportions of pavers - repeat a loop place say 1 largest, 2 next size and 3 next to smallest then repeat ?
    1 point
  5. I made something. A few remarks: - For my ease I made it 1 unit = 1 smallest paver. So I ignored the 8" size. You can always scale the result by 8 at the end. - The driveway starts at 0,0 . Then you pick a second point (both X and Y must be positive). Start small. (x=10, y=25 for example) - The algorithm will pick a random point, then a random pavers size (we skip the smallest paver), and a random orientation (horizontal or vertical) If there's room for that paver there, then it's drawn there. Else skip. This is done 3000 times (you can change this number) - At the end the smallest paver fills all the rest at the end command PAVER The script needs some cleanup; I just got it working. I might edit the script to clean it up. TODO. It might be nice to put a factor in the pavers, so that big pavers are randomly selected more or less often than small ones. You can add pavers sizes to the pavers_size list. Make sure the first size is 1,1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DRAW (defun drawLWPoly (lst cls) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)) (mapcar (function (lambda (p) (cons 10 p))) lst))) ) (defun drawLWPoly_color (lst cls col) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 62 col) (cons 70 cls)) (mapcar (function (lambda (p) (cons 10 p))) lst))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ROUNDING ;; http://www.lee-mac.com/round.html ;; Round Multiple - Lee Mac ;; Rounds 'n' to the nearest multiple of 'm' (defun LM:roundm ( n m ) (* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5))) ) ;; Round Up - Lee Mac ;; Rounds 'n' up to the nearest 'm' (defun LM:roundup ( n m ) ((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r)) ((+ n (- m r))))) (rem n m)) ) ;; Round Down - Lee Mac ;; Rounds 'n' down to the nearest 'm' (defun LM:rounddown ( n m ) ((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r m)) ((- n r)))) (rem n m)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; RANDOM number generator ;; http://www.lee-mac.com/random.html ;; 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) ) ;; 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)))))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Replace item in list (defun replace-element (index newelement lst) (subst newelement (nth index lst) lst) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; XY coordinates to array index ;; vice versa is just (nth index pavers) (defun yx2index ( x y pavers / res i) ;;(setq x_ (rem x w)) ;;(setq y_ (LM:rounddown (/ ind w) 1.0)) (setq i 0) (foreach cel pavers (if (and (= x (nth 0 cel)) (= y (nth 1 cel)) ) (setq res i) ) (setq i (+ i 1)) ) res ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:pavers ( / bl tr p1 p2 driveway_pl pixels pix w h x y a rnd rot ind ind_ blk paver pixelsfree counter stopcounter) (setq stopcounter 3000) ;; number of times it will try to put a randow paver on a random place (setq pavers_size (list (list 1 1) (list 2 1) (list 2 2) (list 3 2) )) ;;(setq p1 (getpoint "\nPoint bottom left: ")) (setq p1 (list 0.0 0.0)) (setq p2 (getcorner p1 "\nPoint top right: ")) ;; now round down the coordinates to multiples of the size of the smallest pavers (setq bl (list (LM:rounddown (nth 0 p1) 1 ) (LM:rounddown (nth 1 p1) 1 ) )) (setq tr (list (LM:rounddown (nth 0 p2) 1 ) (LM:rounddown (nth 1 p2) 1 ) )) ;; draw driveway (drawLWPoly (list (list (nth 0 bl) (nth 1 bl) ) (list (nth 0 tr) (nth 1 bl) ) (list (nth 0 tr) (nth 1 tr) ) (list (nth 0 bl) (nth 1 tr) ) ) 1) ;; make a list of pixels (setq w (- (nth 0 tr) (nth 0 bl))) (setq h (- (nth 1 tr) (nth 1 bl))) ;; round down and turn into integer (setq w (atoi (rtos w 2 0))) (setq h (atoi (rtos h 2 0))) (setq pixels (list)) (setq x 0) (setq y 0) (repeat h (setq x 0) (repeat w (setq pixels (append pixels (list (list x y nil) ;; the nil means the pixel is empty and can/must be filled by a paver ))) (setq x (+ x 1)) ) (setq y (+ y 1)) ) ;;(princ pixels) ;;(while (/= "a" (getstring "\nPress enter for random pixel") ) (setq counter 0) (while (< counter stopcounter) ;; random pixel (setq rnd (LM:randrange 0 (- (length pixels) 1))) ;; random orientation (0 = 0°, 1 = 90°) ;;(setq rot (/ (* pi (LM:randrange 0 1)) -2) ) (setq rot (LM:randrange 0 1)) ;; 0 means horizontal, 1 means vertical (this doesn't matter for square pavers obviously) ;; random paver block. ind is the index of the paver. ;; Let's skip the smallest paver, as it will fill up any place that doesn't fit any bigger. ;;(setq blk (nth (setq ind (LM:randrange 1 (length pavers_name))) pavers_name )) (setq paver (nth (setq ind (LM:randrange 1 (- (length pavers_size) 1))) pavers_size )) (setq pix (nth rnd pixels)) ;; now put a paver there ;;(drawInsert_rot (list (nth 0 pix) (nth 1 pix)) blk rot) (setq pixels_taken (list)) ;; draw paver (if (= 0 rot) ;; horizontal T ;; vertical (setq paver (list (nth 1 paver) (nth 0 paver))) ;; swap Width / height ) (progn ;; pixels taken: ;; width = (nth 0 paver) ;; height = (nth 1 paver) (setq x (nth 0 pix)) (setq y (nth 1 pix)) (setq pixelsfree T) (repeat (nth 1 paver) (setq x (nth 0 pix)) (repeat (nth 0 paver) (setq ind_ (yx2index x y pixels)) (setq pixels_taken (append pixels_taken (list ind_))) (if (or (= ind_ nil) ;; pixels outside the driveway (nth 2 (nth ind_ pixels)) ;; pixels already taken ) (setq pixelsfree nil) ) (setq x (+ x 1)) ) (setq y (+ y 1)) ) (if pixelsfree (progn (foreach a pixels_taken ;; set (nth 2) to true (setq pixels (replace-element a (list (nth 0 (nth a pixels)) (nth 1 (nth a pixels)) T) pixels)) ) (drawLWPoly_color (list (list (nth 0 pix) (nth 1 pix) ) (list (+ (nth 0 pix) (nth 0 paver) ) (nth 1 pix) ) (list (+ (nth 0 pix) (nth 0 paver) ) (+ (nth 1 pix) (nth 1 paver)) ) (list (nth 0 pix) (+ (nth 1 pix) (nth 1 paver)) ) ) 1 ind ) ) ;;(princ "*") ) ) ;;(setq (nth 1 pix)) (setq counter (+ counter 1)) ) ;;(princ pixels) ;; fill the rest with 1/1 pavers (foreach pix pixels (if (not (nth 2 pix)) (drawLWPoly_color (list (list (nth 0 pix) (nth 1 pix) ) (list (+ (nth 0 pix) 1 ) (nth 1 pix) ) (list (+ (nth 0 pix) 1 ) (+ (nth 1 pix) 1) ) (list (nth 0 pix) (+ (nth 1 pix) 1) ) ) 1 0 ) ) ) )
    1 point
  6. No my friend was not chatgpt I did use it for helping me out to give comments on what it does. Sometimes i need to search proper how things works. And 'myfriend" is more a c## coder not lisp. But you script works perfect.. (even with less lines.) Thanks
    1 point
  7. Wow waded through the code and thought its about twice what it should be. Yes read a 8 column text around 200+ rows normally some more. Your error is probably this looks for excel. (setq xlapp (vlax-get-or-create-object "Excel.Application") Ok need the same for libre Office a real guess, (setq xlapp (vlax-get-or-create-object "Libre.Application") Go onto a Libre.Office forum and ask the question there, about a get application, if not available then its back to CSV output.
    1 point
  8. That's what ronjonp said @marko_ribar ChatGPT is a little confused. after about 2 mins and linking to lee mac site about intersection points.
    1 point
  9. Kinda made the same thing that inverts the current selection for things on screen. Useful for when its easier to select the things you don't want vs the things you do. ;;----------------------------------------------------------------------------;; ;; Invert Selection on Screen (defun C:SEE (/ SS SS1) (if (setq SS (ssget "_I")) (progn) (setq ss (ssadd)) ) (if (setq SS1 (ssget "_WP" (GetScreenCoords))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (ssdel ent SS1) ) ) (sssetfirst nil SS1) (princ) ) ;;----------------------------------------------------------------------------;; ;Calculates Size of View Window (defun GetScreenCoords (/ ViwCen ViwDim ViwSiz VptMin VptMax) (setq ViwSiz (/ (getvar 'VIEWSIZE) 2) ViwCen (getvar 'VIEWCTR) ViwDim (list (* ViwSiz (apply '/ (getvar 'SCREENSIZE))) ViwSiz) VptMin (mapcar '- ViwCen ViwDim) VptMax (mapcar '+ ViwCen ViwDim) ) (list VptMin VptMax) )
    1 point
  10. I might be wrong here but s there anything in the code that specifies Excel? That is the first search I would do, next perhaps Libre office uses different terminology to Excel (I don't know), but after searching for 'Excel' there might be other terms in there to change, ranges, cells, sheets and workbooks -should- all be called the same, it is what they are, but you never know. We use Excel so I can't check this out really but might be something to start off looking at?
    1 point
  11. Looking at your dwg have you considered making a surface from all the points ? If you use triangulation it will make a surface model of your dwg in 1 go. it will also create a surface between each rectang, If you have access to say CIV3D then it is done, else try this by YMG. You can convert the 3dfaces to a Autocad surface if needed, but the YMG has contours etc built in. ;;****************************************************************************; ;; Version V0.5.8 ; ;; C:TIN, Generates Delaunay Triangulation and Voronoi Diagram. ; ;; C:CONT, Generates Contours from a sset of 3DFACES. ; ;; C:GEN, Generates a bunch of points for testing. ; ;; C:DEMOZ, Demo of locating yourself in a triangulation. ; ;; C:LBL, Generates Label on Major Contour at regular spacing. ; ;; C:FLBL, Generates Label on All Contours along Fence Lines. ; ;; C:DLBL, Generates Label Dynamically (Based on Alan JT routine) ; ;; C:PROF, Generates a Longitudinal Profile. ; ;; C:XSHAPE, (Chi-shape) Generates a concave boundary around triangulation TriangV0.5.9.LSP
    1 point
  12. Thanks BigAl. I think sticking with a mapped URL path with a drive letter is preferable to trying the Share Drive web based link so I appreciate your suggestion! For what to put in the macro line, is this close to what you are suggesting (using "getfiled" and a "conditional" statement)? ^C^C (getfiled (cond ((= G: yes (load "G:\shardrive\CAD_Department\CAD_menu\LISP\My_routine.lsp");My_routine;) ((= H: yes (load "H:\shardrive\CAD_Department\CAD_menu\LISP\My_routine.lsp");My_routine;) ((= S: yes (load "S:\shardrive\CAD_Department\CAD_menu\LISP\My_routine.lsp");My_routine;) );end Cond );end getfiled I put together this IF statement just to see if its in the ballpark as well: ^C^C (getfiled (if (Progn ((/= G: nil (load "G:\shardrive\CAD_Department\CAD_menu\LISP\My_routine.lsp");My_routine;) ((/= H: nil (load "H:\shardrive\CAD_Department\CAD_menu\LISP\My_routine.lsp");My_routine;) ((/= S: nil (load "S:\shardrive\CAD_Department\CAD_menu\LISP\My_routine.lsp");My_routine;) );end progn );end if );end getfiled Hopefully I'm not wildly off on all the syntax. Thanks again for the great suggestion…!
    1 point
  13. Hatches can only be created in the current XY plane, so if you have a solid model, you will need to align your UCS with the face of the model that you want to hatch. Once the UCS is aligned with the face, you will need to trace around the face with a polyline. Then apply the hatch to the closed polyline. If you have a model that is made up of 3D Faces, you can align the UCS and select the edge of the face as your hatch boundary. No need to draw a polyline. I would not recommend hatching 3D objects though. Use materials instead.
    1 point
×
×
  • Create New...