LISP for dimensioning a preselected set of lines

LISP for dimensioning a preselected set of lines

DavidePresta
Contributor Contributor
1,595 Views
7 Replies
Message 1 of 8

LISP for dimensioning a preselected set of lines

DavidePresta
Contributor
Contributor

Hi,

 

I have a small issue here, I'm brand new at LISP and I'm having difficulties finding a way to automate this task (I don't know if LISP is the best choice but even with a macro or VBA, it doesn't matter, every board is well accepted).

 

I have hundreds of drawings like this:

 Sezioni_mod.jpg

 

 

and i would like to dimensioning the length of vertical lines and if it's possible the orizzontal distance between two lines.

 

At the moment for the vertical dimensions i have to DIM one line a time, then explode the dimension, rotate the resultant text and move it under the line at a specified offset. This for every line of every drawing. This is so brainless.

 

I suppose for a PRO this seems easy, but for me it's pretty hard to code from scratch. I hope someone has already encountered this situation and get some code hidden somewhere.

 

I would like to write a code (most likely modify... with your help) a code that allow me to previously slect all the lines and lets me choose the offset distance from the bottom of the line (the same for all the lines). Stop.

 

Is this so impossible?

 

Please help me get this task automated.

 

Thanks in advance.

 

0 Likes
Accepted solutions (1)
1,596 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

You can do most of this without any custom routine(s), with a little care in set-up.  Make yourself a Dimension Style with all arrows and extension and dimension lines suppressed, and the QDIM command will do the horizontal ones for you, all at once and all lined up.  For the vertical ones, make a Style with the text aligned with the dimension line  [so you don't have to Explode and Rotate], and at one end of it, and Dimension the verticals, after which you will need to drag the text parts downward, but you can all of those at once with Stretch.

 

DIMnoLines.PNG    DIMnoArrows.PNG

 

DIM.PNG

 

A routine could simplify the vertical ones a little, letting you just select Lines [assuming the Dimensioned lengths are the lengths of Line objects], but first see how far these suggestions take you.

Kent Cooper, AIA
0 Likes
Message 3 of 8

DavidePresta
Contributor
Contributor

Hi Kent and thank you for the help.

 

Unfortunately in the time between my question and your reply, i've already found out that with a little costumization of the Dimension Style i can skip some step of my workflow, but the big problem, how you will understand, is that i have to select one line a time.

 

I've tried to understand how to code a routine that, given a selection set of lines, can:

 

  1. extract by every vertical line, Start X, Start Y and Finish Y and save it in three different variables (eg: X1, SY1 and FY1); (I can't understand how to do this first step)
  2. take the smaller between SY1, FY1 and subtract it from the bigger;
  3. save the result in a variable and print it in a text with origin point with coordinate (x,y) equal to (X1,[smaller between SY1,FY1] -30); (where "-30" is an offset value defined by the user).

Unfortunately I don't know the so well the sintax needed. Any advice will be much appreciated.

 

Thank you again for your help.

 

0 Likes
Message 4 of 8

dbroad
Mentor
Mentor

Post a drawing without dimensions so someone can show you via Screencast how you can dimension fast without a program.  Programming a solution will be a poor solution unless the dimension text retains its association with the actual dimensions.  Before you post the file, be sure to set up the dimension styles as you prefer them to be.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 8

Ranjit_Singh
Advisor
Advisor
Accepted solution

@DavidePresta wrote:

Hi,

 

...... i have to DIM one line a time, then explode the dimension, rotate the resultant text and move ........

 


If you do not need the associative dimensions then something like below may work. Lightly tested and no error trap.

;:Ranjit Singh
;;8/30/17
(defun c:somefunc  (/ pt1 pt2 lst ss1)
 (and (setq ss1 (ssget '((0 . "lwpolyline,line")))
            lst (vl-sort (mapcar '(lambda (x) (cons x (car (vlax-curve-getstartpoint x))))
                                 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1))))
                         '(lambda (x y) (< (cdr x) (cdr y))))
            pt1 (getpoint "\nSelect text placement for length: ")
            pt2 (getpoint "\nSelect text placement for distance: "))
      (mapcar '(lambda (x y)
                (entmake (list '(0 . "text")
                               (cons 10 (list (cdr x) (cadr pt1)))
                               '(40 . 0.1)
                               (cons 1 (rtos (getpropertyvalue (car x) "Length") 2 2))
                               '(50 . 1.5708)))
                (vl-catch-all-apply 'entmake
                                    (list (list '(0 . "TEXT")
                                                '(10 0.0 0.0 0.0)
                                                '(40 . 0.1)
                                                (cons 1 (rtos (- (cdr y) (cdr x)) 2 2))
                                                '(72 . 1)
                                                (cons 11 (list (/ (+ (cdr x) (cdr y)) 2.0) (cadr pt2)))
                                                '(73 . 2)))))
              lst
              (append (cdr lst) '(0))))
 (princ))

text_placement.gif

 

0 Likes
Message 6 of 8

DavidePresta
Contributor
Contributor

Thank you so much Ranjit, your code works exactly as I wanted.

 

Can you explain me how does it works? Cause in this way I hope the next time i don't need to disturb the forum.

 

Obviously only if you have time for this. It would be enough if you give me a link where I can learn the function that you used in the code.

 

Thank you again, you saved me from waste my time.

0 Likes
Message 7 of 8

Ranjit_Singh
Advisor
Advisor

There is a complete listing of functions by name available on Autodesk knowledge network here. You can look up the functions I used. Study the functions and come back if you have trouble understanding any. My code is pretty obvious; get the entity, get the relevant point for each entity, process and place the text. This is repeated for all the entities in the selectionset through mapcar. I have added some notes below. At a minimum, learn how to use vlide and see how the code progresses. Good luck.

;:Ranjit Singh
;;8/30/17
(defun c:somefunc  (/ pt1 pt2 lst ss1)
 (and (setq ss1 (ssget '((0 . "lwpolyline,line"))) ; get all the polylines, lines
            lst (vl-sort (mapcar '(lambda (x) (cons x (car (vlax-curve-getstartpoint x)))) ; get a list of all polylines sorted from left to right
                                 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1))))
                         '(lambda (x y) (< (cdr x) (cdr y))))
            pt1 (getpoint "\nSelect text placement for length: ")
            pt2 (getpoint "\nSelect text placement for distance: "))
      (mapcar '(lambda (x y) ; start mapcar to process each entity
                (entmake (list '(0 . "text") ; make text entity for length
                               (cons 10 (list (cdr x) (cadr pt1)))
                               '(40 . 0.1)
                               (cons 1 (rtos (getpropertyvalue (car x) "Length") 2 2))
                               '(50 . 1.5708)))
                (vl-catch-all-apply 'entmake ; make text entity for distance
                                    (list (list '(0 . "TEXT")
                                                '(10 0.0 0.0 0.0)
                                                '(40 . 0.1)
                                                (cons 1 (rtos (- (cdr y) (cdr x)) 2 2))
                                                '(72 . 1)
                                                (cons 11 (list (/ (+ (cdr x) (cdr y)) 2.0) (cadr pt2)))
                                                '(73 . 2)))))
              lst ; pass the sorted list to mapcar
              (append (cdr lst) '(0)))) ; pass the cdr of sorted list to mapcar
 (princ))

 

Message 8 of 8

DavidePresta
Contributor
Contributor
Thank you again, this is gold for me.
0 Likes