Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/29/2024 in all areas

  1. Try something like this - change the value of the two variables at the top of the code to suit: (defun c:test ( / bln idx lst nla pat ) (setq pat "*block*" nla "NewLayer" pat (strcase pat) ) (if (setq sel (ssget '((0 . "INSERT")))) (repeat (setq idx (sslength sel)) (setq idx (1- idx) bln (cdr (assoc 2 (entget (ssname sel idx)))) ) (if (not (member bln lst)) (progn (setq lst (cons bln lst)) (processblock bln pat nla) ) ) ) ) (princ) ) (defun processblock ( bln str lay / ent ) (if (setq ent (tblobjname "block" bln)) (while (setq ent (entnext ent)) (processobject ent str lay) ) ) ) (defun processobject ( ent str lay / bln enx ) (cond ( (not (setq enx (entget ent)))) ( (/= "INSERT" (cdr (assoc 0 enx)))) ( (not (wcmatch (setq bln (strcase (cdr (assoc 2 enx)))) str)) (processblock bln str lay) ) ( (entmod (subst (cons 8 lay) (assoc 8 enx) enx)) (processblock bln str lay) ) ) ) (princ)
    3 points
  2. as always you make it look so easy master Lee
    2 points
  3. @Jozef13 ;; Change this (setq blockname (cdr (assoc 2 (entget blkobj)))) ;; To this (setq blockname (getpropertyvalue blkobj "BlockTableRecord/Name")) ;; Then change this (setq sel (ssget (list (cons 0 "INSERT") (cons 2 blockname)))) ;; To this (if (setq sel (ssget (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blockname))))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex sel))) (or (= blockname (getpropertyvalue e "BlockTableRecord/Name")) (ssdel e sel)) ) )
    1 point
  4. @Highvoltage That's fine, but I need to fix it for my own satisfaction. FWIW - try this version. It gets the width in a different way. (defun c:mbch (/ _StrParse a b bb d dw obj ss tls txt wid) (vl-load-com) (vla-StartUndoMark (setq d (vla-get-activedocument (vlax-get-acad-object)))) (defun _StrParse (str del / pos) (if (and str del) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (_StrParse (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) ) (princ "\nSelect MTEXT Objects: ") (if (setq ss (ssget '((0 . "MTEXT")))) (repeat (setq n (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))) txt (vla-get-textstring obj) dw (vla-get-width obj) bb (vla-GetBoundingBox obj 'a 'b) wid (- (car (vlax-Safearray->List b)) (car (vlax-Safearray->List a))) wid (+ wid (* wid 0.05)); add 5% to width, can be adjusted tls (_strparse txt "\\P") tls (apply 'append (mapcar '(lambda (x)(_strparse x "\\N")) tls)) txt (if (> (length tls) 1) (apply 'strcat (cons (car tls)(mapcar '(lambda (x)(strcat " " x)) (cdr tls)))) (car tls) ) ) (vla-put-textstring obj txt) (if (= dw 0.0)(vla-put-width obj wid)) ) ) (redraw) (vla-endundomark d) (princ) ) EDIT: I Realized I could shorten it even more because I had some unnecessary conditional statements, and tested MTEXT with various codes, determining that the only other common string code that creates a return in MTEXT is "\N" in uppercase. lowercase "\p" and "\n" codes are not accepted as returns. Nor does "\X" work in MTEXT like it does in a Dimension.
    1 point
  5. Z is easy, add (rtos (caddr p) 2) to this line (strcat ";;" (rtos (car p) 2) ";" (rtos (cadr p) 2)) to be (strcat ";;" (rtos (car p) 2) ";" (rtos (cadr p) 2) ";" (rtos (caddr p) 2)) Layer you'll need to add something line (setq lay (cdr (assoc 8 e)) ) maybe in here (setq e (entget (ssname s (setq i (1- i)))) p (cdr (assoc 10 e)) lay (cdr (assoc 8 e)) ;;Layer ) and add lay into the (strcat..... ) line above like this: (strcat ";;" (rtos (car p) 2) ";" (rtos (cadr p) 2) ";" (rtos (caddr p) 2) ";" lay)
    1 point
  6. FYI... ChatGBT does not do lisp well. it can sometimes get you close but I have found personally a 85% failure rate. It makes up functions. Sometimes it's funny what it calls them... Sometimes it fills enough gaps so that if you know lisp you can fill in the needed parts. I do hope it gets better...
    1 point
  7. Code posting guidelines When you are posting AutoLISP or VBA code in these forums, there are some simple guidelines you should observe in order to make life easier for you and for others. Always add routines or code snippets using the Code option. This makes them easier to read within posts by making them distinct from other text. It helps those who may want to copy and paste the code. It also helps to save space because code blocks get a scroll bar beyond a certain number of lines. 1. Click the Code button on the editor toolbar. That's the one with the "<>" on it. You will then see the Code modal, shown below. 2. Type or paste your code into the text box. 3. Select "No Syntax Highlighting" from the drop-down. 4. Click Insert into post. 5. Add any instructions or additional commentary to your post. 6. Click Submit Reply (or Submit Topic if you are starting a new topic). See the next post in this topic for the final result. Please ensure that you have the right to publish code on a public forum. In most cases, the code you are publishing will be your own and it will be assumed that if no attribution is given, you are the author. However, if you are not the author, you must make this clear and where possible, give credit to the author. Any routines published here must have their header intact, including any title, instructions, author contact details, date and copyright information. If at all possible, please make sure that you have the author's permission to publish their work. You may, at your discretion, claim specific copyright over your code. All authors have the right to explicitly claim copyright of their code. We recommend that if you wish to do so, you use a standard form such as Creative Commons.
    1 point
×
×
  • Create New...