Jump to content

Offset Line and add dimension or text of measurement


EricDevault

Recommended Posts

I would like to start by saying thanks to every active member here helping us with our code, it is greatly appreciated.

Being new to this stuff, sometimes it is overwhelming getting code back from someone who edited my code and then trying to dissect it so I can understand it. All I ask is that someone can explain or comment within the code the actions and changes and enhancements, thank you. It's only going to make me better.

That being said, here is my code and what I would like to accomplish is offset a line, dimension or text of measurement from old line to new line, and repeat until nil offsetting the last entity created and then repeat again with a new selection of a different line being selected.

(defun c:grid1 (vs hs)
;;Written by Eric DeVault 2015
;********************************************************


(setvar "CLAYER" "PENME")



(setq entvs (entsel "\Select the Vert Strap measured from: ")

) 
;original strap

(setq vs (getdist "\Distance to next Vert Strap: ")
)
;distance to next vert strap
;(setq vside (getpoint "\Select side to the next Vert strap: "))
;uncomment above and change '(70 0. 0.) below to vside if adjusting left or right offset. Commented will offset to the right

(setvar "CLAYER" "0")
(command ".text"  (list (/ (/ vs 2) 12) -1 0) 0.7 0 (rtos vs 2 0))
(setvar "CLAYER" "PENME")
(command "._offset" (/ vs 12) entvs "_non" '(70 0. 0.) "")



(while 
(setq vsn (getdist "\Distance to next Vert Strap (Enter when done): "))

;(setvar "CLAYER" "0")
;(command ".text"  (list (/ (/ vsn 2) 12) -1 0) 0.7 0 (rtos vsn 2 0))
;(setvar "CLAYER" "PENME")
(command "._offset" (/ vsn 12) (entlast) "_non" '(70 0. 0.) "")
)

(setq enths (entsel "\Select the Horiz Strap measured from: ")) 
;original strap

(setq hs (getdist "\Distance to next Horiz Strap: "))
;distance to next vert strap
;(setq hside (getpoint "\Select side to the next Horiz strap: "))
;uncomment above and change '(70 0. 0.) to hside if adjusting top or bottom offset. Commented will offset up

(command "._offset" (/ hs 12) enths "_non" '(0. 70 0.) "")

(while 
(setq hsn (getdist "\Distance to next Horiz Strap (Enter when done): "))
(command "._offset" (/ hsn 12) (entlast) "_non" '(0. 70 0.) "")

)

;(command "._point")

;(setq tedge (ssget)) ; "\Select the last Vert and Horiz strap created: "
;(command "._trim" tedge)

(princ)
)

What the user will start out with is a file with vertical line 36' long starting at 0,0,0 and ending at 0,36,0 and a horizontal line 55' long starting at 0,0,0 and ending at 55,0,0

They then are prompted to select the first vertical strap(the 36' line) and the distance to the next strap and once they have accounted for all vertical straps they enter a nil and it moves on to the horizontal strap(the 55' line) with the same method as the vertical straps.

What I need is a text or dimension of the offset value for each strap.

I am working with Draftsight 2015, which can use all .lsp but to my knowledge not active-x. If I am wrong on that let me know.

Thanks for everyone's time.

Link to comment
Share on other sites

When you create a new object ie offset 1 line you can use (entlast) to grab this last created object the properties (assoc 10) & (assoc 11) are the start & end points of the line, so you can do a dim using these two pts then go on to next offset. No VL etc

 

(SETQ EL1 (entget (entlast))) ; original line
(setq pt1 (CDR (ASSOC 10 EL1))) 
(setq pt2 (CDR (ASSOC 11 EL1)))
.... do offset
(SETQ EL1 (entget (entlast))) ; offset line
(setq pt3 (CDR (ASSOC 10 EL1)))
(setq pt4 (CDR (ASSOC 11 EL1)))
.... do dim
(setq pt1 pt3) ; need for next offset dim pts
(setq pt2 pt4)

Link to comment
Share on other sites

Hi,

 

Here is a quick start for you to start with Vertical Lines .

 

(defun c:Test (/ s d p1 p2 pt)
 ;; Tharwat 18.07.2015    ;;
 (if (and (setq s (car (entsel "\nSelect the Vertical Strap Line :")))
          (eq (cdr (assoc 0 (entget s))) "LINE")
     )
   (while (setq d (getdist "\nDistance to next Vertical Strap Line: "))
     (command "._offset"
              (/ d 12.)
              s
              "_non"
              (polar (cdr (assoc 10 (entget s))) 0. 1.)
              ""
     )
     (if (not (eq s (setq s (entlast))))
       (progn
         (setq p1 (cdr (assoc 10 (entget s)))
               p2 (cdr (assoc 11 (entget s)))
               pt (if (< (cadr p1) (cadr p2))
                    p1
                    p2
                  )
         )
         (entmake (list '(0 . "TEXT")
                        (cons 10 (polar pt (* pi 1.5) 1.))
                        (cons 11 (polar pt (* pi 1.5) 1.))
                        (cons 1 (rtos d 2 2))
                        '(40 . 0.7)
                        '(8 . "0")
                  )
         )
       )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Hi,

 

Here is a quick start for you to start with Vertical Lines .

 

(defun c:Test (/ s d p1 p2 pt)
 ;; Tharwat 18.07.2015    ;;
 (if (and (setq s (car (entsel "\nSelect the Vertical Strap Line :")))
          (eq (cdr (assoc 0 (entget s))) "LINE")
     )
   (while (setq d (getdist "\nDistance to next Vertical Strap Line: "))
     (command "._offset"
              (/ d 12.)
              s
              "_non"
             [color="red"]--->[/color] (polar (cdr (assoc 10 (entget s))) [color="red"]0. 1.[/color])
              ""
     )
     (if (not (eq s (setq s (entlast))))
       (progn
         (setq p1 (cdr (assoc 10 (entget s)))
               p2 (cdr (assoc 11 (entget s)))
               pt (if (< (cadr p1) (cadr p2))
                    p1
                    p2
                  )
         )
         (entmake (list '(0 . "TEXT")
                        (cons 10 (polar pt (* pi 1.5) 1.))
                        (cons 11 (polar pt (* pi 1.5) 1.))
                        (cons 1 (rtos d 2 2))
                    [color="red"]---->'(40 . 0.7)
                     ----> '(8 . "0")[/color]
                  )
         )
       )
     )
   )
 )
 (princ)
)

Could you explain the points above colored in red? I think I understand but I want to be absolutely sure. Thank you so much.

Link to comment
Share on other sites

Could you explain the points above colored in red? I think I understand but I want to be absolutely sure. Thank you so much.

 

This is to get sure that the offset destination of the selected line would be all the time on the right side hand .

Further more , it is the point that the offset command asks you to specify a point on the desire side as following:

Specify point on side to offset or [Exit/Multiple/Undo] <Exit>:

 

And regarding to the DXF codes:

 

1- 40 .

2- 8 .

Link to comment
Share on other sites

This is to get sure that the offset destination of the selected line would be all the time on the right side hand .

Further more , it is the point that the offset command asks you to specify a point on the desire side as following:

Specify point on side to offset or [Exit/Multiple/Undo] <Exit>:

 

And regarding to the DXF codes:

 

1- 40 .

2- 8 .

 

Very nice, thank you!

Link to comment
Share on other sites

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...