Quick Dimension with fixed spacing from object

Quick Dimension with fixed spacing from object

Anonymous
Not applicable
5,067 Views
20 Replies
Message 1 of 21

Quick Dimension with fixed spacing from object

Anonymous
Not applicable

 Hi, I`m new here and what I`m going to ask was probably asked before. can you please point me the discussion about dimension with fixed spacing from the object. I`ve been using an LSP that can do that to all sides of a polyline, but I just need to learn or have an LSP that can do that to 1 side only, if possible. thanks a lot.

0 Likes
5,068 Views
20 Replies
Replies (20)
Message 2 of 21

devitg
Advisor
Advisor

please show your lisp, and sample dwg, with a before and after. 

 

Message 3 of 21

Moshe-A
Mentor
Mentor

@Anonymous hi,

 

if i understand what you want then no automation is need here:

 

you need to define your dimstyle + set a Fixed length extension lines length (and make it current)

then use DIMLIN or DIMALI commands and use <select object> option (just by hitting enter) and the rest autocad will do - NO?

 

moshe

 

Message 4 of 21

Anonymous
Not applicable

Thanks for the reply, much appreciated.

I've been using this LSP (Dimpoly.lsp) I got which I forgot where, CTTO, and it's been helping me a lot.

It put dimensions in all sides of a selected object with fixed location.

But there are instances which I just need to quickly put a dimension in 1 side, 

just like in my attached photo.

There's also this AD.lsp (ctto), it could have done what I wanted but it needed the spacing/location to be

indicated every time, which is a bit troublesome.

Is there a way this could be set 1 time and modify as per drawing standard.

Thanks in advance.

0 Likes
Message 5 of 21

devitg
Advisor
Advisor

please show your lisp, and sample dwg, with a before and after. 

0 Likes
Message 6 of 21

Anonymous
Not applicable

I already attached a sample drawing and the LSP I am using in my previous reply.

0 Likes
Message 7 of 21

Anonymous
Not applicable

DimPoly.lsp

 

;;  DimPoly.lsp [command names: DPI = Dimension Polyline(s) Inside, DPO = Outside]
;;  To dimension the lengths of all segments of selected Polylines on the Inboard or
;;    Outboard side.  For self-intersecting or open Polyline without a clear "inside" and
;;    "outside," will determine a side -- if not as desired, undo and run other command.
;;  Dimensions along arc segments will be angular Dimensions, showing length of arc
;;    as text override, not included angle native to angular Dimensions.  They will not
;;    update if Polyline is stretched, as those along line segments will; redo DPI/DPO.
;;  Uses current Dimension and Units settings; dimension line location distance from
;;    Polyline segment = 1.5 x dimension text height for stacked fractions to clear [see
;;    commentary at setting of dtxt variable re: stacked fractions].
;;  Accepts LW and 2D "heavy" Polylines, but not 3D Polylines or meshes.  Rejects any
;;    on locked Layers, because of Offset used to determine inside/outside.
;;  Kent Cooper, last edited 18 May 2016
(vl-load-com)
(defun DP (side / *error* doc svnames svvals styht dpss n pl cw inc pt1 pt3 pt2 ang1 ang2 dtxt pt4)
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (mapcar 'setvar svnames svvals); reset System Variables
    (vla-endundomark doc)
    (princ)
  ); defun -- *error*
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (setq ; System Variable saving/resetting without separate variables for each:
    svnames '(osmode cmdecho blipmode clayer)
    svvals (mapcar 'getvar svnames)
  ); setq
  (mapcar 'setvar svnames '(0 0)); turn off Osnap, command echoing
  (command "_.layer" "_make" "ST-DIM" "_color" 8 "" "");; <---EDIT Layer name/color as desired
  (setq styht (cdr (assoc 40 (tblsearch "style" (getvar 'dimtxsty))))); height of text style in current dimension style
  (if (= styht 0.0) (setq styht (* (getvar 'dimtxt) (getvar 'dimscale)))); if above is non-fixed-height
  (prompt (strcat "\nTo Dimension Polyline(s) on the " side "side,"))
  (if (setq dpss (ssget "_:L" '((0 . "*POLYLINE"))))
    (progn ; then [can omit this if you never use blips; also two other lines below]
      (setvar 'blipmode 0); [omit if you never use blips and omitted line above]
      (repeat (setq n (sslength dpss)); step through selection set
        (setq pl (ssname dpss (setq n (1- n))))
        (if (= (logand (cdr (assoc 70 (entget pl))) 88) 0)
          ;; not 3D or mesh [88 = 8 (3D) + 16 (polygon mesh) + 64 (polyface mesh)]
          (progn ; then
            (setq pl (vlax-ename->vla-object pl))
            (vla-offset pl styht); temporary
            (setq cw (< (vla-get-area (vlax-ename->vla-object (entlast))) (vla-get-area pl)))
              ;; clockwise for closed or clearly inside/outside open; may not give
              ;; desired result for open without obvious inside/outside
            (entdel (entlast))
            (repeat (setq inc (fix (vlax-curve-getEndParam pl))); segments
              (setq
                pt1 (vlax-curve-getPointAtParam pl inc)
                pt3 (vlax-curve-getPointAtParam pl (1- inc))
              ); setq
              (if (not (equal pt1 pt3 1e-8)); not coincident vertices
                (progn ; then -- proceed to dimension segment
                  (setq
                    pt2 (vlax-curve-getPointAtParam pl (- inc 0.5)); segment midpoint
                    ang1 (angle pt1 pt2)
                    ang2 (angle pt2 pt3)
                  ); setq
                  (if
                    (or ; line segment?
                      (equal ang1 ang2 1e-8); any non-0 direction or both reading as 0 or 2 pi
                      (equal (abs (- ang2 ang1)) (* pi 2) 1e-8); 0-degree with one reading as 2 pi +/-
                    ); or
                    (command "_.dimaligned" pt1 pt3); then [leaves at dimension line location prompt]
                    (progn ; else [arc segment]
                      (setq dtxt
                        (rtos
                          (abs ; length along arc segment
                            (- (vlax-curve-getDistAtParam pl inc) (vlax-curve-getDistAtParam pl (1- inc)))
                          ); abs
                          ;; [include mode/precision here if current dimension style's settings not desired]
                        ); rtos
                      ); setq
                      (if (wcmatch dtxt "*/*"); includes fraction?
                        ;; can omit this entire (if) function if you don't use stacked fractions
                        (setq dtxt ; stack it
                          (strcat
                            "\\A1;"
                            (vl-string-subst ";}\"" "\""
;                              (vl-string-subst "#" "/"
                                ;; remove ; from beginning of above line and its closing parenthesis line
                                ;; below to make diagonal stack [makes horizontal-line stack without]
                                (vl-string-subst "{\\H0.875x;\\S" " " dtxt)
                                  ;; change 0.875 ratio to agree with Dimension Style's setting
;                              ); -subst
                            ); -subst
                          ); strcat & dtxt
                        ); setq
                      ); if
                      (command
                        "_.dimangular" ""
                        (inters ; arc center
                          (setq pt4 (mapcar '/ (mapcar '+ pt1 pt2) '(2 2 2)))
                          (polar pt4 (+ (angle pt1 pt2) (/ pi 2)) 1)
                          (setq pt4 (mapcar '/ (mapcar '+ pt2 pt3) '(2 2 2)))
                          (polar pt4 (+ (angle pt2 pt3) (/ pi 2)) 1)
                          nil
                        ); inters
                        pt1 pt3
                        "_text" dtxt
                      ); command [leaves at dimension line location prompt]
                    ); progn
                  ); if
                  (command ; complete Dimension: dimension line location
                    (polar
                      pt2
                      (apply ; angle
                        (if (or (and cw (= side "in")) (and (not cw) (= side "out"))) '- '+)
                        (list
                          (angle '(0 0 0) (vlax-curve-getFirstDeriv pl (- inc 0.5)))
                          (/ pi 2)
                        ); list
                      ); apply
                      (* styht 3.125); distance
                        ;; [If you don't use stacked fractions, consider using styht without multiplier]
                    ); polar
                  ); command
                ); progn
              ); if [not coincident]
              (setq inc (1- inc))
            ); repeat [segments]
          ); progn -- then [LW/2D]
        ); if
      ); repeat [Polylines]
    ); progn -- then [valid selection]; [omit if you never use blips and omitted 2 lines above]
    (prompt "\nNo Polyline(s) on unlocked Layer(s) selected."); else
  ); if
  (mapcar 'setvar svnames svvals); reset System Variables
  (vla-endundomark doc)
  (princ)
); defun -- DP
(defun C:DPI () (DP "in")); = Dimension Polyline Inside
(defun C:DPO () (DP "out")); = Dimension Polyline Outside
(prompt "\nType DPI to Dimension Polyline(s) on the Inside, DPO to do so on the Outside.")
0 Likes
Message 8 of 21

Anonymous
Not applicable

AD.lsp

 

(defun c:AD (/ p1 p2 p3 Udist)
      (setq udist (getreal "\nOffset Distance :"))
      (setq p1 (getpoint "\n Specify first extension line origin :"))
      (setq p2 (getpoint "\n Specify first extension line origin :"))
      (setq P3 (polar P2 (+ (angle p1 p2)(/ pi 2)) udist))
      (command "_.dimaligned" "_non" p1 "_non" p2 "_m" "" P3)
(while
      (setq p1 (getpoint "\n Specify first extension line origin :"))
      (setq p2 (getpoint "\n Specify first extension line origin :"))
      (setq P3 (polar P2 (+ (angle p1 p2)(/ pi 2)) udist))
      (command "_.dimaligned" "_non" p1 "_non" p2 "_m" "" P3)
)
  (princ)
)

0 Likes
Message 9 of 21

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

this lisp does noting more than DIMLIN \ DIMALI standard AutoCAD commands. when you will have time, explore "Fixed length extension lines length" on DIMSTYLE and you will see what i'm talking about.

 

 

 

 

0 Likes
Message 10 of 21

kibitotato
Advocate
Advocate

I like this lisps. Im wondering about having the AD.lsp with a prefixed distance like DPI DPO... Is it possible?

0 Likes
Message 11 of 21

kibitotato
Advocate
Advocate

I tried to do by myself by I doesnt works...

 

(defun c:AD (/ p1 p2 p3 Udist)
(setq udist (getreal "\nOffset Distance :" ss "0,15"))
(setq p1 (getpoint "\n Specify first extension line origin :"))
(setq p2 (getpoint "\n Specify first extension line origin :"))
(setq P3 (polar P2 (+ (angle p1 p2)(/ pi 2)) udist))
(command "_.dimaligned" "_non" p1 "_non" p2 "_m" "" P3)
(while
(setq p1 (getpoint "\n Specify first extension line origin :"))
(setq p2 (getpoint "\n Specify first extension line origin :"))
(setq P3 (polar P2 (+ (angle p1 p2)(/ pi 2)) udist))
(command "_.dimaligned" "_non" p1 "_non" p2 "_m" "" P3)
)
(princ)
)

0 Likes
Message 12 of 21

ВeekeeCZ
Consultant
Consultant

Is this what you want to have?

 

(defun c:AD10 (/ p1 p2 p3 Udist)
  (setq udist 10)
  (setq p1 (getpoint "\n Specify first extension line origin :"))
  (setq p2 (getpoint "\n Specify first extension line origin :"))
  (setq P3 (polar P2 (+ (angle p1 p2)(/ pi 2)) udist))
  (command "_.dimaligned" "_non" p1 "_non" p2 "_m" "" P3)
  (while
    (setq p1 (getpoint "\n Specify first extension line origin :"))
    (setq p2 (getpoint "\n Specify first extension line origin :"))
    (setq P3 (polar P2 (+ (angle p1 p2)(/ pi 2)) udist))
    (command "_.dimaligned" "_non" p1 "_non" p2 "_m" "" P3)
    )
  (princ)
  )

 

Message 13 of 21

kibitotato
Advocate
Advocate

exactly thanks

0 Likes
Message 14 of 21

ahmadshabrawy_98
Explorer
Explorer

I would like to edit this lisp to ask me about the distance from the object

here is the lisp

 

;-------------------------------------------------------------------------------
; Program Name: AutoDPL - Dimension Polylines
; Created By: https://www.youtube.com/@CivilSurvey/featured
;
; Function: Dimensions Polyline shapes
;-------------------------------------------------------------------------------
; Revision History
; Rev By Date Description
;-------------------------------------------------------------------------------
; 1 TM 5-20-08 Initial version
;-------------------------------------------------------------------------------
; c:autoDPL - Dimensions Polyline
;-------------------------------------------------------------------------------
(defun c:AutoDPL (/ EntName^ EntPick@)
(setvar "CMDECHO" 0)
(if (setq EntPick@ (entsel "\nSelect Polyline to dimension: "))
(if (= (cdr (assoc 0 (entget (car EntPick@)))) "LWPOLYLINE")
(progn
(setq EntName^ (cdr (assoc -1 (entget (car EntPick@)))))
(DimPL EntName^)
);progn
);if
);if
(if (not EntName^)
(princ "\nNo Polyline selected.")
);if
(princ)
);defun c:DPL
;-------------------------------------------------------------------------------
; DimPL - Function to dimension Polyline
; Arguments: 1
; EntName^ = Polyline entity name
; Returns: Dimensions Polyline
;-------------------------------------------------------------------------------
(defun DimPL (EntName^ / Bottom@ Clayer$ CW# DiffAng DimPts: DimSpace~ EntList@
Item LastAng~ LastPt Left@ List@ NW@ Osmode# P0 P1 P2 Pt Pts@ PtsLen Right@ SE@
Top@ X~ X1~ X1Y1 X1Y2 X1Ys@ X2~ X2Y1 X2Y2 X2Ys@ XPts@ Y~ Y1~ Y1X1 Y1X2 Y1Xs@ Y2~
Y2X1 Y2X2 Y2Xs@ YPts@)
;-----------------------------------------------------------------------------
(defun DimPts: (Pts@ StartPt EndPt Type$ / Add Num1~ Num2~ Nums1@ Nums2@ P1 P2
Pt Return@)
(setq Add t)
(foreach Pt (member StartPt (append Pts@ Pts@))
(if Add
(setq Return@ (append Return@ (list Pt)))
);if
(if (equal Pt EndPt)
(setq Add nil)
);if
);foreach
(foreach Pt Return@
(if (member Type$ (list "Left" "Right"))
(setq Nums1@ (append Nums1@ (list (cadr Pt))))
(setq Nums1@ (append Nums1@ (list (car Pt))))
);if
);foreach
(foreach Num1~ (vl-sort Nums1@ '<)
(setq Nums2@ nil)
(foreach Pt Return@
(if (member Type$ (list "Left" "Right"))
(if (= (cadr Pt) Num1~)
(setq Nums2@ (append Nums2@ (list (car Pt))))
);if
(if (= (car Pt) Num1~)
(setq Nums2@ (append Nums2@ (list (cadr Pt))))
);if
);if
);foreach
(if (member Type$ (list "Left" "Bottom"))
(setq Nums2@ (vl-sort Nums2@ '<))
(setq Nums2@ (reverse (vl-sort Nums2@ '<)))
);if
(foreach Num2~ (cdr Nums2@)
(if (member Type$ (list "Left" "Right"))
(setq Pt (list Num2~ Num1~))
(setq Pt (list Num1~ Num2~))
);if
(setq Return@ (vl-remove Pt Return@))
);foreach
);foreach
(cond
((= Type$ "Left")
(vl-sort Return@ (function (lambda (P1 P2)(< (cadr P1)(cadr P2)))))
);case
((= Type$ "Top")
(vl-sort Return@ (function (lambda (P1 P2)(< (car P1)(car P2)))))
);case
((= Type$ "Right")
(vl-sort Return@ (function (lambda (P1 P2)(> (cadr P1)(cadr P2)))))
);case
((= Type$ "Bottom")
(vl-sort Return@ (function (lambda (P1 P2)(> (car P1)(car P2)))))
);case
);cond
);defun DimPts:
;-----------------------------------------------------------------------------
(setq EntList@ (entget EntName^))
(if (= (cdr (assoc 0 EntList@)) "LWPOLYLINE")
(progn
(foreach List@ EntList@
(if (= (car List@) 10)
(if (not (equal (cdr List@) LastPt))
(progn
(setq Pts@ (append Pts@ (list (cdr List@))))
(if (> (length Pts@) 2)
(if (/= (angle LastPt (cdr List@)) LastAng~) (setq DiffAng t))
);if
(if (> (length Pts@) 1)
(setq LastAng~ (angle LastPt (cdr List@)))
);if
(setq LastPt (cdr List@))
);progn
);if
);if
);foreach
(if (equal (car Pts@) (last Pts@))
(setq Pts@ (reverse (cdr (reverse Pts@))))
);if
(setq PtsLen (length Pts@))
);progn
(exit)
);if
(foreach Pt Pts@
(setq X~ (atof (rtos (car Pt) 2 8))
Y~ (atof (rtos (cadr Pt) 2 8))
XPts@ (append XPts@ (list X~))
YPts@ (append YPts@ (list Y~))
Pts@ (cdr (append Pts@ (list (list X~ Y~))))
);setq
);foreach
(setq XPts@ (vl-sort XPts@ '<)
YPts@ (vl-sort YPts@ '<)
X1~ (car XPts@)
X2~ (last XPts@)
Y1~ (car YPts@)
Y2~ (last YPts@)
);if
(foreach Pt Pts@
(if (= (car Pt) X1~) (setq X1Ys@ (append X1Ys@ (list (cadr Pt)))))
(if (= (car Pt) X2~) (setq X2Ys@ (append X2Ys@ (list (cadr Pt)))))
(if (= (cadr Pt) Y1~) (setq Y1Xs@ (append Y1Xs@ (list (car Pt)))))
(if (= (cadr Pt) Y2~) (setq Y2Xs@ (append Y2Xs@ (list (car Pt)))))
);foreach
(setq X1Ys@ (vl-sort X1Ys@ '<)
X2Ys@ (vl-sort X2Ys@ '<)
Y1Xs@ (vl-sort Y1Xs@ '<)
Y2Xs@ (vl-sort Y2Xs@ '<)
X1Y1 (list X1~ (car X1Ys@))
X1Y2 (list X1~ (last X1Ys@))
X2Y1 (list X2~ (car X2Ys@))
X2Y2 (list X2~ (last X2Ys@))
Y1X1 (list (car Y1Xs@) Y1~)
Y1X2 (list (last Y1Xs@) Y1~)
Y2X1 (list (car Y2Xs@) Y2~)
Y2X2 (list (last Y2Xs@) Y2~)
Pts@ (member X1Y1 (append Pts@ Pts@))
);setq
(while (> (length Pts@) PtsLen)
(setq Pts@ (reverse (cdr (reverse Pts@))))
);while
(setq SE@ (member X2Y2 Pts@) NW@ Pts@)
(foreach Item SE@
(setq NW@ (vl-remove Item NW@))
);foreach
(setq SE@ (append SE@ (list X1Y1))
NW@ (append NW@ (list X2Y2))
CW# 0
);setq
(foreach Pt (list Y2X1 Y2X2)
(if (member Pt NW@) (setq CW# (1+ CW#)))
(if (member Pt SE@) (setq CW# (1- CW#)))
);foreach
(foreach Pt (list Y1X1 Y1X2)
(if (member Pt SE@) (setq CW# (1+ CW#)))
(if (member Pt NW@) (setq CW# (1- CW#)))
);foreach
(if (< CW# 0)
(setq Pts@ (append (list (car Pts@))(reverse (cdr Pts@))))
);if
(setq Left@ (DimPts: Pts@ Y1X1 Y2X1 "Left"))
(setq Top@ (DimPts: Pts@ X1Y2 X2Y2 "Top"))
(setq Right@ (DimPts: Pts@ Y2X2 Y1X2 "Right"))
(setq Bottom@ (DimPts: Pts@ X2Y1 X1Y1 "Bottom"))
;-----------------------------------------------------------------------------
(command "UNDO" "BEGIN")
(setq DimSpace~ (* (getvar "DIMSCALE") (getvar "DIMTXT") 3))
(setq Osmode# (getvar "OSMODE")) (setvar "OSMODE" 0)
(setq Clayer$ (getvar "CLAYER"))
(command "LAYER" "S" (GetDimLayer) "");<--Change to your Dim layer info
(setq P0 (polar X1Y1 pi (* DimSpace~ 1.5))
P1 (car Left@)
);setq
(foreach P2 (cdr Left@)
(command "DIM1" "VER" P1 P2 P0 "")
(setq P1 P2)
);foreach
(if (> (length Left@) 2)
(progn
(setq P0 (polar P0 pi DimSpace~))
(command "DIM1" "VER" (car Left@) (last Left@) P0 "")
);progn
);if
(setq P0 (polar Y2X1 (* pi 0.5) (* DimSpace~ 1.5))
P1 (car Top@)
);setq
(foreach P2 (cdr Top@)
(command "DIM1" "HOR" P1 P2 P0 "")
(setq P1 P2)
);foreach
(if (> (length Top@) 2)
(progn
(setq P0 (polar P0 (* pi 0.5) DimSpace~))
(command "DIM1" "HOR" (car Top@) (last Top@) P0 "")
);progn
);if
(setq P0 (polar X2Y2 0 (* DimSpace~ 1.5))
P1 (car Right@)
);setq
(if (and (> (length Right@) 2) DiffAng)
(foreach P2 (cdr Right@)
(command "DIM1" "VER" P1 P2 P0 "")
(setq P1 P2)
);foreach
);if
(setq P0 (polar Y1X2 (* pi 1.5) (* DimSpace~ 1.5))
P1 (car Bottom@)
);setq
(if (and (> (length Bottom@) 2) DiffAng)
(foreach P2 (cdr Bottom@)
(command "DIM1" "HOR" P1 P2 P0 "")
(setq P1 P2)
);foreach
);if
(setvar "CLAYER" Clayer$)
(setvar "OSMODE" Osmode#)
(command "UNDO" "END")
(princ)
);defun DimPL
;-------------------------------------------------------------------------------
; GetDimLayer - Returns the layer name that's on and has the most dimensions,
; or the current layer name if there's no dimensions.
;-------------------------------------------------------------------------------
(defun GetDimLayer (/ DimLayer$ EntList@ Index# Layer$ LayerInfo@ LayerList@ List@ Num# SS&)
(setq Layer$ (getvar "CLAYER"))
(if (setq SS& (ssget "X" '((0 . "DIMENSION"))))
(progn
(setq Index# -1)
(while (< (setq Index# (1+ Index#)) (sslength SS&))
(setq EntList@ (entget (ssname SS& Index#))
DimLayer$ (cdr (assoc 8 EntList@))
LayerInfo@ (tblsearch "LAYER" DimLayer$)
);setq
(if (and (= (cdr (assoc 70 LayerInfo@)) 0)(> (cdr (assoc 62 LayerInfo@)) 0))
(if (assoc DimLayer$ LayerList@)
(setq Num# (1+ (cdr (assoc DimLayer$ LayerList@)))
LayerList@ (subst (cons DimLayer$ Num#) (assoc DimLayer$ LayerList@) LayerList@)
);setq
(setq LayerList@ (append LayerList@ (list (cons DimLayer$ 1))))
);if
);if
);while
(if LayerList@
(progn
(setq Layer$ (car (car LayerList@))
Num# (cdr (car LayerList@))
);setq
(foreach List@ (cdr LayerList@)
(if (> (cdr List@) Num#)
(setq Layer$ (car List@)
Num# (cdr List@)
);setq
);if
);foreach
);progn
);if
);progn
);if
Layer$
);defun GetDimLayer
;-------------------------------------------------------------------------------
(princ);End of DPL.lsp

 

Message 15 of 21

kibitotato
Advocate
Advocate

Doesn´t work for me because my Autocad is in Spanish...

 

Comando: AUTODPL
Select Polyline to dimension: Comando "UNDO" desconocido. Pulse F1 para obtener ayuda.
Comando "BEGIN" desconocido. Pulse F1 para obtener ayuda.
Comando "S" desconocido. Pulse F1 para obtener ayuda.
Comando "1-BAS-LIN" desconocido. Pulse F1 para obtener ayuda.
Comando "AUTODPL" desconocido. Pulse F1 para obtener ayuda.
Comando "UNDO" desconocido. Pulse F1 para obtener ayuda.
Comando "END" desconocido. Pulse F1 para obtener ayuda.

0 Likes
Message 16 of 21

komondormrex
Mentor
Mentor

check the mod there 

0 Likes
Message 17 of 21

kibitotato
Advocate
Advocate
It works for me bur it only works with geometris aligned to X Y axis... Is it posible to have the same thing but aligned with the pline?
0 Likes
Message 18 of 21

komondormrex
Mentor
Mentor

like what?

0 Likes
Message 19 of 21

kibitotato
Advocate
Advocate

kibitotatogmail_com_0-1696589970556.png

1 your definition

2 what I want

 

0 Likes
Message 20 of 21

komondormrex
Mentor
Mentor

check the following. dimizes lwpline using current dimstyle. positive dimension offset sets dimension outwards of pline, negative - inwards, zero - along the pline.

 

 

;**************************************************************************************************************************************************************************************

;	komondormrex, oct 2023

;**************************************************************************************************************************************************************************************

(defun c:dimize_pline (/ command_terminated dim_offset pline_object next_param param_list bulge_list segment_list segment_start segment_end segment_middle segment_bulge
						 dim_object center_point
					  )

	;**********************************************************************************************************************************************************************************

	(defun get_prompted_value (initget_value get_function prompt_string var command_terminated / default_string var_saved)
		(if (/= 3 (getvar 'dynmode)) (setvar 'dynmode 3))
		(if (null command_terminated)
			(progn
				(setq var_saved (read (strcat (vl-symbol-name var) "_saved")))
				(cond
					(
						(null (vl-symbol-value var_saved))
							(setq default_string "")
					)
					(
						(= 'str (type (vl-symbol-value var_saved)))
							(setq default_string (vl-symbol-value var_saved))
					)
					(
						t
							(setq default_string (rtos (vl-symbol-value var_saved)))
					)
				)
				(initget initget_value)
	 			(set var (vl-catch-all-apply get_function (list (strcat "\n" prompt_string " <" default_string ">: "))))
	 			(cond
	 				(
						(or
							(null (vl-symbol-value var))
							(= "" (vl-symbol-value var))
						)
	 						(set var (vl-symbol-value var_saved))
	 				)
	 				(
	 					(vl-catch-all-error-p (vl-symbol-value var))
	 						(setq command_terminated t)
	 				)
	 				(
	 					t
	 						(set var_saved (vl-symbol-value var))
	 				)
	 			)
			)
		)
	 	command_terminated
	)

	;**********************************************************************************************************************************************************************************

	(defun arc_segment_center (bulge start_point end_point / arc_segment_direction half_included_angle center_position center_distance arc_segment_center )
		(setq arc_segment_direction (/ bulge (abs bulge))
			  half_included_angle (* 2.0 (atan (abs bulge)))
			  center_position (cond
									(
										(< pi (* 2.0 half_included_angle))
											(setq center_distance (/ (* 0.5 (distance start_point end_point)) (/ (sin (- pi half_included_angle)) (cos (- pi half_included_angle)))))
											-1.0			;	center point inside arc
									)
									(
										(> pi (* 2.0 half_included_angle))
											(setq center_distance (/ (* 0.5 (distance start_point end_point)) (/ (sin half_included_angle) (cos half_included_angle))))
											+1.0            ;	center point outside arc
									)
									(
										t
											(setq center_distance 0.0)
											 0.0            ;	center point halfway from arc start poit to arc end point
									)
							  )
			  arc_segment_center (polar (polar start_point (angle start_point end_point) (* 0.5 (distance start_point end_point)))
			  							(+ (angle start_point end_point) (* arc_segment_direction center_position 0.5 pi))
										center_distance
								 )
		)
	)

	;**********************************************************************************************************************************************************************************

	(defun find_pline_direction (segment_list pline_object / angle_list)
		(defun diff_angle (angle_1 angle_2)
		  	(setq angle_1 (if (> angle_2 (+ pi angle_1)) (+ (* pi 2) angle_1) angle_1))
		  	(setq angle_2 (if (> angle_1 (+ pi angle_2)) (+ (* pi 2) angle_2) angle_2))
		  	(- angle_2 angle_1)
		)
		(setq angle_list (mapcar '(lambda (segment) (angle (vlax-curve-getpointatparam pline_object (car segment))
		  												   (vlax-curve-getpointatparam pline_object (cadr segment))
													)
								  )
				 	  			  segment_list
			 		   	  )
		)
		(if (> (apply '+ (mapcar '(lambda (angle_1 angle_2) (diff_angle angle_1 angle_2)) angle_list (cdr angle_list))) 0) t nil)
	)

	;**********************************************************************************************************************************************************************************

	(if (not (minusp (vlax-get (vla-get-activelayer (vla-get-activedocument (vlax-get-acad-object))) 'lock)))
			(progn
				(vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
				(if (null dim_offset_saved) (setq dim_offset_saved 10))
				(and
					(or
						(null (get_prompted_value 0 'getdist "Dimension offset:" 'dim_offset command_terminated))
						(null (princ "\nCommand cancelled"))
					)
					(repeat (sslength (setq ename_index -1
											ignore_empty_sset (while (null (setq pline_sset (vl-catch-all-apply 'ssget (list '((0 . "lwpolyline")))))))
											pline_sset (cond
																	(
																		(vl-catch-all-error-p pline_sset)
																			(princ "\nCommand cancelled")
																			(ssadd)
																	)
																	(
																		t
																			pline_sset
																	)
													  		)
									   )
							)
							(setq pline_object (vlax-ename->vla-object (ssname pline_sset (setq ename_index (1+ ename_index))))
								  next_param -1
								  param_list nil
								  bulge_list nil
							)
							(repeat (fix (vlax-curve-getendparam pline_object))
								(setq param_list (append param_list (list (setq next_param (1+ next_param))))
									  bulge_list (append bulge_list (list (vla-getbulge pline_object next_param)))
								)
							)
							(setq segment_list (mapcar '(lambda (param next_param bulge) (list param next_param bulge))
														param_list
														(append (cdr param_list) (list (1+ (last param_list))))
														bulge_list
												)
							)
							(if (find_pline_direction segment_list pline_object) (setq modify_angle '-) (setq modify_angle '+))
							(foreach segment segment_list
								(setq segment_start (vlax-curve-getpointatparam pline_object (car segment))
									  segment_end (vlax-curve-getpointatparam pline_object (cadr segment))
									  segment_middle (vlax-curve-getpointatparam pline_object (* 0.5 (+ (car segment)(cadr segment))))
									  segment_bulge (last segment)
								)
								(cond
									(
										(zerop segment_bulge)
											(setq dim_object (vla-adddimaligned (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
														   						(vlax-3d-point segment_start)
														   						(vlax-3d-point segment_end)
														   						(vlax-3d-point (polar segment_middle
																									  ((eval modify_angle) (angle segment_start segment_end) (* 0.5 pi))
																									  dim_offset
																							   )
																				)
														 	)
											)
									)
									(
										t
											(setq center_point (arc_segment_center segment_bulge segment_start segment_end))
											(setq dim_object (vla-adddimarc (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
																 			(vlax-3d-point center_point)
																 			(vlax-3d-point segment_start)
																 			(vlax-3d-point segment_end)
																			(vlax-3d-point (polar segment_middle ((eval modify_angle) (angle segment_start segment_end) (* 0.5 pi)) dim_offset))
															 )
											)
									)
								)
							)
					)
				)
			(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
		)
		(alert "       Active layer is locked")
	)
	(princ)
)

;**************************************************************************************************************************************************************************************