Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/05/2025 in all areas

  1. Yes, LIPS is session based, that means you start a command in one drawing, it will run on one drawing and (generally) not run in another. A few ways round this. As BigAl says a script can cross drawings, open or create a new drawing, run commands in it. You could adjust the acad.lsp file, this runs on opening / creating a drawing, but your changes will run on every subsequent drawing Expanding acad.lsp file idea, you could add the below to acad.lsp file. Will work on EVERY new drawing. You could create the below as a stand alone LISP file, add it it the startup suit. Will work on EVERY new drawing You could create a temporary LISP file, search for it and if it exists run it (using acad.lsp or a file in the startup suit)... though of course you'd have to consider deleting after running. Will work on EVERY new drawing till temp file is deleted (can do that with LISP once it is loaded delete the file) Last one is a bit related, have a list of say, filename prefix and if the file name prefix is in this list do stuff... handy if say a clients drawings are all in the form "12345-dwg-001.dwg", search 123456 and if yes, do stuff. A step further on from the 'if new drawing do stuff' idea above All depends how your mind works and which you think is the best solution for you. (defun c:testthis ( / SavedDrawing ) (setq SavedDrawing (getvar "dwgtitled")) (if (= SavedDrawing 1) (progn (alert "Drawing has been saved, is not a new drawing") ) ; end progn (progn ; savedDrawing = 0 (alert "Drawing has not been saved, is a new drawing") ) ; end progn ) ; end if (princ) ) (c:testthis) ;; run on loading
    1 point
  2. Have you thought about using a script, it can open a new dwg and will automatically then be in that dwg. Script code. (command "New" "Yourtemplatename") (alert "now in other dwg do your lisp code here") version 2 (command "New" "Yourtemplatename") (load "your lisp program")
    1 point
  3. But remember: 'c' and 'r' must be 'nil' before running this 'ssget'
    1 point
  4. If, in addition, the selection must take into account the objects on those layers and that have their color set to "bylayer", then... (ssget "_X" (list '(0 . "LWP*") (cons 8 (while (setq c (tblnext "LAYER" (if c nil T))) (setq r (if (member (cdr (assoc 62 c)) '(1 5)) (if r (strcat r "," (cdr (assoc 2 c))) (cdr (assoc 2 c))) r)) ) ) '(-4 . "=,=,*") (list 10 (car p1) (cadr p1)) '(62 . 256) ) )
    1 point
  5. A brief explanation: 1) The line of code '(setq c nil)' is for if you have variable 'c' assigned because the 'while' clause of 'ssget' requires it to be initially 'nil'. 2) I've kept the filter to select only polylines that pass through point 'p1'. If you want to disable this filter, just disable the last two lines in the 'ssget' list. I hope I made myself clear.
    1 point
  6. I had a hard time understanding you. Let's see if I can get it this time: (setq c nil) (ssget "_X" (list '(0 . "LWP*") (cons 8 (while (setq c (tblnext "LAYER" (if c nil (not (setq r nil))))) (setq r (if (member (cdr (assoc 62 c)) '(1 5)) (if r (strcat r "," (cdr (assoc 2 c))) (cdr (assoc 2 c))) r)) ) ) '(-4 . "=,=,*") (list 10 (car p1) (cadr p1)) ) )
    1 point
  7. To include the layer colour, you'll need to iterate over the layer table first and construct an appropriate filter (or check the layer colour for each object within the selection and prune the selection). Here's an example - (defun c:test ( / def lay lst ) (setq lst '(1 5)) ;; Target colours (while (setq def (tblnext "layer" (null def))) (if (member (abs (cdr (assoc 62 def))) lst) (setq lay (cons (cons 8 (LM:escapewildcards (cdr (assoc 2 def)))) lay)) ) ) (sssetfirst nil (ssget "_X" (append '( (000 . "LINE") (-04 . "<OR") ) (mapcar '(lambda ( x ) (cons 62 x)) lst) (if lay (append '( (-04 . "<AND") (062 . 256) (-04 . "<OR") ) lay '( (-04 . "OR>") (-04 . "AND>") (-04 . "OR>") ) ) '( (-04 . "OR>") ) ) ) ) ) (princ) ) ;; Escape Wildcards - Lee Mac ;; Escapes wildcard special characters in a supplied string (defun LM:escapewildcards ( str ) (vl-list->string (apply 'append (mapcar '(lambda ( c ) (if (member c '(35 64 46 42 63 126 91 93 45 44)) (list 96 c) (list c) ) ) (vl-string->list str) ) ) ) ) (princ)
    1 point
  8. You didn't mention that you want a polylines. Just susbtitue (0 . "LINE") with (0 . "LWP*"). (setq ln (ssget '((0 . "LWP*") (-4 . "<OR") (62 . 5) (62 . 1) (-4 . "OR>") )))
    1 point
  9. I hadn't realized. There's a problem with the 3DFACEs in your drawing. Normally, the first and last points coincide. But in your drawing, the first and second points coincide. If you want to solve it you can use this code: (defun c:ajusta3DFACEs (/ cj ent lstent p1 p2 p3 p4 n r la c) (if (setq cj (ssget "x" '((0 . "3DFACE")))) (while (setq ent (ssname cj (setq n (if n (1+ n) 0)))) (setq lstent (entget ent) r nil la nil c 9) (foreach l lstent (if (member (car l) '(10 11 12 13)) (if la (if (not (equal (cdr l) (cdr la) 1e-8)) (setq r (cons (cons (setq c (1+ c)) (cdr l)) r) la l) ) (setq r (cons (cons (setq c (1+ c)) (cdr l)) r) la l) ) ) ) (if (= (length r) 3) (entmod (append (reverse (cdr (member (assoc 10 lstent) (reverse lstent)))) (reverse (cons (cons 13 (cdr (last r))) r)) (list (assoc 70 lstent)) ) ) ) ) ) )
    1 point
×
×
  • Create New...