Leaderboard
Popular Content
Showing content with the highest reputation since 09/22/2025 in all areas
-
4 points
-
Long time I'm nothing written in Lisp. So, I hoppe it will serve you. Also, you can saw a short video how it works. The code: (prompt "\nTo run a LISP type: yval") (princ) (defun c:yval ( / old_osmode pline spt ept spt_pline ept_pline datum_line yval_datum_line yval_start_pline yval_end_pline txt_position ang_spt_pline ang_ept_pline datum_value intersecting_lines len i int_pt_pline int_pt_datum_line dist yval_position ang) (setq old_osmode (getvar 'osmode)) (setq pline (car (entsel "\nSelect Polyline to get an Elevation:"))) (while (or (equal pline nil) (not (equal "LWPOLYLINE" (cdr (assoc 0 (entget pline)))))) (prompt "\nSelected entity must be LWPOLYLINE. Try again...\n") (setq pline (car (entsel "\nSelect Polyline to get an Elevation:"))) ) (setq spt_pline (vlax-curve-getStartPoint pline) ept_pline (vlax-curve-getEndPoint pline) ) (if (> (car spt_pline) (car ept_pline)) (progn (command-s "_reverse" pline "") (setq spt_pline (vlax-curve-getStartPoint pline) ept_pline (vlax-curve-getEndPoint pline) ) ) ) (setq datum_line (car (entsel "\nSelect Datum Line:"))) (while (or (equal datum_line nil) (not (equal "LINE" (cdr (assoc 0 (entget datum_line)))))) (prompt "\nSelected entity must be LINE. Try again...\n") (setq datum_line (car (entsel "\nSelect Datum Line:\n"))) ) (setq yval_datum_line (cadr (vlax-curve-getStartPoint datum_line)) yval_start_pline (- (cadr spt_pline) yval_datum_line) yval_end_pline (- (cadr ept_pline) yval_datum_line) ) (setq txt_position (getpoint "\nPick the lower-left corner of the box for elevation value:\n")) (setvar 'osmode 0) (setq datum_value (car (entsel "\nSelect Datum value:"))) (if (equal "MTEXT" (cdr (assoc 0 (entget datum_value)))) (setq datum_value (LM:UnFormat (cdr (assoc 1 (entget datum_value))) T)) (setq datum_value (cdr (assoc 1 (entget datum_value)))) ) (setq ang_spt_pline (angle (setq yval_position_one (list (car spt_pline) (+ (cadr txt_position) 0.1) (caddr txt_position))) spt_pline) ang_ept_pline (angle (setq yval_position_two (list (car ept_pline) (+ (cadr txt_position) 0.1) (caddr txt_position))) ept_pline) ) (entmake (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 1 (rtos (+ yval_start_pline (atof datum_value)) 2 3)) (cons 10 yval_position_one) (cons 11 yval_position_one) (cons 40 0.35) (cons 72 0) (cons 73 2) (cons 50 ang_spt_pline))) (entmake (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 1 (rtos (+ yval_end_pline (atof datum_value)) 2 3)) (cons 10 yval_position_two) (cons 11 yval_position_two) (cons 40 0.35) (cons 72 0) (cons 73 2) (cons 50 ang_ept_pline))) (princ "\nSelect intersecting lines:") (setq intersecting_lines (ssget (list (cons 0 "LINE") (cons 8 "DATUM-GRID"))) len (sslength intersecting_lines) i 0 ) (while (< i len) (setq int_pt_pline (vlax-safearray->list (vlax-variant-value (vla-IntersectWith (vlax-ename->vla-object pline) (vlax-ename->vla-object (ssname intersecting_lines i)) acExtendNone))) int_pt_datum_line (vlax-safearray->list (vlax-variant-value (vla-IntersectWith (vlax-ename->vla-object datum_line) (vlax-ename->vla-object (ssname intersecting_lines i)) acExtendNone))) dist (distance int_pt_pline int_pt_datum_line) yval_position (list (car int_pt_pline) (+ (cadr txt_position) 0.1) (caddr txt_position)) ang (angle yval_position int_pt_pline) i (1+ i) ) (entmake (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 1 (rtos (+ dist (atof datum_value)) 2 3)) (cons 10 yval_position) (cons 11 yval_position) (cons 40 0.35) (cons 72 0) (cons 73 2) (cons 50 ang_spt_pline))) ) (setvar 'osmode old_osmode) (prompt "\nAn elevation values were added!") (princ) ) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat ( str mtx / _replace rx ) (vl-load-com) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) The short video: YVAL.mp4 Best regards.3 points
-
Here's a proof-of-concept example for consideration - (defun update-attributes ( / bln idx ins map obj sel tag val ) (setq ;; List of ;; ((lower-left point) (upper-right point) "attribute value") map '( (( 0.0 0.0) (10.0 10.0) "abc") ((20.0 20.0) (30.0 30.0) "def") ) ;; Block name bln "YourBlock" tag "YourTag" ) (setq bln (strcase bln) tag (strcase tag) ) (if (setq sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (strcat "`*U*," bln))))) (repeat (setq idx (sslength sel)) (setq idx (1- idx) obj (vlax-ename->vla-object (ssname sel idx)) ) (cond ( (/= bln (strcase (vlax-get-property obj (if (vlax-property-available-p obj 'effectivename) 'effectivename 'name))))) ( (setq ins (vlax-get obj 'insertionpoint) val (vl-some '(lambda ( itm ) (if (vl-every '<= (car itm) ins (cadr itm)) (caddr itm))) map) ) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (progn (if (vlax-write-enabled-p att) (vla-put-textstring att val) ) t ) ) ) (vlax-invoke obj 'getattributes) ) ) ) ) ) ) (defun block-position-callback ( rtr arg ) (if (and arg (wcmatch (strcase (car arg) t) "qsave,save,saveas,plot,publish")) (update-attributes) ) (princ) ) ( (lambda ( key ) (vl-load-com) (foreach rtr (cdar (vlr-reactors :vlr-command-reactor)) (if (= key (vlr-data rtr)) (vlr-remove rtr) ) ) (vlr-set-notification (vlr-command-reactor key '( (:vlr-commandwillstart . block-position-callback) ) ) 'active-document-only ) (update-attributes) (princ) ) "block-position-reactor" ) There is no command to run the program: simply amend the block name, tag name, and map at the top of the code to suit your setup, and then load the program - the attributes will be automatically updated when the drawing is saved or plotted.3 points
-
I did write something once to find and launch documents but its a little over the top probably. But Bigal also had a good suggestion , a program called everything.3 points
-
@Steven P See what this does. again will use default browser. (startapp "explorer.exe" "https://www.youtube.com/watch?v=dQw4w9WgXcQ") So above can be (defun c:GetGoogle ( / Search Page) (setq Search (getstring "Enter Serch Term: [use '+' between terms] ")) ;; get search term, '+' between words (setq Page (strcat "https://www.google.com/search?q=" Search)) ;; google + search term address (startapp "explorer.exe" page) ) -edit didn't have the exe3 points
-
actually quite nice Steven , think I'm gonna add this to one of my toolbars (if there's still room that is...) for opening things I also like : https://lee-mac.com/open.html3 points
-
also shell commands - I've only used that once though: (defun c:GetGoogle ( / SearchTerm PageBase) (setq SearchTerm (getstring "Enter Serch Term: [use '+' between terms] ")) ;; get search term, '+' between words (setq PageBase "(command \"shell\" \"start microsoft-edge:http://google.com/search?q=") ;; google address (setq Page (strcat PageBase SearchTerm "\")" )) ;; google + search term address (eval (read Page)) ;; open 'Page' ) Guess what this does....3 points
-
Even more reason to give weight to the opinions of those who have more experience in this area To the man with a hammer, everything looks like a nail.3 points
-
I think it's time you started to learn AutoLISP @Nikon3 points
-
Are you able to post a copy of the LISP so we can see what is happening? Sounds like your (command method is referring to the source file and the (vla- method is referring to your working file3 points
-
Another - (defun c:rectrevclcol ( / cec ) (setq cec (getvar 'cecolor)) (setvar 'cecolor "2") (initcommandversion) (vl-cmdf "_.revcloud" "_a" 500 "_r") (while (= 1 (logand 1 (getvar 'cmdactive))) (vl-cmdf "\\")) (setvar 'cecolor cec) (princ) )3 points
-
Hi, With your drawing, this code will correct the polylines. To be adapted if used in another drawing (ssget filter) (vl-load-com) (defun c:Correct3DPL ( / ss AcDoc Space nb n ename obj l_pt lay new_obj) (setq ss (ssget "_X" '((0 . "POLYLINE") (67 . 0) (8 . "CTL_PNT") (66 . 1) (70 . 9)))) (cond (ss (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)) Space (if (= 1 (getvar "CVPORT")) (vla-get-PaperSpace AcDoc) (vla-get-ModelSpace AcDoc) ) nb 0 ) (repeat (setq n (sslength ss)) (setq ename (ssname ss (setq n (1- n))) obj (vlax-ename->vla-object ename) l_pt (vlax-get obj 'Coordinates) lay (vlax-get obj 'Layer) ) (cond ((eq (length l_pt) 12) (vla-delete obj) (setq new_obj (vlax-invoke Space 'Add3dPoly (cdddr l_pt))) (vla-put-Closed new_obj :vlax-true) (vla-put-Layer new_obj lay) (setq nb (1+ nb)) ) ) ) (princ (strcat "\n" (itoa nb) " polylines corrected.")) ) ) (prin1) )3 points
-
Just sharing a simple script I just wrote, I don't have a question When drawing the hidden lines of stairs steps (the overlap of the lower step hidden under the step above) I thought: I would like to select all the steps; multi offset them; the offset lines should be selected and gripped, so that I can set them in a different layer (a layer with LType Hidden) ... But feel free to comment, improve, ... ;; Multi Offset. New objects get selected and gripped. ;; For example to make the hidden stairs steps... Select all (defun c:moff ( / sel ss pt3 i off_dst obj elast pickset1) (setq off_dst (getdist "\nOffset Distanct: ")) (setq pt3 (getpoint "\nOffset point: ")) (setq pickset1 (ssadd)) (princ "\nSelect objects: ") (setq ss (ssget)) (setq i 0) (repeat (sslength ss) (setq obj (ssname ss i)) (command "offset" off_dst obj pt3 "") (setq elast (entlast)) ;; (ssadd elast pickset1) (setq i (+ i 1)) ) ;; now grip the pickset (the newly made objects) (sssetfirst nil pickset1) )3 points
-
I think I forgot something important: when there are multiple selections, it's necessary to show the user which object will be modified in each case. Below, I've included the complete code with a zoom utility to show the user the next object to modify. ; Original by RonJonP, edited by P. Kenewell and GLAVCVS (defun c:ltx (/ o s pt i p1 p2 le) (setvar "cmdecho" 0) (command "._undo" "_be") (if (setq s (ssget ":L" '((0 . "*TEXT,DIMENSION")))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq o (vlax-ename->vla-object e)) (cond ((= "TEXT" (cdr (assoc 0 (entget e)))) (vla-put-textstring o (strcat "%%O" (vl-string-subst "" "" (vl-string-subst "" "%%O" (vla-get-textstring o)) ) ) ) ) ((= "MTEXT" (cdr (assoc 0 (entget e)))) (vla-put-textstring o (strcat "\\O" (vl-string-subst "" "" (vl-string-subst "" "\\O" (vla-get-textstring o)) ) ) ) ) ((= "DIMENSION" (cdr (assoc 0 (entget e)))) (if (not (tblsearch "APPID" "ACAD_DSTYLE_DIMJAG_POSITION")) (regapp "ACAD_DSTYLE_DIMJAG_POSITION") ) (command "_zoom" "_w" (setq i (cdr (assoc 10 (setq le (entget e))))) (polar i (angle (setq p2 (cdr (assoc 14 le))) (setq p1 (cdr (assoc 13 le)))) (distance p1 p2))) (if (setq pt (getpoint "\rJOG: Pick a point on the DIMENSION line")) (entmod (append (entget e) (list (list -3 (list "ACAD_DSTYLE_DIMJAG_POSITION" '(1070 . 387) '(1070 . 3) '(1070 . 389) (cons 1010 pt)))))) ) (if (= (vla-get-textoverride o) "") (vla-put-textoverride o "\\O<>") (vla-put-textoverride o (strcat "\\O" (vl-string-subst "" "" (vl-string-subst "" "\\O" (vla-get-textoverride o)) ) ) ) ) ) ) ) ) (command "._undo" "_end") (setvar "cmdecho" 1) (princ) )3 points
-
Depending on your version of CAD, you can use this: (defun c:test ( ) (command "_.-insert" "yourblockname" "_s" 1 "_r" 0 "_re" "_y") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\")) (princ) )2 points
-
found this one under a layer of dust : ;;; https://lispbox.wordpress.com/2016/05/01/remove-any-unloaded-unreferenced-xrefsimagespdfsdgns-and-dwfs-in-a-one-click/ ;;; Remove any unloaded (unreferenced) XREFs,IMAGE's,PDF's,DGN's and DWF's in a one click ;;; Combined from existing subroutines by Igal Averbuh 2016 ;;; Based on https://www.theswamp.org/index.php?topic=51337.0 ;;; With respect to T.Willey ; Detach any unloaded (unreferenced) XREFs (defun C:dux () (vlax-for BIND_xrefname (vla-get-blocks (vla-get-ActiveDocument (vlax-get-Acad-object))) (if (= (vla-get-isxref BIND_xrefname) ':vlax-true) (progn (setq BIND_cont (entget (vlax-vla-object->ename BIND_xrefname)) BIND_cont (tblsearch "BLOCK" (cdr (assoc 2 BIND_cont))) ) (if (or (= (cdr (assoc 70 BIND_cont)) 4) (= (cdr (assoc 70 BIND_cont)) 12)) (vla-Detach BIND_xrefname) ) ) ) ) ) (defun c:RID ( / isDefReferenced dict data name tData lst imName ) ; Remove image definition of unreferenced and unloaded definitions. (defun isDefReferenced ( aEname / cnt data ) (setq cnt 0) (foreach i (entget aEname) (if (and (equal (car i) 330) (setq data (entget (cdr i))) (= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR") ) (foreach j data (if (and (equal (car j) 330) (entget (cdr j))) (setq cnt (+ cnt 1)) ) ) ) ) (> cnt 0) ) ;------------------------------------------------------- (setq dict (namedobjdict)) (setq data (entget dict)) (setq name "ACAD_IMAGE_DICT") (if (setq data (dictsearch dict name)) (foreach i data (cond ((and imName (equal (car i) 350)) ;check to see if unreferenced or unload (setq tData (entget (cdr i))) (if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i)))) (setq lst (cons (cons imName (cdr i)) lst)) ) ) ((equal (car i) 3) (setq imName (cdr i))) (t (setq imName nil)) ) ) ) (if lst (progn (setq dict (cdr (assoc -1 data))) (foreach i lst (dictremove dict (car i)) (entdel (cdr i)) ) (prompt (strcat "\n Removed " (itoa (length lst)) " image definition(s).")) ) ) (princ) ) (defun c:RPD ( / isDefReferenced dict data name tData lst imName ) ; Remove pdf definition of unreferenced and unloaded definitions. (defun isDefReferenced ( aEname / cnt data ) (setq cnt 0) (foreach i (entget aEname) (if (and (equal (car i) 330) (setq data (entget (cdr i))) (= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR") ) (foreach j data (if (and (equal (car j) 330) (entget (cdr j))) (setq cnt (+ cnt 1)) ) ) ) ) (> cnt 0) ) ;------------------------------------------------------- (setq dict (namedobjdict)) (setq data (entget dict)) (setq name "ACAD_PDFDEFINITIONS") (if (setq data (dictsearch dict name)) (foreach i data (cond ((and imName (equal (car i) 350)) ;check to see if unreferenced or unload (setq tData (entget (cdr i))) (if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i)))) (setq lst (cons (cons imName (cdr i)) lst)) ) ) ((equal (car i) 3) (setq imName (cdr i))) (t (setq imName nil)) ) ) ) (if lst (progn (setq dict (cdr (assoc -1 data))) (foreach i lst (dictremove dict (car i)) (entdel (cdr i)) ) (prompt (strcat "\n Removed " (itoa (length lst)) " pdf definition(s).")) ) ) (princ) ) (defun c:RDD ( / isDefReferenced dict data name tData lst imName ) ; Remove dgn definition of unreferenced and unloaded definitions. (defun isDefReferenced ( aEname / cnt data ) (setq cnt 0) (foreach i (entget aEname) (if (and (equal (car i) 330) (setq data (entget (cdr i))) (= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR") ) (foreach j data (if (and (equal (car j) 330) (entget (cdr j))) (setq cnt (+ cnt 1)) ) ) ) ) (> cnt 0) ) ;------------------------------------------------------- (setq dict (namedobjdict)) (setq data (entget dict)) (setq name "ACAD_DGNDEFINITIONS") (if (setq data (dictsearch dict name)) (foreach i data (cond ((and imName (equal (car i) 350)) ;check to see if unreferenced or unload (setq tData (entget (cdr i))) (if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i)))) (setq lst (cons (cons imName (cdr i)) lst)) ) ) ((equal (car i) 3) (setq imName (cdr i))) (t (setq imName nil)) ) ) ) (if lst (progn (setq dict (cdr (assoc -1 data))) (foreach i lst (dictremove dict (car i)) (entdel (cdr i)) ) (prompt (strcat "\n Removed " (itoa (length lst)) " dgn definition(s).")) ) ) (princ) ) (defun c:RWD ( / isDefReferenced dict data name tData lst imName ) ; Remove dwf definition of unreferenced and unloaded definitions. (defun isDefReferenced ( aEname / cnt data ) (setq cnt 0) (foreach i (entget aEname) (if (and (equal (car i) 330) (setq data (entget (cdr i))) (= (cdr (assoc 0 data)) "IMAGEDEF_REACTOR") ) (foreach j data (if (and (equal (car j) 330) (entget (cdr j))) (setq cnt (+ cnt 1)) ) ) ) ) (> cnt 0) ) ;------------------------------------------------------- (setq dict (namedobjdict)) (setq data (entget dict)) (setq name "ACAD_DWFDEFINITIONS") (if (setq data (dictsearch dict name)) (foreach i data (cond ((and imName (equal (car i) 350)) ;check to see if unreferenced or unload (setq tData (entget (cdr i))) (if (or (equal (cdr (assoc 280 tData)) 0) (not (isDefReferenced (cdr i)))) (setq lst (cons (cons imName (cdr i)) lst)) ) ) ((equal (car i) 3) (setq imName (cdr i))) (t (setq imName nil)) ) ) ) (if lst (progn (setq dict (cdr (assoc -1 data))) (foreach i lst (dictremove dict (car i)) (entdel (cdr i)) ) (prompt (strcat "\n Removed " (itoa (length lst)) " dwf definition(s).")) ) ) (princ) ) (defun c:eid () (c:dux) (c:rid) (c:rpd) (c:rdd) (c:rwd) (vl-cmdf "_.externalreferences") (princ) ) (c:eid)2 points
-
maybe something like this (untested) ;;; copy & paste for dummies - rlx 2025-10-18 (defun c:capfd ( / this-dwg ss other-dwg blocknames-in-selectionset blocknames-in-other-dwg duplicate-blocknames) (setq this-dwg (vla-get-ActiveDocument (vlax-get-acad-object))) (if (and (setq ss (ssget)) (setq other-dwg (getfiled "Copy SS to:" "" "dwg" 0))) (progn (setq blocknames-in-selectionset (Get_SS_BlockNames ss)) (setq blocknames-in-other-dwg (Get_DBX_Blocknames other-dwg)) (setq duplicate-blocknames (compare_block_names blocknames-in-selectionset blocknames-in-other-dwg)) (if (vl-consp duplicate-blocknames) (progn (dplm duplicate-blocknames "Duplicated block names : ") (if (yes_no "Copy anyway?") (ctd ss other-dwg) (princ"\nBite me...") ) ) (ctd ss other-dwg) ) ) ) (princ) ) (defun compare_block_names (a b / c) (and (vl-consp a) (vl-consp b) (foreach item a (if (member item b) (setq c (cons item c))))) c) (defun Get_SS_BlockNames ( ss / n l) (foreach o (ss->ol ss) (if (and (block-p o)(not (member (setq n (block-n o)) l))) (setq l (cons n l)))) l) (defun SS->OL (ss / i l)(setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) ; (block-p (vlax-ename->vla-object (car (entsel)))) (defun block-p (o) (and (= 'vla-object (type O))(eq (vla-get-objectname O) "AcDbBlockReference"))) (defun block-n (o) (if (and (= 'vla-object (type O))(eq (vla-get-objectname O) "AcDbBlockReference")) (if (vlax-property-available-p o 'EffectiveName)(vla-Get-EffectiveName o)(vla-Get-Name o)) nil)) ; (yes_no "Do you like snow") (defun yes_no ( $m / f p i r ) (and (= (type $m) 'STR) (setq f (vl-filename-mktemp ".dcl")) (setq p (open f "w")) (write-line (strcat "yesno:dialog{label=\"" $m "?\";ok_cancel;}") p) (progn (close p)(gc) t) (setq i (load_dialog f)) (new_dialog "yesno" i) (progn (action_tile "accept" "(done_dialog 1)")(action_tile "cancel" "(done_dialog 0)") (setq r (start_dialog))(unload_dialog i)(vl-file-delete f) t)(if (= r 1) t nil))) ;;; display list (plus message) (defun dplm (l m / f p d w) (and (vl-consp l) (setq l (mapcar 'vl-princ-to-string l)) (setq w (+ 5 (apply 'max (mapcar 'strlen l)))) (setq p (open (setq f (vl-filename-mktemp ".dcl")) "w")) (princ (strcat "cfl:dialog{label=\"" m "\";:list_box {key=\"lb\";" "width="(itoa w)";}ok_only;}") p)(not (setq p (close p)))(< 0 (setq d (load_dialog f)))(new_dialog "cfl" d)(progn (start_list "lb") (mapcar 'add_list l)(end_list)(action_tile "accept" "(done_dialog)")(start_dialog)(unload_dialog d)(vl-file-delete f)))) ;;; copy to drawing (defun ctd ( ss dwg / ss->ol dbx_ver acApp acDoc dbx object-list object-safe-array) (defun SS->OL (ss / i l) (setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) (defun dbx_ver ( / v) (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))) (setq acApp (vlax-get-acad-object) acDoc (vla-get-ActiveDocument acApp)) (setq dbx (vl-catch-all-apply 'vla-getinterfaceobject (list acApp (dbx_ver)))) (vla-open dbx dwg) ; put all block objects in a list (setq object-list (ss->ol ss)) ; put list with objects in a safe array (setq object-safe-array (vlax-make-safearray vlax-vbobject (cons 0 (1- (length object-list))))) (vl-catch-all-apply 'vlax-safearray-fill (list object-safe-array object-list)) ; copy objects to dbx-drawing (vla-CopyObjects acDoc object-safe-array (vla-get-ModelSpace dbx)) (vl-catch-all-apply 'vla-saveas (list dbx dwg)) (vl-catch-all-apply 'vlax-release-object (list dbx)) (setq object-list nil object-safe-array nil) (princ) ) ; test : (setq lst (GetDocBlockNames (vla-get-ActiveDocument (vlax-get-acad-object)))) ; returns sorted list (uppercase) like : ("BLOCK_A" "BLOCK_B" ...) (defun GetDocBlockNames (d / o n l) (vlax-for o (vla-get-blocks d)(if (and (= :vlax-false (vla-get-isxref o))(= :vlax-false (vla-get-islayout o)) (snvalid (setq n (vla-get-name o)) 0))(setq l (cons (strcase n) l))))(if (vl-consp l)(acad_strlsort l))) (defun Get_DBX_Blocknames ( doc-name / lst v objectdbx-document) (cond ((not (eq (type doc-name) 'STR)) (princ (strcat "\nInvalid filename : " (vl-princ-to-string doc-name)))) ((not (findfile doc-name)) (princ (strcat "\nFile not found : " (vl-princ-to-string doc-name)))) (t (vlax-for doc (vla-get-Documents (vlax-get-acad-object)) (and (eq (strcase (vla-get-fullname doc)) (strcase doc-name))(setq objectdbx-document doc))) (cond ((eq (type objectdbx-document) 'VLA-OBJECT)) ((not (setq objectdbx-document (vlax-create-object (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))))) (princ "\nUnable to start object dbx")) ((vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list objectdbx-document doc-name))) (princ (strcat "\nOdbx error - unable to acces : " doc-name))) (t (setq lst (GetDocBlockNames objectdbx-document))) ) ) ) (vl-catch-all-apply 'vla-close (list objectdbx-document :vlax-False)) (if (and (= 'vla-object (type objectdbx-document))(not (vlax-object-released-p objectdbx-document))) (vlax-release-object objectdbx-document)) (if (vl-consp lst) (mapcar 'strcase lst)) ) and if you want the rename version : ;;; copy for lazy dummies - rlx 2025-10-18 (defun c:cfld ( / this-dwg ss other-dwg blocknames-in-selectionset blocknames-in-other-dwg duplicate-blocknames) (setq this-dwg (vla-get-ActiveDocument (vlax-get-acad-object))) (if (and (setq ss (ssget)) (setq other-dwg (getfiled "Copy SS to:" "" "dwg" 0))) (progn (if (vl-consp (setq blocknames-in-selectionset (Get_SS_BlockNames ss))) (setq blocknames-in-selectionset (mapcar 'strcase blocknames-in-selectionset))) (if (vl-consp (setq blocknames-in-other-dwg (Get_DBX_Blocknames other-dwg))) (setq blocknames-in-other-dwg (mapcar 'strcase blocknames-in-other-dwg))) (setq duplicate-blocknames (compare_block_names blocknames-in-selectionset blocknames-in-other-dwg)) (if (vl-consp duplicate-blocknames) (progn (dplm duplicate-blocknames "Duplicated block names : ") ;;; (if (yes_no "Copy anyway?") (ctd ss other-dwg) (princ"\nBite me...") ) (if (yes_no "Rename duplicates?") (progn (foreach b duplicate-blocknames (rename_block_definition b)) (ctd ss other-dwg) ) (princ"\nBite me...") ) ) (ctd ss other-dwg) ) ) ) (princ) ) ; check if $member exists in (vla-) %collection (defun Collection-Member ( $member %collection / result) (if (vl-catch-all-error-p (setq result (vl-catch-all-apply 'vla-item (list %collection $member)))) nil result)) (defun create_unique_blockname ( $bn / i bn) (setq i 0)(while (tblsearch "block" (setq bn (strcat $bn "_" (itoa (setq i (1+ i))))))) bn) (defun rename_block_definition ( $bn / bn ) (if (and (not (void $bn)) (tblsearch "block" $bn)) (vla-put-name (Collection-Member $bn (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)))) (setq bn (create_unique_blockname $bn)))) bn) (defun compare_block_names (a b / c) (and (vl-consp a) (vl-consp b) (foreach item a (if (member item b) (setq c (cons item c))))) c) (defun Get_SS_BlockNames ( ss / n l) (foreach o (ss->ol ss) (if (and (block-p o)(not (member (setq n (block-n o)) l))) (setq l (cons n l)))) l) (defun SS->OL (ss / i l)(setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) ; (block-p (vlax-ename->vla-object (car (entsel)))) (defun block-p (o) (and (= 'vla-object (type O))(eq (vla-get-objectname O) "AcDbBlockReference"))) (defun block-n (o) (if (and (= 'vla-object (type O))(eq (vla-get-objectname O) "AcDbBlockReference")) (if (vlax-property-available-p o 'EffectiveName)(vla-Get-EffectiveName o)(vla-Get-Name o)) nil)) ; (yes_no "Do you like snow") (defun yes_no ( $m / f p i r ) (and (= (type $m) 'STR) (setq f (vl-filename-mktemp ".dcl")) (setq p (open f "w")) (write-line (strcat "yesno:dialog{label=\"" $m "?\";ok_cancel;}") p) (progn (close p)(gc) t) (setq i (load_dialog f)) (new_dialog "yesno" i) (progn (action_tile "accept" "(done_dialog 1)")(action_tile "cancel" "(done_dialog 0)") (setq r (start_dialog))(unload_dialog i)(vl-file-delete f) t)(if (= r 1) t nil))) ;;; display list (plus message) (defun dplm (l m / f p d w) (and (vl-consp l) (setq l (mapcar 'vl-princ-to-string l)) (setq w (+ 5 (apply 'max (mapcar 'strlen l)))) (setq p (open (setq f (vl-filename-mktemp ".dcl")) "w")) (princ (strcat "cfl:dialog{label=\"" m "\";:list_box {key=\"lb\";" "width="(itoa w)";}ok_only;}") p)(not (setq p (close p)))(< 0 (setq d (load_dialog f)))(new_dialog "cfl" d)(progn (start_list "lb") (mapcar 'add_list l)(end_list)(action_tile "accept" "(done_dialog)")(start_dialog)(unload_dialog d)(vl-file-delete f)))) ;;; copy to drawing (defun ctd ( ss dwg / ss->ol dbx_ver acApp acDoc dbx object-list object-safe-array) (defun SS->OL (ss / i l) (setq i 0)(repeat (sslength ss)(setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) (defun dbx_ver ( / v) (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))) (setq acApp (vlax-get-acad-object) acDoc (vla-get-ActiveDocument acApp)) (setq dbx (vl-catch-all-apply 'vla-getinterfaceobject (list acApp (dbx_ver)))) (vla-open dbx dwg) ; put all block objects in a list (setq object-list (ss->ol ss)) ; put list with objects in a safe array (setq object-safe-array (vlax-make-safearray vlax-vbobject (cons 0 (1- (length object-list))))) (vl-catch-all-apply 'vlax-safearray-fill (list object-safe-array object-list)) ; copy objects to dbx-drawing (vla-CopyObjects acDoc object-safe-array (vla-get-ModelSpace dbx)) (vl-catch-all-apply 'vla-saveas (list dbx dwg)) (vl-catch-all-apply 'vlax-release-object (list dbx)) (setq object-list nil object-safe-array nil) (princ) ) ; test : (setq lst (GetDocBlockNames (vla-get-ActiveDocument (vlax-get-acad-object)))) ; returns sorted list (uppercase) like : ("BLOCK_A" "BLOCK_B" ...) (defun GetDocBlockNames (d / o n l) (vlax-for o (vla-get-blocks d)(if (and (= :vlax-false (vla-get-isxref o))(= :vlax-false (vla-get-islayout o)) (snvalid (setq n (vla-get-name o)) 0))(setq l (cons (strcase n) l))))(if (vl-consp l)(acad_strlsort l))) (defun Get_DBX_Blocknames ( doc-name / lst v objectdbx-document) (cond ((not (eq (type doc-name) 'STR)) (princ (strcat "\nInvalid filename : " (vl-princ-to-string doc-name)))) ((not (findfile doc-name)) (princ (strcat "\nFile not found : " (vl-princ-to-string doc-name)))) (t (vlax-for doc (vla-get-Documents (vlax-get-acad-object)) (and (eq (strcase (vla-get-fullname doc)) (strcase doc-name))(setq objectdbx-document doc))) (cond ((eq (type objectdbx-document) 'VLA-OBJECT)) ((not (setq objectdbx-document (vlax-create-object (strcat "objectdbx.axdbdocument" (if (< (setq v (atoi (getvar 'acadver))) 16) "" (strcat "." (itoa v))))))) (princ "\nUnable to start object dbx")) ((vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list objectdbx-document doc-name))) (princ (strcat "\nOdbx error - unable to acces : " doc-name))) (t (setq lst (GetDocBlockNames objectdbx-document))) ) ) ) (vl-catch-all-apply 'vla-close (list objectdbx-document :vlax-False)) (if (and (= 'vla-object (type objectdbx-document))(not (vlax-object-released-p objectdbx-document))) (vlax-release-object objectdbx-document)) (if (vl-consp lst) (mapcar 'strcase lst)) ) (c:cfld)2 points
-
I think this code should meet what you need. ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:subTexta (/ e n le vlae txu tx cj g? tg) (vl-catch-all-apply '(lambda () (while (or (/= (setq tx (getstring (strcat "\nType TEXT to add to DIMENSION (escape to EXIT) " (if tx (strcat "<" tx ">") "") ": "))) "") txu) (set (if (= tx "") 'tx 'txu) (if (= tx "") txu tx)) (setq n nil cj (ssget "_:L" '((0 . "*DIMENSION")))) (while (setq e (ssname cj (setq n (if n (1+ n) 0)))) (setq g? (/= (setq tg (vla-get-Textoverride (setq vlae (vlax-ename->vla-object e)))) "")) ;(vla-put-Textoverride vlae (if g? (strcat tg (if (wcmatch tg "*\\X*") "\n" "\\X") tx) (strcat tg "<>\\X" tx)));ACTIVA ESTA LÍNEA SI QUIERES EVITAR QUE PONGA EL SIGNO + DELANTE DEL PRIMER TEXTO Y DESACTIVA LA SIGUIENTE LÍNEA DE CODIGO (vla-put-Textoverride vlae (if g? (strcat (if (wcmatch tg "+*") "" "+") tg (if (wcmatch tg "*\\X*") "\n" "\\X") tx) (strcat "+" (rtos (vla-get-Measurement vlae) 2 (vla-get-PrimaryUnitsPrecision vlae)) "\\X" tx))) ) ) ) ) (princ) )2 points
-
2 points
-
2 points
-
Look for Notepad your Acad.pgp make code even shorter. This the bat file I use. d: cd\alan\lisp findstr %1 *.lsp2 points
-
If you wish to entmake a field, you need to also entmake the FIELD entity within the TEXT entry of the ACAD_FIELD dictionary found within the extension dictionary attached to the entity - this is theoretically possible, but a lot of work and wheel reinvention. Instead, if you either create the MText object using vla-addmtext or convert the MTEXT entity into a VLA object and set the textstring property to a field expression, the CAD platform will automatically parse the field expression and configure the corresponding dictionaries for you.2 points
-
I use Everything all the time it indexes hard drives and finds a file instantly. Re Access, Word, Excel and Libre office all of these can be accessed from CAD I use Bricscad. You can for say Access not only open but actually get at the data, most common being Excel get and put. If you have a few known files you want to open all the time can either make a defun for each and load on startup or my preferred would be a sub menu in a POP menu with the file names as the description. As mentioned already using notepad is shown how in ACAD.PGP as an already defined option.2 points
-
2 points
-
This will search a location for a file type, in the example searching for LISP files in c:\MyLocation\Here - remember to use a double backslash in any location, and return a list of files names + extensions (also folders if the file type is *.*). (setq myfiles (vl-directory-files "C:\\MyLocation\\Here" "*.lsp" nil)) You could do a search of this list to check if your required file is in there As MHUPP use startapp to open the file, here opens the file in variable Lispfile with notepad (startapp "notepad" Lispfile) MHUPP example was for explorer - I didn't know that method would work for any file type to open the default programme. For the first line here, your file path could be contained in a list, looping through each list item (location) until you find the file you want - could search a few locations if you knew them and want to hardcode them in the LISP, and if fails to find them there use MHUPPs 'getfiled' line for the user to select a folder or file. Use an if, cond or while loop to open the file where it finds it and stop the rest of the loop from looping2 points
-
Had a command DIR to start in the folder of the active drawing would open the save prompt like window to allow you to select the file you want. pretty sure if you feed the path to explorer it will use the default program to open the file. (defun C:DIR ( / filePath) (setq dwgPath (getvar "DWGPREFIX")) (setq filePath (getfiled "Select a File to Open" dwgPath "*" 0)) ;limit what types you see by changing "*" (if filePath (progn (startapp "explorer.exe" filePath) (princ (strcat "\nOpening: " filePath)) ) (princ "\nNo file selected.") ) (princ) ) -edit You can also hard code where it stats in like if your documents are in a network drive. (setq filePath (getfiled "Select a Spec File" "C:\\Project\\spec\\" "PDF" 0)) ;look in spec folder for all pdf's2 points
-
Oh I'm not mad, I just think you're blinkered into using the Startup Suite. As I've suggested throughout this thread, I would use the acaddoc.lsp. In my acaddoc.lsp, I have the following basic code: ( (lambda ( d ) (foreach x (vl-directory-files d "*.lsp" 1) (if (/= "acaddoc.lsp" (strcase x t)) (load (strcat d "\\" x) nil) ) ) ) "C:\\YourLISPFolder" ) Then, whatever .lsp files I place in "C:\\YourLISPFolder" are automatically loaded on startup - no need to change the Startup Suite, no need to modify the acaddoc.lsp any further - just drop a file into the folder.2 points
-
@Nikon My 2c .. place all your lisp files in a subfolder under "MYDOCUMENTS". Then you don't have to worry about permissions, AutoCAD version or usernames. (strcat (getvar "MYDOCUMENTSPREFIX") "\\LISP") Then add this to your support paths and DONE!2 points
-
You can enable VLIDE in newer releases by setting LISPSYS=0. https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-1853092D-6E6D-4A06-8956-AD2C3DF203A32 points
-
I'm still not understanding why this won't do the trick. I've been successfully loading files for 20+ years using a version of that code and a custom MNL tied to a partial CUI. Adding a bunch of lisp routines to the startup suite is not standard practice ( well at least in my little world : ) )2 points
-
I think Steven is right , this is about redefining or not. When you insert a block without path , AutoCad uses the block definition allready present in active drawing. If you put a path to it , AutoCad will overwrite current block definition with the one on file. So , if you insert block for the first time , then edit it and after that insert the one from file , your edited definition will be overwritten again. Standard / classic / basic AutoCad behaviour.2 points
-
You should avoid using Defpoints layer, Defpoints layer in AutoCAD is automatically created when dimensions are added and is intended to hold definition points for those dimensions. While some users may place objects on this layer to prevent them from printing, it is generally not recommended as it can lead to unexpected issues in the drawing. Create a new no plot layer instead and use that.2 points
-
Shout out to @alanjt for doing the heavy lifting here. This will generate a temp DCL Menu with a list provided and whatever you pick will change the scale accordingly. could be cleaned up a bit with error handling of making sure you selected a viewport or if your in an active viewport pick that one by default. ;;----------------------------------------------------------------------------;; ;; Generates DCL Menu for user to select a veiwport Scale (defun C:VPS () (C:VPSCALE)) (defun C:VPSCALE (/ lst vp) (vl-load-com) (setq Doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark Doc) (setq lst '("1:1" "1:5" "1:10" "1:15" "1:20" "1:30" "1:40" "1:50" "1:60" "1:70" "1:80" "1:90" "1:100")) ;update list how you see fit (if (setq vp (car (entsel "\nSelect viewport: "))) (progn (setq vp (vlax-ename->vla-object vp)) (setq scl (AT:ListSelect "Set Viewport Scale" "Pick A Scale" 30 60 "False" lst)) (setq X (atoi (substr scl 3))) (vla-put-CustomScale vp (/ 1.0 X)) (vla-Regen Doc acAllViewports) ;might not be needed (princ (strcat "\nViewport scale set to " scl)) ) ) (vla-endundomark Doc) (princ) ) ;;----------------------------------------------------------------------------;; ;; Function to Pick form list ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) ;; (AT:ListSelect "Title" "Lable" Height Width "true/false multi select" lst) ;; some coding borrowed from http://www.jefferypsanders.com (thanks for the DCL examples) (defun AT:ListSelect (title label height width multi lst / fn fo d f) (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line (strcat "list_select : dialog { label = \"" title "\"; spacer;") fo) (write-line (strcat ": list_box { label = \"" label "\";" "key = \"lst\";") fo) (write-line (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";") fo) (write-line (strcat "width = " (vl-princ-to-string width) ";") fo) (write-line (strcat "multiple_select = " multi "; } spacer; ok_cancel; }") fo) (close fo) (new_dialog "list_select" (setq d (load_dialog fn))) (start_list "lst") (mapcar (function add_list) lst) (end_list) (setq item (set_tile "lst" "0")) (action_tile "lst" "(setq item $value)") (setq f (start_dialog)) (unload_dialog d) (vl-file-delete fn) (if (= f 1) ((lambda (s / i s l) (while (setq i (vl-string-search " " s)) (setq l (cons (nth (atoi (substr s 1 i)) lst) l)) (setq s (substr s (+ 2 i))) ) (reverse (cons (nth (atoi s) lst) l)) ) item ) ) ) -edit Set x as integer with atoi2 points
-
or instead of using (setq p2 (getpoint p1)) try (setq p2 (getcorner p1))2 points
-
Another option: Keeping the original entity and removing any repeated points along the 3D polyline. (defun supriPts3DPol (e / l p lp vlae) (setq vlae (vlax-ename->vla-object e)) (while (/= (cdr (assoc 0 (setq l (entget (setq e (entnext e)))))) "SEQEND") (if (not (equal (setq p (cdr (assoc 10 l))) (car lp) 1e-4)) (setq lp (cons p lp))) ) (vlax-put vlae 'Coordinates (apply 'append (mapcar '(lambda(p) (mapcar 'float p)) lp))) )2 points
-
******************************************************************** When I use lisp commands, I always wish the developers all the best. Thank you so much for your hard work and enthusiasm. Thanks to your programs, routine work turns into pleasure. And it takes much less time to create drawings. ********************************************************************2 points
-
Another way, taking advantage of @Lee Mac's idea and condensing an output message for the user (defun c:sf (/ v) (princ (strcat "\n*** " (setq v "UCSFOLLOW") (nth (setvar v (- 1 (getvar v))) '(" desactivado" " activado")))) (princ) )2 points
-
Update to aggregate the logs - (defun init ( ) (foreach grp (vlr-reactors :vlr-command-reactor :vlr-lisp-reactor) (foreach rtr (cdr grp) (if (= "lisp-commands" (vlr-data rtr)) (vlr-remove rtr) ) ) ) (setq lisp-command-list nil) (vlr-command-reactor "lisp-commands" '((:vlr-commandwillstart . onsave))) (vlr-lisp-reactor "lisp-commands" '((:vlr-lispwillstart . onlisp))) (princ) ) (defun onsave ( rtr arg / ent enx idx lyr mts sel str ) (setq lyr "lisp-commands") (cond ( (not arg)) ( (not (wcmatch (setq arg (strcase (car arg))) "SAVE,QSAVE,SAVEAS"))) ( lisp-command-list (if (setq sel (ssget "_X" (list (cons 8 lyr)))) (repeat (setq idx (sslength sel)) (setq idx (1- idx) ent (ssname sel idx) enx (entget ent) ) (if (= "MTEXT" (cdr (assoc 0 enx))) (setq mts (cdr (assoc 1 enx))) ) (entdel ent) ) ) (if mts (setq lisp-command-list (mergelists (parsetext mts) lisp-command-list))) (setq str "") (foreach itm (vl-sort lisp-command-list '(lambda ( a b ) (> (cdr a) (cdr b)))) (setq str (strcat str "\\P" (car itm) "\t\t" (itoa (cdr itm)))) ) (makelayer lyr) (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") '(010 0.0 0.0) (cons 1 (substr str 3)) (cons 8 lyr) ) ) (setq lisp-command-list nil) ) ) (princ) ) (defun onlisp ( rtr arg / fun itm ) (cond ( (not arg)) ( (wcmatch (setq arg (strcase (car arg))) "~(C:*)")) ( (setq fun (substr arg 4 (- (strlen arg) 4)) itm (assoc fun lisp-command-list) ) (setq lisp-command-list (subst (cons (car itm) (1+ (cdr itm))) itm lisp-command-list)) ) ( (setq lisp-command-list (cons (cons fun 1) lisp-command-list))) ) (princ) ) (defun makelayer ( lay ) (if (not (tblobjname "layer" lay)) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") '(070 . 0) (cons 2 lay) '(062 . 8) '(290 . 0) ) ) ) ) (defun parsetext ( str / pos ) (cond ( (setq pos (vl-string-search "\\P" str)) (append (parsetext (substr str 1 pos)) (parsetext (substr str (+ pos 3)))) ) ( (setq pos (vl-string-position 9 str)) (list (cons (substr str 1 pos) (atoi (substr str (+ pos 3))))) ) ) ) (defun mergelists ( ls1 ls2 / ass ) (if (< (length ls1) (length ls2)) (mapcar 'set '(ls1 ls2) (list ls2 ls1)) ) (foreach itm ls2 (if (setq ass (assoc (car itm) ls1)) (setq ls1 (subst (cons (car itm) (+ (cdr ass) (cdr itm))) ass ls1)) (setq ls1 (cons itm ls1)) ) ) ls1 ) (vl-load-com) (init)2 points
-
Yes I know. 'vlr-remove-all' is executed during loading so that any reactor created with the previous code is erased. It was a quick solution. Additionally, it runs when the drawing is exited or at startup before any other application loads, so it would only affect those reactors that should remain between drawings. I assumed that Nikon does not use these reactors. But it is probably a risky assumption. So I guess I am "obliged" to fix it. Below, a solution that keeps the reactors even if the drawing closure is canceled, that respects any reactor created by another application, and that regenerates them in each drawing. (defun fota (/ arch cad cmd mens etq letq n er lx) (defun pregunta (a b / cad) (cond ((member (strcase (car b)) '("CLOSE" "_CLOSE" "QUIT" "_QUIT" "EXIT" "_EXIT")) (if (and *lstCmds* (setq mens (cmdsCargados)) (= (vlax-invoke-method (vlax-create-object "wscript.shell") 'popup "Print commands on screen?" 0 "Save commands name" 4) 6) ) (progn (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (getpoint "\nInsertion point...")) 100 mens) (vlax-invoke-method (vlax-get-acad-object) 'Update) ) ) ) ((= (type a) 'VLR-Lisp-Reactor) (if (not (member (setq cad (substr (car b) 4 (- (strlen (car b)) 4))) *lstCmds*)) (setq *lstCmds* (cons (substr (car b) 4 (- (strlen (car b)) 4)) *lstCmds*)) ) ) ) ) (setq letq '("Nikon1" "Nikon2") *afI* nil) (foreach r (vlr-reactors) (foreach er (cdr r) (if (member (setq etq (vlr-data er)) letq) (if (wcmatch etq "Nikon1,Nikon2") (setq lx (cons er lx)) ) ) ) ) (if lx (foreach r lx (vlr-remove r))) (foreach sim (atoms-family 0) (if (wcmatch (setq cmd (strcase (vl-princ-to-string sim) T)) "c:*") (setq *afI* (cons sim *afI*)) ) ) (setq *r* (vlr-command-reactor "Nikon1" '((:vlr-commandwillStart . pregunta)))) (setq *r1* (vlr-lisp-reactor "Nikon2" '((:vlr-lispwillstart . pregunta)))) ) (defun cmdsCargados (/ cad) (setq *cadCmds* nil) (foreach sim (atoms-family 0) (if (not (member sim *afI*)) (if (and (wcmatch (setq cad (strcase (vl-princ-to-string sim) T)) "c:*") (member (strcase (substr cad 3)) *lstCmds*) ) (setq *cadCmds* (strcat (if *cadCmds* (strcat *cadCmds* "\n") "\\C1Comandos utilizados durante la sesi贸n:\\C256\n") (substr cad 3))) ) ) ) *cadCmds* ) (fota)2 points
-
Not sure if this is useful it tracks all commands used in a session Productivity_Analysis_Tool.lsp2 points
-
I think it's a good idea that I'm also going to try: leaving a text box with the names of the Lisp commands used to edit a drawing. This new code will filter all of AutoCAD's predefined Lisp commands and, of those loaded by the user, will only consider those that have been used in the drawing. To avoid confusion, replace everything above with this new one. (defun fota (/ arch cad cmd) (defun pregunta (a b / cad) (cond ((= (car b) "CLOSE") (if (and *lstCmds* (= (vlax-invoke-method (vlax-create-object "wscript.shell") 'popup "Print commands on screen?" 0 "Nikon's doubts" 4) 6)) (c:cmdsCargados)) ) ((= (type a) 'VLR-Lisp-Reactor) (if (not (member (setq cad (substr (car b) 4 (- (strlen (car b)) 4))) *lstCmds*)) (setq *lstCmds* (cons (substr (car b) 4 (- (strlen (car b)) 4)) *lstCmds*)) ) ) ) ) (foreach sim (atoms-family 0) (if (wcmatch (setq cmd (strcase (vl-princ-to-string sim) T)) "c:*") (setq *afI* (cons sim *afI*)) ) ) (setq *r* (vlr-command-reactor nil '((:vlr-commandwillStart . pregunta)))) (setq *r1* (vlr-lisp-reactor nil '((:vlr-lispwillstart . pregunta)))) ) (defun c:cmdsCargados (/ cad arch linea) (setq *cadCmds* nil) (foreach sim (atoms-family 0) (if (not (member sim *afI*)) (if (and (wcmatch (setq cad (strcase (vl-princ-to-string sim) T)) "c:*") (member (strcase (substr cad 3)) *lstCmds*) ) (setq *cadCmds* (strcat (if *cadCmds* (strcat *cadCmds* "\n") "\\C1Commands loaded during last sesion:\\C256\n") (substr cad 3))) ) ) ) (if *cadCmds* (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (getpoint "\nInsertion point...")) 100 *cadCmds*)) (princ) ) (fota)2 points
-
300 Lisp programmes... If you have the time, create this: (defun recordLISP (LispName / ) (if (= LispsList nil) ; check if list exits (progn (setq LispsList (list LispName)) ; create new list, add text string to it ) ; end progn (progn (setq LispsList (cons LispName LispsList)) ; add LispName to LispsList ) ; end progn ) ; end IF ) (defun c:MySave ( / ) (defun MakeMText (pt TxtString) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 TxtString) )) ; end Entmakex, End List ) ; end MakeMText (defun LM:lst->str ( lst del ) (if (cdr lst) (strcat (car lst) del (LM:lst->str (cdr lst) del)) (car lst) ) ) (MakeMText (GetPoint "Enter Insert Point") (LM:lst->str (reverse LispsList) "\\P")) ) and for every LISP you want to record add this line (recordLISP "-LISPNAME-") A little over the top maybe, but you get to control what LISPs you really want to record. For example, I have a couple of shortcuts, for example "ZA" for Zoom All, "PlotPDF" to plot a PDF - neither of these examples are a part of the process to create a drawing, where others such as "CTX+" - Copy Text, increment by 1 is, I might want to record that. If you LISP library is like mine you could probably cut 50 or so off that 300 LISPs as unnecessary to record think. I am curious what the end result you want to do is, once you have listed the commands you use, you can recreate process to create the drawing, but perhaps without also knowing mouse clicks and keyboard entries not a lot else?2 points
-
Another - (defun c:sf ( ) (setvar 'ucsfollow (- 1 (getvar 'ucsfollow))) (princ) )2 points
-
Or this, for toggle (defun c:SF ( / ) (if (zerop (boole 1 (getvar "UCSFOLLOW") 1)) (progn (setvar "UCSFOLLOW" (1+ (getvar "UCSFOLLOW"))) (princ "\nUCS Follow Activado") ) (progn (setvar "UCSFOLLOW" (1- (getvar "UCSFOLLOW"))) (princ "\nUCS Follow Desactivado") ) ) (prin1) )2 points
-
I would add: ; Original by Emmanuel Delay + additions (defun c:MuOffLay ( / ss pt3 i off_dst obj elast pickset1 old_dst str_prompt) ;; creating a new layer (if (not (tblsearch "LAYER" "OffsetLines")) (command "_-layer" "_make" "OffsetLines" "_color" "1" "OffsetLines" "") ) ;; memorizing the distance (setq old_dst (getenv "MULTIOFF_LASTDST")) (if old_dst (progn (setq str_prompt (strcat " Offset Distance <" old_dst ">: ")) (setq off_dst (getreal str_prompt)) (if (not off_dst) (setq off_dst (atof old_dst)) ) ) (setq off_dst (getdist " Offset Distance: ")) ) (setenv "MULTIOFF_LASTDST" (rtos off_dst 2 3)) (setq pt3 (getpoint " Offset point: ")) (setq pickset1 (ssadd)) (princ " Select objects: ") (setq ss (ssget)) (setq i 0) (while (< i (sslength ss)) (setq obj (ssname ss i)) (command "_.offset" off_dst obj pt3 "") (setq elast (entlast)) (command "_.chprop" elast "" "_la" "OffsetLines" "_color" "1" "") (ssadd elast pickset1) (setq i (1+ i)) ) (sssetfirst nil pickset1) (princ) )2 points
-
And this is the small variation that best fits what @leonucadomi is asking for, I think. With the peculiarity that the "jog" will be placed where the selection is made with the pickbox. ; Original by RonJonP, edited by P. Kenewell and GLAVCVS (defun c:ltx (/ e o s le to l) (setvar "cmdecho" 0) (command "._undo" "_be") (while (and (setq e (car (setq l (entsel "\rSelect a TEXT, MTEXT or DIMENSION...")))) (wcmatch (cdr (assoc 0 (setq le (entget e)))) "*TEXT,DIMENSION")) (setq o (vlax-ename->vla-object e)) (cond ((= "TEXT" (setq to (cdr (assoc 0 le)))) (vla-put-textstring o (strcat "%%O" (vl-string-subst "" "" (vl-string-subst "" "%%O" (vla-get-textstring o)) ) ) ) ) ((= "MTEXT" to) (vla-put-textstring o (strcat "\\O" (vl-string-subst "" "" (vl-string-subst "" "\\O" (vla-get-textstring o)) ) ) ) ) ((= "DIMENSION" to) (if (not (tblsearch "APPID" "ACAD_DSTYLE_DIMJAG_POSITION")) (regapp "ACAD_DSTYLE_DIMJAG_POSITION") ) (entmod (append le (list (list -3 (list "ACAD_DSTYLE_DIMJAG_POSITION" '(1070 . 387) '(1070 . 3) '(1070 . 389) (cons 1010 (cadr l))))))) (if (= (vla-get-textoverride o) "") (vla-put-textoverride o "\\O<>") (vla-put-textoverride o (strcat "\\O" (vl-string-subst "" "" (vl-string-subst "" "\\O" (vla-get-textoverride o)) ) ) ) ) ) ) ) (command "._undo" "_end") (setvar "cmdecho" 1) (princ) )2 points
-
Its incomplete code and only uses vla-object names showing best practice for using cond. Use the original code setting e type outside the cond to check instead of using enget for each cond check. with dimensions you use entget three times, mtext two times. its probably only saving ms of time. ; Original by RonJonP, edited by P. Kenewell and GLAVCVS (defun c:ltx (/ o s pt i p1 p2 le typ) (setvar "cmdecho" 0) (command "._undo" "_be") (if (setq s (ssget ":L" '((0 . "*TEXT,DIMENSION")))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq typ (cdr (assoc 0 (entget e)))) (setq o (vlax-ename->vla-object e)) (cond ((= "TEXT" typ) ... ) Every time you are using enget its returning something like this. ( (0 . "MTEXT") ; saving this bit (5 . "1F2") (330 . <owner>) (100 . "AcDbEntity") (67 . 0) (8 . "TextLayer") (100 . "AcDbMText") (10 100.0 200.0 0.0) (40 . 2.5) (41 . 50.0) (71 . 1) (72 . 5) (1 . "This is a multiline text") (7 . "Standard") (210 0.0 0.0 1.0) (11 100.0 200.0 0.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (73 . 1) (44 . 0.0) (45 . 0.0) (90 . 0) (91 . 1) (92 . 0) (93 . 0) (94 . 0) (95 . 0) )2 points
-
Also you can return the vla-object list with foreach by wrapping it in mapcar. eliminating having to use (setq o (vlax-ename->vla-object e)). Pulling the vla-object name before the cond means your checking the variable rather then check the entity up to 3 times. ; Original by RonJonP, edited by P. Kenewell, updated by Mhupp (defun c:ltx (/ D O S) (vl-load-com) (setq D (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark D) (if (setq s (ssget ":L" '((0 . "*TEXT,DIMENSION")))) (foreach o (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) (setq typ (vla-get-ObjectName o)) (cond ((= typ "AcDbText") (vla-put-textstring o (strcat "%%O" (vl-string-subst "" "" (vl-string-subst "" "%%O" (vla-get-textstring o))))) ) ((= typ "AcDbMText") ... ) ((= typ "AcDbDimension") ... ) ) ) ) (vla-endundomark D) (princ) ) -edit also useing the (vla-startundomark allows you to have things selected before you run the command.2 points
-
That isn't complete code it's just a layout of what to do. You had the getcoords function in your original post. -edit You can see this post to pull cords from an polyline without its own function https://www.cadtutor.net/forum/topic/76319-add-block-onto-polyline-vertices/#findComment-603350 (setq PTLST1 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget PL1))))1 point
-
This is an awesome application. The problem is I need another license. I have purchased a couple in the past and need another for a new computer. I can't get through the checkout without an error - "We're sorry, your session has expired. Please go back to the vendor website and place your order again." I have tried dozens of times, different browsers, devices, etc. Tried contacting debalance.com, 2Checkout says contact debalance, tried emailing Alexey. Can't get any help.1 point