Jump to content

Modify & Improve existing routine


Want2LispForever

Recommended Posts

Hello,

 

 

I am currently using a function that dimensions a 2D line and generates text to display the relevant dimension and I am trying to figure out if I can specify a particular position for the text when it is inserted.

At the moment the text is placed manually at the end of the routine but I want it to be placed at a specific offset ie: 0.50m from the line, example below.

 

I'm a total newbie when it comes to LISP routines and am keen to learn if someone can point me in the right direction it'd be much appreciated.

Here's what we are currently using...

 

 

(defun c:d1-2002()
(command "osnap" "end")
(setq pt1 (getpoint "1st end:"))
(setvar "lastpoint" pt1)
(setq pt2 (getpoint "2nd end:"))
(command "osnap" "")
(setq dist (rtos (distance pt1 pt2) 2 2))
(setq ang (- 90.0 (/ (* (angle pt1 pt2) 180.0) pi)))
(setq pt1 (getpoint "mid point of text:"))
 (setq b  (* 3 (getvar "dimscale")))
(command "-layer" "m" "DISTANCE" "c" "3" "" "")
(command "text" "m" pt1 b ang dist)
(princ)
)

Distance text eg.jpg

Edited by SLW210
Code Tags.
Link to comment
Share on other sites

Dimstyle is one way you create a style with all the end stuff turned off and the dim line so you end up only with the text it then handles the offset and puts the text middle etc

 

The other is to just work out your text position similar to your lisp.

 

; simple line labeller 
; by Alan H June 2018

(defun c:linelab ( / pt1 pt2 pt3 oldsnap rads oldang ang dist  )
(setq oldsnap (getvar 'osmode))
(setq oldang (getvar 'angdir))
(setq rads (getvar 'aunits))
(setvar 'osmode 1)
(setq dimsc (* 3 (getvar "dimscale")))
(alert "Text will follow Pt1 -> pt2") ; delete line later
(setq pt1 (getpoint "pick end pt"))
(setq pt2 (getpoint "Pick other end"))
(setq ang (angle pt1 pt2))
(setq dist (distance pt1 pt2))
(setq pt3 (polar pt1 ang (/ dist 2.0)))
(setq pt3 (polar pt3 (+ ang (/ pi 2.0)) 3.5)) ; hard coded 3.5
(if (= (tblsearch "layer" "DISTANCE") nil)
(command "-layer" "m" "DISTANCE" "c" "3" "" "")
)
(setvar 'osmode 0) ; end
(setvar 'angdir 0) ; east
(setvar 'aunits 3) ; radians
(command "text" pt3 dimsc (- ang (/ pi 2.0)) (rtos dist 2 2))
; flip option here inside/outside press enter
(setvar 'osmode oldsnap)
(setvar 'angdir oldang)
(setvar 'aunits rads)
)
(c:linelab)

Edited by BIGAL
Link to comment
Share on other sites

here's something written quick, you could optimise further by using entmake for the text labels & cmdecho to silence the console spam but I'll leave that for you to play with

 

(defun c:d1-line ( / e ) ; draw new line and label it
 (setq e (entlast))
 (command-s "._line")
 (while (setq e (entnext e))
    (d1-label e)
 )
)

(defun c:d1-2002 ( / ss i ) ; select existing lines to label
 (princ "\nSelect lines to measure")
 (if (setq ss (ssget '((0 . "LINE"))))
     (repeat (setq i (sslength ss))
         (d1-label (ssname ss (setq i (1- i))))
     )
 )
)

(defun d1-label ( e / la p0 p1 a d m )
 (setq e (entget e))
 (if (= "LINE" (cdr (assoc 0 e)))
    (progn
       (setq la (getvar 'clayer)
             p0 (cdr (assoc 10 e))
             p1 (cdr (assoc 11 e))
             a (angle p0 p1)
             d (distance p0 p1)
             m (polar p0 a (/ d 2.0))
       )
       (if (< (* pi 0.5) a (* pi 1.5)) (setq a (+ a pi)))
       (command 
          "._layer" "_m" "DISTANCE" "_c" "3" "DISTANCE" ""
          "._text"
             "_m"
             "_none" ; no snap for next pick
             (polar m (+ a (* pi 0.5)) 0.5) ; insert point
             (* (getvar 'dimscale) 3.0) ; size
             (* (/ a pi) 180) ; angle
             (rtos d 2 2) ; line dist
       )
       (setvar 'clayer la)
    )
 )
 (princ)
)

I like the idea BIGAL mentioned of having a stripped down dimstyle, then if the line changes the label will update automatically

Edited by FranknBeans
Link to comment
Share on other sites

  • 2 weeks later...

Thanks again for all the advice, finally got around to implementing a few of the suggestions and ultimately went with the stripped down dimension style. This solution was definitely a lot easier to get a grasp on but I'm still interested with the Auto LISP side of things and will endeavour to continue interacting with the community to that end.

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