Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/17/2025 in Posts

  1. As we say here in NL : garantie tot aan de deur I've updated RlxPaste in attempt to handle dynamic blocks a little different than the normal cut/copy stuff. At this time it only works (if it works at all) when you select 1 dynamic block to add. It checks if block is dynamic or not. If so , it reads all dymanic properties of this block (I nicked a couple of Grand Master Lee's routines but don't tell him ) Save the block (under a different name of course because you can't save a block with the same name as the dwg) Then it writes all properties to a text file in the same folder & same name as the block but with extenion dbd (dynamic block data). Theory is that after insert it reads this dbd file and puts all props back. If it works , oh happy day , if it doesn't this conversation never happend... RlxPaste.LSP
    2 points
  2. I kept most of your code. What I added: - code to determine if a point is inside a closed polyline. What the code does is cast a RAY (half a XLINE, just to one side) from said point (being the insert point of the MTEXT). If that ray touches/intersects the polyline an odd number of times, then the point is inside. - You don't have to select the MTEXT. You select the polyline, then the script will select all MTEXTS and only rotate the MTEXTS that are inside the polyline (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; This section is all about determining if a point is inside a closed polyline (defun c:testray ( / pt) (drawxRay (setq pt (getpoint "\nPoint: ")) (list 1.0 0.0)) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun drawxRay (pt vec) (entmakex (list (cons 0 "RAY") (cons 100 "AcDbEntity") (cons 100 "AcDbRay") (cons 10 pt) (cons 11 vec)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Intersections - Lee Mac ;; http://www.lee-mac.com/intersectionfunctions.html ;; Returns a list of all points of intersection between two objects ;; for the given intersection mode. ;; ob1,ob2 - [vla] VLA-Objects ;; mod - [int] acextendoption enum of intersectwith method ;; acextendnone Do not extend either object ;; acextendthisentity Extend obj1 to meet obj2 ;; acextendotherentity Extend obj2 to meet obj1 ;; acextendboth Extend both objects (defun LM:intersections ( ob1 ob2 mod / lst rtn ) (if (and (vlax-method-applicable-p ob1 'intersectwith) (vlax-method-applicable-p ob2 'intersectwith) (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)) ) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst) ) ) ) (reverse rtn) ) ;; what this function does: from point pt we draw a RAY to the right. We detect intersections of the ray with the closed polyline. ;; => if the number of intersections is odd -> this means the point is inside the polygon, and the ray exits the polygon at the last intersection. ;; => if the number of intersections is even (0, 2, 4...) -> the point is outside the polygon. The ray doesn't intersect, or it enters then exits... (defun point_inside_closed_polyline (pt pline / ray ins) (setq ray (drawxRay pt (list 1.0 0.0))) (setq ins (LM:intersections (vlax-ename->vla-object pline) (vlax-ename->vla-object ray) acextendnone )) ;; delete the ray (entdel ray) (if (= 0 (rem (length ins) 2)) nil T) ;; (rem number 2) returns 1 when number is odd, 0 when even. We return T when odd, nil when even ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:RotateMtext ( / ent mtexts i mtext is_inside pt entObj mtextObj vertices longestSide longestAngle p1 p2 dist) ;; don't forget these. Local variables must be listed like this. (setq ent (car (entsel "\nSelect enclosed polyline: "))) ;; this selects all MTEXTS (setq mtexts (ssget "_x" (list (cons 0 "MTEXT") ))) (setq i 0) (repeat (sslength mtexts) ;;(setq mtext (car (entsel "\nSelect MTEXT: "))) (setq mtext (ssname mtexts i)) (setq is_inside (point_inside_closed_polyline (setq pt (cdr (assoc 10 (entget mtext)))) ent)) (if (and ent mtext is_inside) (progn (setq entObj (entget ent)) (setq mtextObj (entget mtext)) (if (eq (cdr (assoc 0 entObj)) "LWPOLYLINE") (progn (setq vertices '()) (foreach item entObj (if (or (eq (car item) 10) (eq (car item) 11)) (setq vertices (append vertices (list (cdr item)))) ) ) (setq longestSide 0 longestAngle 0) (repeat (- (length vertices) 1) (setq p1 (nth 0 vertices) p2 (nth 1 vertices)) (setq vertices (cdr vertices)) (setq dist (distance p1 p2)) (if (> dist longestSide) (progn (setq longestSide dist) (setq longestAngle (angle p1 p2)) ) ) ) (setq mtextObj (subst (cons 50 longestAngle) (assoc 50 mtextObj) mtextObj)) (entmod mtextObj) (princ "\nMTEXT rotated successfully.") ) (princ "\nSelected entity is not a polyline.") ) ) (princ "\nInvalid selection.") ) (setq i (+ i 1)) ) (princ) ) Happy with this?
    1 point
  3. Hi Maahee I think it's hard to know what your code is supposed to do. Without knowing this, it's hard to get anyone to respond to you.
    1 point
×
×
  • Create New...