Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/10/2023 in all areas

  1. i have it working guys, so long story short, i should have read "ALL" of the header test of the Steal.lsp, and not just some (lesson learned the hard way, but learned non the less).. So Lee has already made this lisp program accessible as a sub function also So with the following code (tweaked from mhupp's above... my thanks once more) it now does exactly what I need from a new page (defun c:GetLastFile (/ Filsys FilObj DatMod lst nfilepath) (setq FilSys (vlax-create-object "Scripting.FileSystemObject") path "C:\\Workflow" ) (foreach F (vl-directory-files path "*.DWG" 1) (setq FilObj (vlax-invoke FilSys 'GetFile (strcat path "\\" F)) DatMod (vlax-get FilObj 'DateLastModified) lst (cons (cons F DatMod) lst) ) ) (vlax-release-object FilObj) (vlax-release-object FilSys) (setq lst (mapcar '(lambda (l) (car (nth l lst))) (vl-sort-i lst '(lambda (d1 d2) (> (cdr d1) (cdr d2)))))) ;(setq nfile (car lst)) ;newest file in folder (setq nfilepath (strcat path "\\" (car lst))) ;or if you need the full path (Steal nfilepath '( ( "Blocks" ("*") ) ( "Layers" ("*") ) ( "Dimension Styles" ("*") ) ( "Text Styles" ("*") ) ( "Multileader Styles" ("*") ) ) ) (Princ "\nPrior Order Data import finished") (princ) ) My thanks again to everyone that helped... You guys rock!
    2 points
  2. I started from scratch. Is this how you want is? Bottom function: adapt the text height to your likings . Now: (setq hgt 2.5) ;;1. promt the user to select multiple polygons. ;;2. in a loop: ;; a. calculate each polygon area. ;; b. insert the area text in the geometric center of each polygon (vl-load-com) ;; Multiple assoc. Returns a list of all requested (assoc) with set key ; use like this (massoc 10 YourListOfData) (defun massoc (key alist / x nlist) (foreach x alist (if (eq key (car x)) (setq nlist (cons (cdr x) nlist)) ) ) (reverse nlist) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/ (defun drawText (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 1 str)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; main function (defun wamp (pline hgt / area pt str vert_pts x y p) (setq area (vla-get-area (vlax-ename->vla-object pline) )) ;; get the vertex positions. (setq vert_pts (massoc 10 (entget pline))) (setq x 0.0) (setq y 0.0) ;; Then calculate the average. Sum of x and y values divided by the number of vertices (foreach p vert_pts (setq x (+ x (nth 0 p))) (setq y (+ y (nth 1 p))) ) (setq pt (list (/ x (length vert_pts)) (/ y (length vert_pts)) )) ;; make a string out of the area float. Here would be the place to add a prefix or postfix. Example: ;; (setq str (strcat "area: " (rtos area 2 3) )) (setq str (rtos area 2 3)) ;; that 3 means 3 decimals. Feel free to change this (drawText pt hgt str) (princ ) ) ;; WAMP for Write Area in the Middle of Polyline (defun c:wamp ( / pline ss i hgt) ;; User setting. Set to your liking (setq hgt 2.5) ;; user selects polylines (princ "\nSelect polylines: ") (setq ss (ssget (list (cons 0 "*POLYLINE")))) ;; loop of the elements (setq i 0) (repeat (sslength ss) (setq pline (ssname ss i)) (wamp pline hgt) (setq i (+ i 1)) ) )
    2 points
  3. @Emmanuel Delay I have one more question - Iv'e tried to change the rext justification to middle center like this: ;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/ (defun drawText (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 73 2) (cons 72 1) (cons 1 str)))) but when I do that all the text items are put to 0,0,0 (ignore cons 10 pt). is there a way to fix it? *EDIT: cons 11 is the solution... when using cons 72 & cons 73 must assign the insertion point to cons 11 as well.. ;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/ (defun drawText (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 11 pt) (cons 10 pt) (cons 40 (getvar "TEXTSIZE")) (cons 7 (getvar "TEXTSTYLE")) (cons 73 2) (cons 72 1) (cons 1 str)))) I've also attched a screenshot from the DXF Reference guide (Capture1.JPG)
    1 point
  4. @Emmanuel Delay AMAIZING- THANKS!! how complicate is to do the same for selection by internal point like the second lisp I have posted (Area_To_Text_Boundery_M2A.lsp)? I looked for an exampels of creating a selection set by choosing internal points like in the command for a single object: (command "-Boundary" a "") but could'nt find any. many thanks, aridzv.
    1 point
  5. If it's for graphics, make that circle a block and create a mask with a hatch that is color 255,255,255.
    1 point
  6. *Side-note About using gcen method. This didn't work so well with plots of land that shared borders with each other. I think it had to do with the draw order. But it sometimes it was picking the geo center of the adjacent plots so it wasn't 100% accurate. This is what i used to check CW of a polyline. See example at start of lisp. will offset + or - depending on CW function. ;;----------------------------------------------------------------------------;; ; Checking if pline drawn CW or CCW - Writer Evgeniy Elpanov By Bill Gilliss ;(vla-offset (vlax-ename->vla-object entity) (if (CW entity) -0.01 0.01)) (defun CW (poly / lw lst LL UR) (setq lw (vlax-ename->vla-object poly)) (vla-GetBoundingBox lw 'LL 'UR) (setq LL (vlax-safearray->list LL) UR (vlax-safearray->list UR) lst (mapcar (function (lambda (x) (vlax-curve-getParamAtPoint poly (vlax-curve-getClosestPointTo poly x) ) ) ) (list LL (list (car LL) (cadr UR)) UR (list (car UR) (cadr LL)) ) ) ) (if (or (<= (car lst) (cadr lst) (caddr lst) (cadddr lst)) (<= (cadr lst) (caddr lst) (cadddr lst) (car lst)) (<= (caddr lst) (cadddr lst) (car lst) (cadr lst)) (<= (cadddr lst) (car lst) (cadr lst) (caddr lst)) ) ;_ or t ) ) --Edit Another way is to offset with "both" option. Then check area of the polylines. tho if you have some funky shapes their could be more then two polylines created.
    1 point
  7. Just quickly some hints and will think about this shortly. You can use reverse to alter reverse a list of points, or here http://www.theswamp.org/index.php?topic=50007.msg552346#msg552346 This might come in useful, working out where the centre of the shape is (setq p (osnap (vlax-curve-getStartPoint (entlast)) "gcen")) if you want to do some thinking but an internet search comes up with this thread https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/polyline-direction-clockwise-or-counterclockwise/td-p/6050612 which I think this is the good stuff:: (defun ListClockwise-p (lst / z vlst) (vl-catch-all-apply 'minusp (list (if (not (equal 0.0 (setq z (apply '+ (mapcar (function (lambda (u v) (- (* (car u) (cadr v)) (* (car v) (cadr u))) ) ) (setq vlst (mapcar (function (lambda (a b) (mapcar '- b a)) ) (mapcar (function (lambda (x) (car lst))) lst) (cdr (reverse (cons (car lst) (reverse lst)))) ) ) (cdr (reverse (cons (car vlst) (reverse vlst)))) ) ) ) 1e-6 ) ) z (progn (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list") nil ) ) ) ) )
    1 point
  8. Depends on whats in the text file. This lisp would make points listed in a text file. Each line was. <PointID> <Easting> <Northing> <Elevation> If all your getting is one value stick with prompts. this will save the variable Dist into the drawing file as ldata. When you run the command again it will remember last input. (or (setq *dist (vlax-ldata-get "Distance" "Dist")) (setq *dist 0.83)) (if (setq dist (getdist (strcat "\nSpecify Distance [" (rtos *dist 2 2) "]: "))) (vlax-ldata-put "Distance" "Dist" dist) ;updates with new distance (vlax-ldata-put "Distance" "Dist" (setq dist *dist)) )
    1 point
  9. I'm pleased that you find my website useful in your studies. As dexus has subsequently pointed out, the getattributes method will return an array (or list when using vlax-invoke) of attribute reference objects; you'll need to obtain the tagstring property for an object in the list returned. It may be clearer to evaluate each expression through the Visual LISP IDE console, so that you can see the value returned by each expression.
    1 point
  10. Try this (vl-load-com) ;; LW Vertices - Lee Mac ;; Returns a list of lists in which each sublist describes ;; the position, starting width, ending width and bulge of the ;; vertex of a supplied LWPolyline (defun LM:LWVertices ( e ) (if (setq e (member (assoc 10 e) e)) (cons (list (assoc 10 e) (assoc 40 e) (assoc 41 e) (assoc 42 e) ) (LM:LWVertices (cdr e)) ) ) ) ;; Tangent - Lee Mac ;; Args: x - real (defun tan ( x ) (if (not (equal 0.0 (cos x) 1e-10)) (/ (sin x) (cos x)) ) ) ;; ;; Heavily inspired (I hope that's okay) by ;; http://www.lee-mac.com/addpolyvertex.html ;; I took the user input out of the function, they're now parameters of the function. ;; Nor does it error check much. ;; (defun addVertexToLWPolyline ( e p on_pline / a b e h l n p r v w x z p_orig) (if (and p e (setq p_orig p p (vlax-curve-getclosestpointto e (trans p 1 0)) n (vlax-curve-getparamatpoint e p) ) ) (if (not (equal n (fix n) 1e-8)) (progn (setq e (entget e) h (reverse (member (assoc 39 e) (reverse e))) v (assoc 90 h) l (LM:LWVertices e) z (assoc 210 e) ) (repeat (fix n) (setq a (cons (car l) a) l (cdr l) ) ) (setq x (car l) r (- n (fix n)) w (cdr (assoc 40 x)) w (+ w (* r (- (cdr (assoc 41 x)) w))) b (atan (cdr (assoc 42 x))) ) ;; if on_pline is nil, then we keep the opiginal point given by the user (if on_pline T (setq p p_orig) ) ;;(LM:startundo (LM:acdoc)) (entmod (append (subst (cons 90 (1+ (cdr v))) v h) (apply 'append (reverse a)) (list (assoc 10 x) (assoc 40 x) (cons 41 w) (cons 42 (tan (* r b))) (cons 10 (trans p 0 (cdr z))) (cons 40 w) (assoc 41 x) (cons 42 (tan (* (- 1.0 r) b))) ) (apply 'append (cdr l)) (list z) ) ) ;;(LM:endundo (LM:acdoc)) ) ) ) e ;; return the modified polyline ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Polyline Add Vertex At Leader (defun c:paval ( / pline leaders i pts pt en ins) (setq pline (car (entsel "\nSelect polyline: "))) (princ "\nNow select the leaders: ") (setq leaders (ssget (list (cons 0 "LEADER")))) (setq i 0) (repeat (sslength leaders) ;; pt is the first (assoc 10) of the leader (setq pt (cdr (assoc 10 (entget (ssname leaders i))))) (princ "\n") (princ pt) (setq en (addVertexToLWPolyline pline pt nil )) (setq i (+ i 1)) ) (princ) )
    1 point
  11. Just posted this over at theSwamp, thought I'd share it with you fine people also. I was inspired to write a few functions that will generate entities using the minimum possible data requirements - hence all other values are taken as default. This is handy for those who want to quickly generate entities without having to look up what codes are necessary, and which are surplus to requirement. Also, it helps beginners to use the entmake function in their codes, without too much effort. These, of course, are the quickest way to generate entities in AutoCAD - quicker than VL, and much quicker than a command call. Also, they are not affected by OSnap (so no need to turn it off). Example of usage, to create a line from (0,0,0) to (1,0,0): (Line '(0 0 0) '(1 0 0)) Yes, its as easy as that. The functions will also return the entity name of the newly created entity (if successful), and so, no need to be using 'entlast'... If you have any queries as to how to use them, just ask. (defun 3DFace (p1 p2 p3 p4) (entmakex (list (cons 0 "3DFACE") (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)))) (defun Arc (cen rad sAng eAng) (entmakex (list (cons 0 "ARC") (cons 10 cen) (cons 40 rad) (cons 50 sAng) (cons 51 eAng)))) (defun AttDef (tag prmpt def pt hgt flag) (entmakex (list (cons 0 "ATTDEF") (cons 10 pt) (cons 40 hgt) (cons 1 def) (cons 3 prmpt) (cons 2 tag) (cons 70 flag)))) (defun Circle (cen rad) (entmakex (list (cons 0 "CIRCLE") (cons 10 cen) (cons 40 rad)))) (defun Ellipse (cen maj ratio) (entmakex (list (cons 0 "ELLIPSE") (cons 100 "AcDbEntity") (cons 100 "AcDbEllipse") (cons 10 cen) (cons 11 maj) (cons 40 ratio) (cons 41 0) (cons 42 (* 2 pi))))) (defun Insert (pt Nme) (entmakex (list (cons 0 "INSERT") (cons 2 Nme) (cons 10 pt)))) (defun Line (p1 p2) (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)))) (defun LWPoly (lst cls) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)) (mapcar (function (lambda (p) (cons 10 p))) lst)))) (defun M-Text (pt str) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 str)))) (defun Point (pt) (entmakex (list (cons 0 "POINT") (cons 10 pt)))) (defun Polyline (lst) (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)))) (mapcar (function (lambda (p) (entmake (list (cons 0 "VERTEX") (cons 10 p))))) lst) (entmakex (list (cons 0 "SEQEND")))) (defun Solid (p1 p2 p3 p4) (entmakex (list (cons 0 "SOLID") (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)))) (defun Text (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 1 str)))) (defun Trce (p1 p2 p3 p4) (entmakex (list (cons 0 "TRACE") (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)))) (defun xLine (pt vec) (entmakex (list (cons 0 "XLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbXline") (cons 10 pt) (cons 11 vec)))) (defun Layer (Nme) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0)))) (defun Layer (Nme Col Ltyp LWgt Plt) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0) (cons 62 Col) (cons 6 Ltyp) (cons 290 Plt) (cons 370 LWgt)))) The list is a working progress of course, but this is what I have so far. Also, if the argument names aren't too clear, a reference as to what they mean can be found here. Lee
    1 point
  12. entmake: If successful, entmake returns the entity's list of definition data. entmakex: If successful, entmakex returns the name of the entity created Depending on what you intend to do with the entity once it is created.
    1 point
×
×
  • Create New...