Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/12/2023 in all areas

  1. Hello everyone, I've been coding a lot the past few days and I just wanted to share my code for those who may have some use for them, and also for me to keep track of my progress. ;********************************************************; ;; MA:perp-test - Test if two angles are perpendicular ;; Arguments: ;; - a (float): First angle in radians ;; - b (float): Second angle in radians ;; - tol (float): Tolerance value for comparison ;; Returns: ;; - test (bool): True if the angles are perpendicular within the given tolerance, False otherwise ;; Usage: (MA:perp-test a b tol) (defun MA:perp-test (a b tol / test) (if (and a b tol) (if (< (abs (- (abs (cos a)) (abs (sin b)))) tol) (setq test T) (setq test nil) ) ) ) This is a very simple script for when you want to compare two angles, especially of blocks you're working with. This can be modified to where it has a default tolerance value for orthogonality, but that would be a good exercise for you guys to test for yourselves.
    2 points
  2. Similar to MHUPP - I don't think it is the LISP that is at fault, more the way it is loaded. Couple of thoughts, download it again just in case the file has a confused file extension somehow (windows does do odd things every now and then), or open in notepad or similar and save as *.* file type with the .lsp in the file name Try putting the LISP in the appload start-up suit Try putting the load instructions in acad.lsp file (which should load every time) I tend to use the startup suit, having my LISPs in my personal area of the works file stores (that way a change of CAD installation won't wipe out anything important and I can jump on any computer and still have access to them). If they still don;t load I use appreload (below) to load everything in that folder: (defun c:appreload ( / lspname myfiles acount mylistlength Failedtoload) ;;Re-load named LISP files (setq MyLispFolder "c:\\") ; your LISP diorectory (setq myfiles (vl-directory-files mylispfolder "*.lsp" nil)) ;;myfiles is list of files in mylispfolder location (setq mylistlength (length myfiles)) ;;count of number of lsp files (setq acount -1) (repeat mylistlength (setq acount (1+ acount)) (setq FailedtoLoad (strcat (nth acount myfiles) " failed to load")) (load (strcat mylispfolder (nth acount myfiles)) FailedtoLoad) ;;Loads each LISP file ) (princ "\n") (princ mylistlength) (princ " lsp files loaded from ") (princ mylispfolder) (princ) )
    1 point
  3. Several ways to load lisps here. I always loaded them using the the acad.lsp file method. because It would also set several variables as well. Only used CUI to set shortcuts keys. -edit Remember something about lisp having to be in a trusted folder to autoload or something.
    1 point
  4. Consider my Split String function, found here.
    1 point
  5. Try this I added things to @BIGAL code, no trimming but scaling instead. And angles should work fine. Tested it and it seems working, but only problem is it breaks on error after first time you run the function in drawing. Don't know why, I made all variables local I think. Maybe someone can debug and figure out why is that? (defun c:testdia ( / oldosmode oldaunits lst1 lst2 dia ans pt1 start pt2 pt3 fact fact2 d12 dif_scl fact12 lin1 ang1 obj offset1L off1 offset1R off2 pt2old lin2 ang2 d23 fact23 offset2L offset2R) (setvar 'orthomode 1) (setq oldosmode (getvar 'osmode));snap (setq oldaunits (getvar 'aunits)) (setvar 'aunits 0);degrees (if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp")) (if (= ah:but nil)(setq ah:but 1)) (if (= ah:but2 nil)(setq ah:but2 1)) (setq lst1 (list "Select Dia " "25" "32" "50" "82" "110")) (setq lst2 (list "Select Visibilty " "A" "B" "C" "D")) (ah:buttscol ah:but ah:but2 "Please select " lst1 lst2) (setq dia (/ (atof (nth ah:2col lst1)) 2.0)) (setq ans (nth ah:2col2 lst2)) (setq fact (/ dia 50.0)) (setq fact2 (* fact 102)) (setq start 0) (if (and (setq pt1 (getpoint "\nStarting point of pipe: ")) (setq pt2 (getpoint pt1 "\nPick second point: "))) (progn (while (setq pt3 (getpoint pt2 "\nPick next point: ")) (setvar 'osmode 0) (cond ((= start 0) (setq d12 (distance pt1 pt2)) (setq dif_scl (- d12 fact2)) (setq fact12 (/ dif_scl d12)) (setvar 'clayer "0") (command "_line" pt1 pt2 "") (setq lin1 (entlast)) (command "_scale" lin1 "" pt1 fact12) (setq ang1 (angtos (angle pt1 pt2))) (setq obj (vlax-ename->vla-object lin1)) (vla-offset obj dia) (setq offset1L (entlast)) (setq off1 (vlax-ename->vla-object lin1)) (vla-offset obj (- 0.0 dia)) (setq offset1R (entlast)) (setq off2 (vlax-ename->vla-object lin1)) (vla-put-linetype (vlax-ename->vla-object lin1) "Center") (vla-put-linetypescale (vlax-ename->vla-object lin1) 10) ) ((= start 1) (setq pt1 pt2old) (setq lin1 lin2) (setq d12 (distance (vlax-curve-getstartPoint lin1) (vlax-curve-getendPoint lin1))) (setq dif_scl (- d12 fact2)) (setq fact12 (/ dif_scl d12)) (command "_scale" lin1 "" (vlax-curve-getstartPoint lin1) fact12) (setq offset1L offset2L) (command "_scale" offset1L "" (vlax-curve-getstartPoint offset1L) fact12) (setq offset1R offset2R) (command "_scale" offset1R "" (vlax-curve-getstartPoint offset1R) fact12) (setq ang1 (angtos (angle pt1 pt2))) ) );cond (setq d23 (distance pt2 pt3)) (setq dif_scl (- d23 fact2)) (setq fact23 (/ dif_scl d23)) (setvar 'clayer "0") (command "_line" pt2 pt3 "") (setq lin2 (entlast)) (command "_scale" lin2 "" pt3 fact23) (setq obj (vlax-ename->vla-object lin2)) (vla-offset obj dia) (setq offset2L (entlast)) (setq off1 (vlax-ename->vla-object lin2)) (vla-offset obj (- 0.0 dia)) (setq offset2R (entlast)) (setq off2 (vlax-ename->vla-object lin2)) (vla-put-linetype (vlax-ename->vla-object lin2) "Center") (vla-put-linetypescale (vlax-ename->vla-object lin2) 10) (cond ((= ang1 "0") (cond ((< (cadr pt2) (cadr pt3)) (setq ang2 "90") ) ((> (cadr pt2) (cadr pt3)) (setq ang2 "180") ) );cond ) ((= ang1 "180") (cond ((< (cadr pt2) (cadr pt3)) (setq ang2 "0") ) ((> (cadr pt2) (cadr pt3)) (setq ang2 "270") ) );cond ) ((= ang1 "90") (cond ((< (car pt2) (car pt3)) (setq ang2 "270") ) ((> (car pt2) (car pt3)) (setq ang2 "180") ) );cond ) ((= ang1 "270") (cond ((< (car pt2) (car pt3)) (setq ang2 "0") ) ((> (car pt2) (car pt3)) (setq ang2 "90") ) );cond ) );cond (setvar 'clayer "01-FITTINGS") (command "-insert" "CHWP ELBOW 40 mm 90° ELBOW" pt2 (/ dia 50.0) (/ dia 50.0) ang2) (setq obj (vlax-ename->vla-object (entlast))) (if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put")) (LM:SetVisibilityState obj ans) (setq pt2old pt2) (setq pt2 pt3) (setq start 1) (setvar 'aunits oldaunits) (setvar 'osmode oldosmode) );while );progn );if )
    1 point
  6. (defun Parse:Numbers+Decimals ( str ) (vl-list->string (vl-remove-if-not (function (lambda ( u ) (< 45 u 58) ) ) (vl-string->list str) ) ) ) (vl-load-com)
    1 point
  7. @ohhong2 Please clear out this sentence. And, please upload your sample.dwg
    1 point
×
×
  • Create New...