Having trouble with this lisp program to offset the dimensions automatically from the polyline

Having trouble with this lisp program to offset the dimensions automatically from the polyline

thomas_huntFMPXR
Contributor Contributor
173 Views
1 Reply
Message 1 of 2

Having trouble with this lisp program to offset the dimensions automatically from the polyline

thomas_huntFMPXR
Contributor
Contributor

The image below shows the latest offset correction doesn't comly with command. any tips to correct this.

 

(defun c:RDD_Roofdimn ( / ent obj coords n i j p1 p2 mid offset object_offset offset_direction)

;; Set or create dimension layer
(if (tblsearch "layer" "PV-TEXT-DIMN")
(setvar "clayer" "PV-TEXT-DIMN")
(command "._LAYER" "_Make" "PV-TEXT-DIMN" "")
)

;; Prompt for polyline
(setq ent (car (entsel "\nSelect 2D closed polyline (roof outline): ")))

(if (and ent (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE"))
(progn
(setq obj (vlax-ename->vla-object ent))

;; Check if closed
(if (not (= (vla-get-Closed obj) :vlax-true))
(progn
(prompt "\nPolyline is not closed.")
(command "._UNDO" "_End")
(exit)
)
)

;; Determine offset direction
(setq object_offset (car (vlax-invoke obj 'Offset 150.0)))
(setq offset_direction (if (> (vla-get-Area object_offset) (vla-get-Area obj)) -2 2))
(vla-delete object_offset)r

;; Get polyline coordinates
(setq coords (vlax-get obj 'Coordinates))
(setq n (/ (length coords) 2))
(setq i 0)
(setq offset 100.0)

;; Loop through vertices
(while (< i n)
(setq p1 (list (nth (* i 2) coords) (nth (+ 1 (* i 2)) coords) 2.0))
(setq j (if (= i (- n 1)) 0 (+ i 1)))
(setq p2 (list (nth (* j 2) coords) (nth (+ 1 (* j 2)) coords) 2.0))

;; Midpoint for dimension placement
(setq mid (polar
(mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2)
(+ (* -1.5 pi) (angle p1 p2))
(* offset_direction offset)
))

;; Place dimension
(command "._DIMALIGNED" p1 p2 mid)

(setq i (1+ i))
)
(prompt (strcat "\n" (itoa n) " aligned dimensions placed."))
)
(prompt "\nInvalid selection. Please select a closed LWPOLYLINE.")
)

(princ)
)

0 Likes
Accepted solutions (1)
174 Views
1 Reply
Reply (1)
Message 2 of 2

Kent1Cooper
Consultant
Consultant
Accepted solution

If I understand what the indecipherable image is supposed to show, my first guess is that you are doing it with some running Object Snap mode(s) on, since the routine does not account for that.  Turn off Osnap -- does it work right?  Accounting for it can easily be built into the routine.

Kent Cooper, AIA