Leaderboard
Popular Content
Showing content with the highest reputation on 06/28/2023 in all areas
-
The following should handle any layout naming convention, either retaining or ignoring leading zeroes: (defun c:copylayout ( / cmd lyt new ) (cond ( (= 1 (getvar 'tilemode)) (princ "\nCommand only available in paperspace.") ) ( (setq cmd (getvar 'cmdecho) lyt (getvar 'ctab) new lyt ) (setvar 'cmdecho 0) (repeat (progn (initget 6) (cond ((getint "\nNumber of layouts to create <1>: ")) (1)) ) (while (member (setq new (LM:suffix++ new)) (layoutlist))) (vl-cmdf "_.-layout" "_c" lyt new) (setq lyt new) ) (setvar 'cmdecho cmd) ) ) (princ) ) (defun LM:suffix++ ( str ) (cond ( (wcmatch str "~*#") (strcat str "1") ) ( (wcmatch str "*9") (strcat (LM:suffix++ (substr str 1 (1- (strlen str)))) "0") ) ( (strcat (substr str 1 (1- (strlen str))) (chr (1+ (ascii (substr str (strlen str))))) ) ) ) ) (princ) I don't think LT fully supports VL/ActiveX, and so the automatic layout ordering may not be possible, but on the off-chance that it does, give this a try: (defun c:sortlayouts ( / lst ord tab ) (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= :vlax-false (vla-get-modeltype lyt)) (setq lst (cons lyt lst) ord (cons (strcase (vla-get-name lyt)) ord) ) ) ) (setq tab 1) (foreach idx (vl-sort-i ord 'compare) (vla-put-taborder (nth idx lst) tab) (setq tab (1+ tab)) ) (princ) ) (defun compare ( a b / x y ) (setq x (ascii a) y (ascii b) ) (cond ( (zerop x)) ( (zerop y) nil) ( (= x y) (compare (substr a 2) (substr b 2))) ( (and (< 47 x 58) (< 47 y 58)) (< (atof a) (atof b)) ) ( (< x y)) ) ) (vl-load-com) (princ)2 points
-
Not a problem, (and if Stephen was the worst I am ever called I'd be a happy man.....)1 point
-
I'm so sorry I called you Stephen back there. Thank you again Steven. Everything is working the way I wanted to.1 point
-
I've updated the code quickly - it will put the filename in if there are no green lines selected, I'll need to copy and paste in some proper error checking though to do anything other than that - will be later maybe1 point
-
Try this one, it should put the filename in all the green boxes (noting this includes the green box in the border), plus filename in the origin (0,0) - try it and see and let me know any comments (defun C:foo ( / varf ins str MySS) ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/zoom-object-problem/td-p/5031146 (defun GetCentre (ent / minPt maxPt ll ur inspt) ;; gets the centre of the entity bounding box-ish (vla-GetBoundingBox (vlax-ename->vla-object ent) 'minPt 'maxpt ) (setq ll (car (cons (vlax-safearray->list minPt) ll)) ur (car (cons (vlax-safearray->list maxPt) ur)) ) (setq inspt (list (/ (+ (car ll) (car ur)) 2) (/ (+ (cadr ll) (cadr ur)) 2)) ) ) (defun MakeText ( ins txt / ) (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans ins 1 0)) (cons 40 0.8);Text height (cons 1 txt) (cons 7 "STANDARD");Text style '(1 . "") ) ; end list ) ; end entmakex ) ; end defun ; Selecting Polyline (setq varf (list '(-4 . "<OR") '(0 . "LWPOLYLINE") '(-4 . "<AND") '(0 . "POLYLINE") '(-4 . "<NOT") '(-4 . "&") '(70 . 80) '(-4 . "NOT>") '(-4 . "AND>") '(-4 . "OR>") (cons 62 3) ) ) (sssetfirst nil (setq MySS (ssget "_X" varf))) ;; ADDED A NAME TO THE SELECTION SET (if MySS (progn ; Inverting selection (if (ssget "_I") (progn; then (sssetfirst nil) (command "_.select" "_all" "_remove" (ssget "_p") "") ;; could also do 'remove' MySS (sssetfirst nil (ssget "_p")) ) ; end progn (prompt "\nRequires pre-selection."); else ) ; end if ; Delete Selection (command "_.erase") ; Insert Drawing Name (and (or (> (getvar 'DWGTITLED) 0) (alert "Save the drawing then try again!") ) ; end or (setq acount 0) (while (< acount (sslength MySS)) (setq ins (GetCentre (ssname MySS acount) ) ) (setq str (MakeText ins (vl-filename-base (getvar "dwgname"))) ) (setq acount (+ acount 1)) ) ; end while ) ; end and ) ; end progn 'if MySS' (setq str (MakeText (list 0 0 0) (vl-filename-base (getvar "dwgname"))) ) ) ; end if 'if MySS' (princ) )1 point
-
Thank you Stephen, - Not necessarily, filename can also be as string text. - All of the green polylines the better.1 point
-
As a start I'll post this and see where you go from there. I've put your entmakex part into a sub-routine - easier for the next step where you insert the filename at the origin (saves copying the code twice) and copied in a small routine to get the centre point of an entity bounding box. Also gave your selection set a name (MySS) to make it easier to refer to later. So this should now put the fllename in the centre of the first polyline in the selection set. Do you need the filename in all the polylines (the green boxes) ? noting in your example there are 2. We can add a loop through the selection set (MySS) to do that Wasn't looking at your drawing properly then, will need to delete the green outline that is in the border so the LISPs don't get confused as what to look at. I'll assume that the detail is always in the bottom of the border, that is below the green outlie that you want to keep? For the filenames, is there a reason that you want to insert that as a field or can it just be inserted straight as a text string? (noting you mention conditional checking comes later) Can modify this later if you let me know about the filename - in all the green boxes or not and enter as a string or field? (defun C:foo ( / varf ins str MySS) ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/zoom-object-problem/td-p/5031146 (defun GetCentre (ent / minPt maxPt ll ur) (vla-GetBoundingBox (vlax-ename->vla-object ent) 'minPt 'maxpt ) (setq ll (car (cons (vlax-safearray->list minPt) ll)) ur (car (cons (vlax-safearray->list maxPt) ur)) ) (setq inspt (list (/ (+ (car ll) (car ur)) 2) (/ (+ (cadr ll) (cadr ur)) 2)) ) ) (defun MakeText ( ins / ) (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (trans ins 1 0)) (cons 40 0.8);Text height (cons 7 "STANDARD");Text style '(1 . "") ) ; end list ) ; end entmakex ) ; end defun ; Selecting Polyline (setq varf (list '(-4 . "<OR") '(0 . "LWPOLYLINE") '(-4 . "<AND") '(0 . "POLYLINE") '(-4 . "<NOT") '(-4 . "&") '(70 . 80) '(-4 . "NOT>") '(-4 . "AND>") '(-4 . "OR>") (cons 62 3) ) ) (sssetfirst nil (setq MySS (ssget "_X" varf))) ;; ADDED A NAME TO THE SELECTION SET ; Inverting selection (if (ssget "_I") (progn; then (sssetfirst nil) (command "_.select" "_all" "_remove" (ssget "_p") "") (sssetfirst nil (ssget "_p")) ) (prompt "\nRequires pre-selection."); else ) ; Delete Selection (command "_.erase") ; And This is how I insert Drawing Name (and (or (> (getvar 'DWGTITLED) 0) (alert "Save the drawing then try again!") ) ;; (setq ins (getpoint "\nChoose Insertion Point: ")) (setq ins (GetCentre (ssname MySS 0) ) ) (setq str (MakeText ins) ) (vla-put-textstring (vlax-ename->vla-object str) "%<\\AcVar Filename \\f \"%tc4%fn2\">%}" ) ) ) No doubt there will be other suggestions but this is based on what you have made up so far1 point
-
1 point
-
1 point
-
Like Steven P you can get the co-ordinates of a pline, then replace or even replace all co-ordinates. So post a before after dwg.1 point
-
What does dumpit show for a mpolygon. Hopefully co-ordinates. ;;;===================================================================; ;;; DumpIt ; ;;;-------------------------------------------------------------------; ;;; Dump all methods and properties for selected objects ; ;;;===================================================================; (defun C:Dumpit ( / ent) (while (setq ent (entsel "\n pick object ")) (vlax-Dump-Object (vlax-Ename->Vla-Object (car ent)) ) ) (princ) )1 point
-
For Hassan, just to note that I love these types of questions "this isn't working, please help" - but of course, no description of what isn't working and any errors that your CAD throws up when you ty to run the LISP. Following what SW210 says your code looks to be inconplete, finishing with (foreach termination terminations (setq termination-xy (list (car (cdr (assoc I have never used ChatGPT, actually quite enjoy working out the puzzles that LISP throws up by myself, but I gather you ask it questions and set out the procedure you want the LISP to do, so my next question should be easy - what do you want the LISP to do exactly? Assuming again that you want it to speed up a process you do just now, what is this process? For example: 1. Set the cabinet radius 2. Set the cabinet positions 3. Loop to set the cabinet positions and so on (Noting here that ChatGPT uses its best guess of internet searches to produce a code but won't test what it says actually works as required(1 point
-
@Hassan95 Maybee I'm off-topic, but: Did you seriously aked a AI? And then you want the forum to finish this job? I wonder how long it will take, AIs register this forum, begging for help yust my 2 cts Wolfgang1 point
-
You posted on the weekend, be patient. Please use code tags, <> in the menu bar in the reply box. Your code looks incomplete, is that all of it?1 point