Leaderboard
Popular Content
Showing content with the highest reputation on 05/31/2022 in all areas
-
Try this ... does not check for locked layers. (defun c:foo (/ a i o s) (if (setq s (ssget "_X" '((0 . "TEXT") (1 . "* .#,* .##,* .###")))) (foreach e (mapcar 'cadr (ssnamex s)) (setq a (vla-get-textstring (setq o (vlax-ename->vla-object e)))) (setq i (vl-string-position 32 a 0 t)) (vla-put-textstring o (substr a 1 i)) ) ) (princ) )3 points
-
Probably, if the outerpolyline is always outside and the inner circles are always inside should be easy peasy1 point
-
Hahaha That's spot on! Love that comment! So accurate. I will definitely test a handful individually/manually, and also on a small test directory so I ensure the end product is exactly what I want. You totally rock man!1 point
-
Glad you could make use it. Definitely test it out before shredding a directory of drawings. The filter will only grab end numbers up to 3 digits long so if there are any longer than that just keep adding # like so separated by commas: (1 . "* .#,* .##,* .###,* .####,* .#####")1 point
-
@Steven P I will certainly consider all of your helpful information and apply this towards developing and testing something to achieve what I am looking for! Thanks for posting here I truly appreciate it! Hey if you take a stab at it and succeed then more power to you! Kudos to you for being awesome! I will keep at it on and off throughout my day when I have time. Will post updates as they come along. Cheers1 point
-
How is your LISP programming? I haven't looked at this yet however if you can make up a LISP routine then the following might make some sense? Thinking quickly, Lee Mac has a string to List LISP, perhaps if you can use ssget to get the text and mtexts into a selection set (and perhaps other text types, dimensions or whatever if necessary). Loop through the selection set and use Lee Macs string to List using a '.' as the deliminator, checking the last list item - a check for string length (should be 3 characters long), and a check to see if it is a number (atoi ? ) - if it is not an error the last 4 characters of the text string is a number ".xyz".. maybe look for stringsearch to delete that or, since you have a list all ready strcat the list items with a '.' (the deliminator) between each.. apart from the last list item.. which will give the new text string, then something like vl-put-textstring or entmod that text item from the selection set. Hope that makes sense and might give you a way to go? Got stuff to do this evening, else might be tempted to have a go for you,1 point
-
For better understanding, and maybe get further help, please upload such sample.dwg and LSP1 point
-
Steven P already knows it and solves it. I do unnecessary thing.1 point
-
did yo0u try the code I suggested above? That works OK on my computer.....1 point
-
; CNC - 2022.05.31 exceed ; https://www.cadtutor.net/forum/topic/75276-an-offset-marco-for-cnc-plasma-cutting-process/ ; ; Works on closed polylines, circles. ; Objects with the largest area are offset outward, others are offset inward. ; ; Command List ; CNC - do offset ; @Q - Save and close all opened drawings. Dialogs do not appear individually when closing each drawing. Appears only once for confirmation. ; ; The color is designated as number 3 (green). The layer does not change. ; ; When you add this Lisp to your starter set, it will work automatically every time you open a drawing. ; Open multiple drawings and save and close them all with the @Q command. ; If you want to manually, add ; in front of (c:CNC) to make ;(c:CNC), ; it will work when manually entering CNC ; ; Note ; If you reopen a drawing that has already been executed and saved, it will be created again. ; In this part, it seems to be necessary to add a statement that does not execute if there is a green object in the drawing. ; Your green looks different than mine, so I didn't add this code. (vl-load-com) (defun c:CNC ( / offsetvalue ss ssl index arealist obj objarea objlist outerloopobj outeroffset otherloop otherlooplen index2 otherloopobj inneroffset ) ;(setq offsetvalue 10) (setq offsetvalue (getreal "\n Input offset value : ")) (if (= offsetvalue nil) (progn (princ "\n you cancel CNC offset command") (exit)) ) (setq ss (ssget "X" '((0 . "LWPOLYLINE,CIRCLE")))) (setq ssl (sslength ss)) (setq index 0) (setq arealist '()) (repeat ssl (setq obj (vlax-ename->vla-object (ssname ss index))) (setq objarea (vla-get-area obj)) (setq objlist (list obj objarea)) (setq arealist (cons objlist arealist)) (setq index (+ index 1)) ) (setq arealist (vl-sort arealist (function (lambda (x1 x2) (> (cadr x1) (cadr x2)) ) ))) (setq outerloopobj (car (car arealist))) (setq outeroffset (ex:offsetout outerloopobj offsetvalue)) (vlax-put-property outeroffset 'color 3) (setq otherloop (cdr arealist)) (setq otherlooplen (length otherloop)) (setq index2 0) (repeat otherlooplen (setq otherloopobj (car (nth index2 otherloop))) (setq inneroffset (ex:offsetin otherloopobj offsetvalue)) (vlax-put-property inneroffset 'color 3) (setq index2 (+ index2 1)) ) (princ) ) (defun ex:offsetin ( obj offdis / subloop1 subloop2 subloop1type subloop2type subloop1length subloop2length objloop) (vla-offset obj (* offdis 1)) (setq subloop1 (vlax-ename->vla-object (entlast))) (vla-offset obj (* offdis -1)) (setq subloop2 (vlax-ename->vla-object (entlast))) (setq subloop1type (vlax-get-property subloop1 'entityname)) (setq subloop2type (vlax-get-property subloop2 'entityname)) (cond ((= subloop1type "AcDbPolyline") (setq subloop1length (vlax-get-property subloop1 'length)) ) ((= subloop1type "AcDbCircle") (setq subloop1length (vlax-get-property subloop1 'Circumference)) ) ((= subloop1type "AcDbArc") (setq subloop1length (vlax-get-property subloop1 'Radius)) ) );end of cond (cond ((= subloop2type "AcDbPolyline") (setq subloop2length (vlax-get-property subloop2 'length)) ) ((= subloop2type "AcDbCircle") (setq subloop2length (vlax-get-property subloop2 'Circumference)) ) ((= subloop2type "AcDbArc") (setq subloop2length (vlax-get-property subloop2 'Radius)) ) );end of cond (cond ((> subloop1length subloop2length) (progn (vla-delete subloop1) (setq looplength subloop2length) (setq objloop subloop2))) ((< subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ((= subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ) objloop ) (defun ex:offsetout ( obj offdis / subloop1 subloop2 subloop1type subloop2type subloop1length subloop2length objloop) (vla-offset obj (* offdis 1)) (setq subloop1 (vlax-ename->vla-object (entlast))) (vla-offset obj (* offdis -1)) (setq subloop2 (vlax-ename->vla-object (entlast))) (setq subloop1type (vlax-get-property subloop1 'entityname)) (setq subloop2type (vlax-get-property subloop2 'entityname)) (cond ((= subloop1type "AcDbPolyline") (setq subloop1length (vlax-get-property subloop1 'length)) ) ((= subloop1type "AcDbCircle") (setq subloop1length (vlax-get-property subloop1 'Circumference)) ) ((= subloop1type "AcDbArc") (setq subloop1length (vlax-get-property subloop1 'Radius)) ) );end of cond (cond ((= subloop2type "AcDbPolyline") (setq subloop2length (vlax-get-property subloop2 'length)) ) ((= subloop2type "AcDbCircle") (setq subloop2length (vlax-get-property subloop2 'Circumference)) ) ((= subloop2type "AcDbArc") (setq subloop2length (vlax-get-property subloop2 'Radius)) ) );end of cond (cond ((< subloop1length subloop2length) (progn (vla-delete subloop1) (setq looplength subloop2length) (setq objloop subloop2))) ((> subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ((= subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ) objloop ) ; close all by Middleton, Cliff ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/early-christmas/m-p/777308/highlight/true#M2966 (defun C:@Q nil (cond ((= 6 (LM:popup "Close All with Save" "You want close all with save?" 36)) (@CloseWithSave) (command "_close" "n") ) (t (princ "\nCanceled")) ) (princ) ) (defun @CloseWithSave ( / cnt) (setq cnt (@CloseAllButActive :vlax-True)) (if (> cnt 0) (princ (strcat "\n[ " (itoa cnt) " ] " (if (> cnt 1) "s" "") "are saved and closed")) (princ "\nThere's no dwg for closing.") ) (princ) ) (defun @CloseAllButActive (TrueOrFalse / cnt) (setq cnt 0) (vlax-for Item (vla-get-Documents (vlax-get-acad-object)) (if (= (vla-get-Active Item) :vlax-False) (progn (vla-close Item TrueOrFalse) (setq cnt (1+ cnt)) ) ) ) cnt ) ;; Popup - Lee Mac ;; A wrapper for the WSH popup method to display a message box prompting the user. ;; ttl - [str] Text to be displayed in the pop-up title bar ;; msg - [str] Text content of the message box ;; bit - [int] Bit-coded integer indicating icon & button appearance ;; Returns: [int] Integer indicating the button pressed to exit (defun LM:popup ( ttl msg bit / wsh rtn ) (if (setq wsh (vlax-create-object "wscript.shell")) (progn (setq rtn (vl-catch-all-apply 'vlax-invoke-method (list wsh 'popup msg 0 ttl bit))) (vlax-release-object wsh) (if (not (vl-catch-all-error-p rtn)) rtn) ) ) ) (c:CNC) now you can, - If you don't enter a value (space bar or esc), doesn't run it. - It will work as long as you don't enter too large a value inward. (For example, if you have a circle with a diameter of 10, offset 11 inward.) if you don't want it to run on every open, Remove the last (c:CNC) from notepad But it will ask you every time the drawing is opened. This is so the first version to write directly into the code might be better. you can edit this by ; Edit 10 in (setq offsetvalue 10) to adjust the offset length1 point
-
; CNC - 2022.05.31 exceed ; https://www.cadtutor.net/forum/topic/75276-an-offset-marco-for-cnc-plasma-cutting-process/ ; ; Works on closed polylines, circles. ; Objects with the largest area are offset outward, others are offset inward. ; ; Command List ; CNC - do offset ; @Q - Save and close all opened drawings. Dialogs do not appear individually when closing each drawing. Appears only once for confirmation. ; ; The color is designated as number 3 (green). The layer does not change. ; ; Edit 10 in (setq offsetvalue 10) to adjust the offset length ; ; When you add this Lisp to your starter set, it will work automatically every time you open a drawing. ; Open multiple drawings and save and close them all with the @Q command. ; If you want to manually, add ; in front of (c:CNC) to make ;(c:CNC), ; it will work when manually entering CNC ; ; Note ; If you reopen a drawing that has already been executed and saved, it will be created again. ; In this part, it seems to be necessary to add a statement that does not execute if there is a green object in the drawing. ; Your green looks different than mine, so I didn't add this code. (vl-load-com) (defun c:CNC ( / offsetvalue ss ssl index arealist obj objarea objlist outerloopobj outeroffset otherloop otherlooplen index2 otherloopobj inneroffset ) (setq offsetvalue 10) (setq ss (ssget "X" '((0 . "LWPOLYLINE,CIRCLE")))) (setq ssl (sslength ss)) (setq index 0) (setq arealist '()) (repeat ssl (setq obj (vlax-ename->vla-object (ssname ss index))) (setq objarea (vla-get-area obj)) (setq objlist (list obj objarea)) (setq arealist (cons objlist arealist)) (setq index (+ index 1)) ) (setq arealist (vl-sort arealist (function (lambda (x1 x2) (> (cadr x1) (cadr x2)) ) ))) (setq outerloopobj (car (car arealist))) (setq outeroffset (ex:offsetout outerloopobj offsetvalue)) (vlax-put-property outeroffset 'color 3) (setq otherloop (cdr arealist)) (setq otherlooplen (length otherloop)) (setq index2 0) (repeat otherlooplen (setq otherloopobj (car (nth index2 otherloop))) (setq inneroffset (ex:offsetin otherloopobj offsetvalue)) (vlax-put-property inneroffset 'color 3) (setq index2 (+ index2 1)) ) (princ) ) (defun ex:offsetin ( obj offdis / subloop1 subloop2 subloop1type subloop2type subloop1length subloop2length objloop) (vla-offset obj (* offdis 1)) (setq subloop1 (vlax-ename->vla-object (entlast))) (vla-offset obj (* offdis -1)) (setq subloop2 (vlax-ename->vla-object (entlast))) (setq subloop1type (vlax-get-property subloop1 'entityname)) (setq subloop2type (vlax-get-property subloop2 'entityname)) (cond ((= subloop1type "AcDbPolyline") (setq subloop1length (vlax-get-property subloop1 'length)) ) ((= subloop1type "AcDbCircle") (setq subloop1length (vlax-get-property subloop1 'Circumference)) ) ((= subloop1type "AcDbArc") (setq subloop1length (vlax-get-property subloop1 'Radius)) ) );end of cond (cond ((= subloop2type "AcDbPolyline") (setq subloop2length (vlax-get-property subloop2 'length)) ) ((= subloop2type "AcDbCircle") (setq subloop2length (vlax-get-property subloop2 'Circumference)) ) ((= subloop2type "AcDbArc") (setq subloop2length (vlax-get-property subloop2 'Radius)) ) );end of cond (cond ((> subloop1length subloop2length) (progn (vla-delete subloop1) (setq looplength subloop2length) (setq objloop subloop2))) ((< subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ((= subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ) objloop ) (defun ex:offsetout ( obj offdis / subloop1 subloop2 subloop1type subloop2type subloop1length subloop2length objloop) (vla-offset obj (* offdis 1)) (setq subloop1 (vlax-ename->vla-object (entlast))) (vla-offset obj (* offdis -1)) (setq subloop2 (vlax-ename->vla-object (entlast))) (setq subloop1type (vlax-get-property subloop1 'entityname)) (setq subloop2type (vlax-get-property subloop2 'entityname)) (cond ((= subloop1type "AcDbPolyline") (setq subloop1length (vlax-get-property subloop1 'length)) ) ((= subloop1type "AcDbCircle") (setq subloop1length (vlax-get-property subloop1 'Circumference)) ) ((= subloop1type "AcDbArc") (setq subloop1length (vlax-get-property subloop1 'Radius)) ) );end of cond (cond ((= subloop2type "AcDbPolyline") (setq subloop2length (vlax-get-property subloop2 'length)) ) ((= subloop2type "AcDbCircle") (setq subloop2length (vlax-get-property subloop2 'Circumference)) ) ((= subloop2type "AcDbArc") (setq subloop2length (vlax-get-property subloop2 'Radius)) ) );end of cond (cond ((< subloop1length subloop2length) (progn (vla-delete subloop1) (setq looplength subloop2length) (setq objloop subloop2))) ((> subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ((= subloop1length subloop2length) (progn (vla-delete subloop2) (setq looplength subloop1length) (setq objloop subloop1))) ) objloop ) ; close all by Middleton, Cliff ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/early-christmas/m-p/777308/highlight/true#M2966 (defun C:@Q nil (cond ((= 6 (LM:popup "Close All with Save" "You want close all with save?" 36)) (@CloseWithSave) (command "_close" "n") ) (t (princ "\nCanceled")) ) (princ) ) (defun @CloseWithSave ( / cnt) (setq cnt (@CloseAllButActive :vlax-True)) (if (> cnt 0) (princ (strcat "\n[ " (itoa cnt) " ] " (if (> cnt 1) "s" "") "are saved and closed")) (princ "\nThere's no dwg for closing.") ) (princ) ) (defun @CloseAllButActive (TrueOrFalse / cnt) (setq cnt 0) (vlax-for Item (vla-get-Documents (vlax-get-acad-object)) (if (= (vla-get-Active Item) :vlax-False) (progn (vla-close Item TrueOrFalse) (setq cnt (1+ cnt)) ) ) ) cnt ) ;; Popup - Lee Mac ;; A wrapper for the WSH popup method to display a message box prompting the user. ;; ttl - [str] Text to be displayed in the pop-up title bar ;; msg - [str] Text content of the message box ;; bit - [int] Bit-coded integer indicating icon & button appearance ;; Returns: [int] Integer indicating the button pressed to exit (defun LM:popup ( ttl msg bit / wsh rtn ) (if (setq wsh (vlax-create-object "wscript.shell")) (progn (setq rtn (vl-catch-all-apply 'vlax-invoke-method (list wsh 'popup msg 0 ttl bit))) (vlax-release-object wsh) (if (not (vl-catch-all-error-p rtn)) rtn) ) ) ) (c:CNC)1 point
-
Just to get you going a bit, this should return the entity name of the largest area polyline in your drawing. Command LineArea (defun PolyLineArea ( MyPolyLineEntName / MyArea) (setq MyPolyLine (vlax-ename->vla-object MyPolyLineEntName)) (setq MyArea (vla-get-Area MyPolyLine) ) MyArea ) ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/find-the-largest-number-in-a-list-of-numbers/td-p/816742 (defun maxinlist (x / next highest) (setq next 0) (setq highest (nth 0 x)) ; Assumes that the first item in the list is the highest. Then iterates through every number in the list (while (< next (1- (length x))) (setq highest (max highest (nth (1+ next) x))) (setq next (1+ next)) ) highest ) ) (defun c:LineArea ( / MyPolyLineEntName Acount AreaList) (vl-load-com) ;;Load VL (setq AreaList (list)) ;;Blank List (setq Acount 0) ;; Set a counter to 0 (setq ss (ssget "_A")) ;;select set, all visible objexts, change A to X for all objects (while (< acount (sslength ss)) ;;Loop through selection Set, ss (setq MyPolyLineEntName (ssname ss Acount)) ;;nth entity in ss name (setq AreaList (append AreaList (list (PolyLineArea MyPolyLineEntName)) )) ;;get object area from PolyLineArea function above (setq Acount (+ Acount 1)) ;;increase counter ) (setq largestEntity (ssname ss (vl-position (maxinlist AreaList) AreaList) )) ;; the perimeter entity name using maxinlist function above ) and I reckon if you look to MHUPPs above that will let you offset the perimeter and remove that from the selection set list, , then you can offset all that is left in the other direction, add something to save and close the file and job done? Will come back to look at this tomorrow1 point
-
To tell the machine what you want to do, have to think more step by step. You may have questions such as: Q1. Does 1 dwg contain only 1 part? Q2. Doesn't one dwg contain objects that are not parts and have nothing to do with parts? If you YES these 2 questions, you can add all polylines to the selection set with (ssget "X" '((0 . "LWPOLYLINE"))) and then mark the polyline with the largest area as the outside. Q3. Are there any isolated objects like donuts in your parts? this case make some headache.. If you don't have donuts, you just have to offset them all to the small side. But with donuts, a problem arises. It may be better to auto-assign the isolate using a hatch. This is just example, I recently used command HATCH to group objects into a selection set. (BMP3) https://www.cadtutor.net/forum/topic/75162-bmp-file-to-polyline-mosaic/ And when offsetting a closed polyline, you need to know whether the polyline is drawn clockwise or counterclockwise to determine the direction of the outer or inner offset. This is the correct way. but I think below is more understandable, 1. create inside & outside both polylines 2. determine the outside if the length is long & the inside if the length is short 3. and delete what you don't need. This Link is example I wrote this way. Lisp that repeatedly offsets the inside of a shape until it is impossible to offset it. https://www.cadtutor.net/forum/topic/74957-inside-offset-multiple/ This allows you to use the offset in any direction without considering the order of the nodes. It's not a good way because to create something you don't need and then delete it. But for a beginner like me, this was more intuitive. And, It is generally impossible to use Lisp in multiple drawings, so i recommend using it with a script. However, if you have difficulties with the script, there is a simple way to register Lisp in the startup set, make Lisp run automatically when opened, then open all DWGs manually, then save and close at once. with CLOSEALL command1 point
-
Mhupp I think I got this from PBE. Note for Bricscad use Pedit Plent R. ;; get closed polygon's area (defun ss-pts2area (l) (/ (apply (function +) (mapcar (function (lambda (x y) (- (* (car x) (cadr y)) (* (car y) (cadr x))))) (cons (last l) l) l)) 2.) ) ;_force pointset CCW (setq plent (entsel "\nPick pline")) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))) (if (< (ss-pts2area co-ord) 0) (command "reverse" plent) )1 point
-
Maybe this. ; Pline segment with angle (defun c:plseg( / oldsnap pick plobj pick2 param segemnt co-ord pt1 pt2 ang) (setq plent (entsel "\nSelect Pline or line ")) (setq oldsnap (getvar 'osmode)) (setvar "osmode" 0) (cond ((= (cdr (assoc 0 (entget (car plent)))) "LWPOLYLINE") (setq pick (cadr plent) plObj (vlax-ename->vla-object (car plent)) pick2 (vlax-curve-getclosestpointto plobj pick) param (vlax-curve-getparamatpoint plObj pick2) segment (fix param) co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))) pt1 (nth segment co-ord) pt2 (nth (+ segment 1) co-ord)) ) ((= (cdr (assoc 0 (entget (car plent)))) "LINE") (setq lObj (vlax-ename->vla-object (car plent)) pt1 (vlax-curve-getstartPoint lobj) pt2 (vlax-curve-getEndPoint lobj)) ) ((alert "incorrect object selected Pline or line")) ) (setq ang (angle pt1 pt2)) (alert (strcat "angle is " (rtos (/ (* ang 180.0) pi) 2 2) )) (setvar 'osmode oldsnap) (princ) )1 point