Jump to content

Creating Dimensions for multiple lines from Base line


Recommended Posts

Posted

I am off fishing for a few days so back in 3 days will see what I can do. Briliant sunshine and surf at the doorstep.

  • Like 1
Posted

Thanks Bigal, I'm waiting. Enjoy your surfing.

  • 1 month later...
Posted (edited)

I have been busy lately this seems to be best version for where I am at.

 

; dim multi offsets ver2
; By AlanH Jan 2022
; https://www.cadtutor.net/forum/topic/74382-creating-dimensions-for-multiple-lines-from-base-line/

(defun c:dimoffs ( / )

(setq oldsnap (getvar 'osmode))
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 3)

(setq pi2 (/ pi 2))

(setq ent (entsel  "\nPick a point on control line " ))
(setq pt1 (cadr ent))
(setq pt1 (vlax-curve-getclosestpointto (vlax-ename->vla-object (car ent)) pt1))

(setq 
Pt2 (getpoint pt1 "\nPick a point on other side of last line ")
pt3 pt2
)

(setq ang (angle pt1 pt2))

(setq spc (getreal "\nEnter spcing"))

(if (not (tblsearch "dimstyle" "Standard"))
(alert "The correct dimstyle is not available \nResults may not be what is expected")
(command "dimstyle" "R" "Standard")
)

(setvar 'dimse1 1)
(setvar 'dimse2 1)

(setvar 'osmode 0)

(setq pt1a (polar pt1 (angle pt1 pt2) 0.001))
(setq ss (ssget "F" (list pt1a pt2)))


(command "line" pt1a pt2 "")
(setq obj1 (vlax-ename->vla-object (entlast)))

(setq lst '())
(repeat (setq x (sslength ss))
  (setq obj2 (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
   (setq intpt (vlax-curve-getclosestpointto obj2 pt1))
  (setq lst (cons (list (distance  intpt pt1) intpt) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
(vla-delete obj1)

(setq ang (angle pt1 (nth 1 (nth 0 lst))))
(setq len (distance pt1 pt3))

(setq x 0)
(repeat (length lst) 
   (Command "Dim" "align" pt1 (cadr (nth x lst)) pt3   "" "exit")
      (vlax-put (vlax-ename->vla-object (entlast)) 'TextPosition pt3)
(setq pt3 (polar pt3 (- ang pi2) spc))
   (setq x (1+ x))
 )

(setvar 'osmode oldsnap)
(setvar 'aunits oldaunits)
(setvar 'dimse1 0)
(setvar 'dimse2 0)

(princ)
)
(c:dimoffs)

 

Edited by BIGAL
Posted

Hi Bigal,

Thanks for the Updated code, It's working, now i can place the Dimension on both side, but it's taking the Dimension for few lines only.

If i have 9 lines, and middle one is the base line, if i'm taking the dimension for left side, then i can select only 4 lines on left side, for another 4 lines on right side dimensions not coming, 

also Dimensions not coming for 3 lines next to the selected base line.

 

This is the earlier version you gave me, this is works fine, the only thing on this, it's placing the dimension only one side.

; dim multi offsets
; By AlanH Nov 2021
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/line-up-dimension-text-in-multiple-dimensions/td-p/10739193

; (defun c:dimoffs ( / pt1 pt2 pt3 ent ent1  ss  obj1 obj2 tpos lst oldsnap oldaunits  )
(defun c:dimoffs ( /)

(if (not (tblsearch "dimstyle" "Standard"))
(alert "The correct dimstyle is not available \nResults may not be what is expected")
(command "dimstyle" "R" "Standard")
)

(setq oldsnap (getvar 'osmode))

; left or right by lee-mac
(defun lM:ISL-R (ent pnt /  cpt der )
		(setq pnt (trans pnt 1 0))
    (setq cpt (vlax-curve-getclosestpointto ent pnt)
          der (vlax-curve-getfirstderiv ent (vlax-curve-getparamatpoint ent cpt))
    )
    (if (minusp (sin (- (angle cpt pnt) (angle '(0.0 0.0) der))))
        (setq dir 1.0)
        (setq dir -1.0)
    )
    (princ)
)

(defun alg-ang (object pnt)
  (angle '(0. 0. 0.)
     (vlax-curve-getfirstderiv
       obj
       (vlax-curve-getparamatpoint
         object
         pnt
       )
     )
  )
)

(setq oldsnap (getvar 'osmode))
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 3)

(setq pi2 (/ pi 2.0))

(setq ent (entsel "\nPick control line " ))
(setq entname (car ent))
(setq pt1 (cadr ent))
(setq pt1 (vlax-curve-getclosestpointto (vlax-ename->vla-object (car ent)) pt1))
(setq ent1 (entget (car ent)))

(setvar 'osmode 0)

(setq pt2 (getpoint "\nPick a point on left side"))
(setq  pt3 (getpoint pt2 "\nPick a point on right side "))
  
;(setq spac (getreal "\Enter spacing "))
  
(setq ss (ssget "F" (list pt2 pt3)))

(setq ss (ssdel (cdr (assoc  -1 ent1))  ss)) ; remove control

(setq ang (angle pt2 pt3))

(setvar 'osmode 0)


;(setq pt1a (polar pt1 (angle pt1 pt2) 0.0001))
;(setq ss (ssget "F" (list pt1a pt2)))

(command "line" pt2 pt3 "")
(setq obj1 (vlax-ename->vla-object (entlast)))

(setq lst '() )
(repeat (setq x (sslength ss))
(setq entl (ssname ss (setq x (- x 1))))
(setq obj2 (vlax-ename->vla-object  (ssname ss  x)))
(setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendnone))
(LM:ISL-R (car ent) intpt)
(setq lst (cons (list  (* (distance  intpt pt1) dir) intpt entL) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))
(vla-delete obj1)

(setq  pt (cadr (nth 0 lst)))
(setq obj (vlax-ename->vla-object  ( caddr (nth 0 lst))))
(setq  ang (alg-ang obj pt))
(setq len (distance pt1 pt3))

(setq x -1)
(setq pt3 (polar pt1 (+ ang pi2) len))
(repeat (length lst) 
  (setq obj2 (vlax-ename->vla-object  (caddr (nth (setq x (1+ x)) lst))))
  (setq pt2 (vlax-curve-getclosestpointto obj2 pt1))
  (setq  dist  (distance pt1 pt2) )
  (if (< (car (nth  x  lst)) 0.0)(setq dist (- 0.0 dist)))
  ;(Command "Dim" "align" pt1 pt2 pt3   (rtos dist 2 2) "exit")
 (Command "Dim" "align" pt1 pt2 pt3   (strcat (rtos (abs dist) 2 2) " m") "exit")
        (setq pt3 (polar pt3 ang 1.05))
  (setq obj2 (vlax-ename->vla-object (entlast)))
 ; (vlax-put obj2 'TextMovement 1)
  ;(setq tpos  (polar pt3 (angle pt1  pt2)  2.5))
  ;(vlax-put obj2 'TextPosition tpos)
 (vlax-put obj2 'TextPosition pt3)
)

(setvar 'osmode oldsnap)
(setvar 'aunits oldaunits)

(princ)
)
(c:dimoffs)

 

Posted (edited)

Will look into it should do all. When you pick last outside point go past not on last line see if that fixes. Pick dim location outside also.

Edited by BIGAL
Posted (edited)

When i select left side line (green) and pick the Dim location on right side (Outside), Dimension is not coming for first two Highlighted lines.

 

image.png.45ce85934521936005aeee047d1c5fbc.png

 

When i select Right side line (Red color) and pick the Dim location on Left side (Outside), Dimension is not coming for first two Highlighted lines from the red color line.

 

image.png.745cfae7de3e99644bc375bf8d54e3cf.png

 

If i'm selecting the middle line as base line, then i can create the dimensions only part of lines. see the attached.

But in old version i can select all the lines after selecting the baseline.

 

 sample.dwg  

 

Thanks

Edited by acad1985
Posted

The OP must have pulled all of their hair for now. :D 

Anyway, try the following and specify the first point on the first & the second point on the two sides of the selected line to add dims on the two sides and you can end the second point up to the end of the selected line to add dims on either sides of the line.

 

(defun c:DimMe (/ pck 1pt 2pt sel cnt int ent pts run ang cho dis 1st off cls pos)
  ;;------------------------------------------------------------;;
  ;;	Author: Tharwat Al Choufi - Date: 29.Mar.2022		;;
  ;;	website: https://autolispprograms.wordpress.com		;;
  ;;------------------------------------------------------------;;
  (and
    (setq pck (entsel "\nSelect base line to dimension from : "))
    (or (wcmatch (cdr (assoc 0 (entget (car pck)))) "*LINE")
        (alert "Must select Polyline, Spline, Line to continue")
    )
    (or (setq cnt (vlax-curve-getclosestpointto (car pck) (cadr pck)))
        (alert "Close point could not be retrieved. Try again")
    )
    (setq 1pt (getpoint "\nSpecify 1st side : "))
    (setq 2pt (getpoint "\nSpecify 2nd side : " 1pt))
    (setq run 0 2pt (list 1pt 2pt))
    (setq cho (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (repeat 2
      (and (setq int -1 sel (ssget "_F" (list cnt (nth run 2pt)) '((0 . "*LINE"))))
           (while (setq int (1+ int) ent (ssname sel int))
             (or (eq (car pck) ent)
                 (and (setq cls (vlax-curve-getclosestpointto ent cnt))
                      (setq pts (cons cls pts))
                 )
             )
           )
           (< 1 (length pts))
           (setq pts (vl-sort pts (function (lambda (j k) (< (distance cnt j) (distance cnt k)))))
                 1st (car pts)
                 off 0.0
                 dis (+ (distance cnt (last pts)) 0.5)
           )
           (foreach pt pts
             (setq off (+ off 0.2)
                   ang (+ (angle cnt pt) (* pi 0.5))
             )
             (vl-cmdf "_.DIMALIGNED" "_none" cnt "_none" pt "_none" (setq pos (polar cnt ang off)))
             (vla-put-textposition
               (vlax-ename->vla-object (entlast))
               (vlax-3d-point (polar pos (angle cnt pt) dis))
             )
           )
      )
      (setq run (1+ run) pts nil off 0.0)
    )
    (setvar 'CMDECHO cho)
  )
  (princ)
) (vl-load-com)

 

Posted

Thanks Tharwat,

It's working but it's creates the dimensions on both side. i need to place the dimension either left or right where i clicked.

Thank you so much for your code.

 

Posted

As I already explained that in my last post, end up the second point up to the selected line then this would create dims on one side.

I already created .gif file but the uploads throwing an error and rejects uploading the file.

Posted

Hi Tharwat,

Getting confused, if you can share the GIF if possible.

 

Posted

Hi Tharwat,

 

Got it now, 2nd option you are doing, i need to select middle/ in between line always, but all the dimension should place any one side.

 

Thanks

Posted

I wrote the program according to your request in this thread so if you want to have it with more options then you can message me to donate for my time working on this.

Posted

I have updated the code in previous post, 2 items, removed extension lines and added a spacing value. Your original dwg had offsets like 3 4 5 this has offsets like 0.1 0.2 so code did not work I had a small offset in code but way to big hence skipped lines.

Posted

Try this different version and keep an eye on the command line while running the program to know how to deal with the inputs.

 

(defun c:DimMe (/ pck 1pt 2pt sel cnt int ent pts run ang cho dis 1st off cls pos nxt)
  ;;------------------------------------------------------------;;
  ;;	Author: Tharwat Al Choufi - Date: 30.Mar.2022		;;
  ;;	website: https://autolispprograms.wordpress.com		;;
  ;;------------------------------------------------------------;;
  (and
    (setq pck (entsel "\nSelect base line to dimension from : "))
    (or (wcmatch (cdr (assoc 0 (entget (car pck)))) "*LINE")
        (alert "Must select Polyline, Spline, Line to continue")
    )
    (or (setq cnt (vlax-curve-getclosestpointto (car pck) (cadr pck)))
        (alert "Close point could not be retrieved. Try again")
    )
    (setq 1pt (getpoint "\nSpecify 1st side : " cnt))
    (or (setq 2pt (getpoint "\nSpecify 2nd side < Enter to pass > : " cnt)) t)
    (setq run 0 2pt (list 1pt 2pt))
    (setq cho (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (repeat 2
      (and (setq nxt (nth run 2pt))
           (setq int -1 sel (ssget "_F" (list cnt nxt) '((0 . "*LINE"))))
           (while (setq int (1+ int) ent (ssname sel int))
             (or (eq (car pck) ent)
                 (and (setq cls (vlax-curve-getclosestpointto ent cnt))
                      (setq pts (cons cls pts))
                 )
             )
           )
           (< 1 (length pts))
           (setq pts (vl-sort pts (function (lambda (j k) (< (distance cnt j) (distance cnt k)))))
                 1st (car pts)
                 off 0.0
                 dis (+ (distance cnt (last pts)) 0.5)
           )
           (foreach pt pts
             (setq off (+ off 0.2)
                   ang (+ (angle cnt pt) (* pi 0.5))
             )
             (vl-cmdf "_.DIMALIGNED" "_none" cnt "_none" pt "_none" (setq pos (polar cnt ang off)))
             (vla-put-textposition
               (vlax-ename->vla-object (entlast))
               (vlax-3d-point (polar pos (angle cnt pt) dis))
             )
           )
      )
      (setq run (1+ run) pts nil off 0.0)
    )
  )
  (and cho (setvar 'CMDECHO cho))
  (princ)
) (vl-load-com)

 

Posted

Man, press enter on the second point to pass the other sides as the message says while running the program.

Posted

Yes Tharwat, I tried that option also, if i pass the other side then the dimensions created only for 1st side. 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...