Jump to content

Lisp file request


Stryder

Recommended Posts

I enjoy a challenge, but sometimes I want to try things that are above my expertise. So, if there is anyone out there that enjoys a challenge and would like to help me out I have a request. I work in civil drafting and at the company I work for we don’t all have Civil 3d, for cost reasons. This is understandable, but I am always finding ways to use standard AutoCAD to make my job easier. With that in mind, I understand that Civil 3d will do what I am about to ask, but I don’t have that option.

 

When I draw a plan and profile of a sanitary sewer line I label the pipe in the profile to read as follows:

 

304 L.F. OF 8" P.V.C. @ 0.014 SLOPE

 

What I would like to be able to do is maybe pick the flow line out of the first manhole then pick the flow line out of the upstream manhole and have the above string of text placed above the pipe in the profile. I would like the text to be dtext and be bottom center justification and be placed at the midpoint of the top line of the pipe that is in the profile. I know that AutoCAD can calc the l.f. which is just the “x” distance of the two picked points. The slope could probably be calculated too but the profiles are at an exaggerated y scale so if this isn’t possible a place holder that can be edited would be fine. I have attached a dwg with an example of how the text should look. To whoever tackles this, if you need more info or I wasn’t clear on something, let me know.

Profile.dwg

Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    34

  • Stryder

    27

  • NH3man!

    2

  • CarlB

    1

Top Posters In This Topic

Posted Images

A suggestion..

 

If the top line of the pipe would accurately represent the LF (x distance), user could select just this line, and provide the y scale exaggeration. With the selected line & the exaggeration, the routine would know the LF, the slope, and exactly where to place the text & the orientation. (could ask user for text height also). It could provide everything except the pipe diameter & type, but could use X" P.V.C. as the default.

Link to comment
Share on other sites

True, however, the way the pipe lines are drawn in my profiles, the lines are trimmed back to the outer edge of the manhole. The manholes are typically the same dia. in the profile, so the routine would have to calculate and add some extra to make up the difference.

Link to comment
Share on other sites

Did something similar pretty easy just break down into one step at a time

 

Enter vert scale

Enter hor scale

pick pit1 c/l /inv point

Pick pit2 c/l /inv point

pick top pipe

the rest is just maths taking into account the scales

 

taking your words I enjoy a challenge

 

(setq pt1 (Getpoint "pick point 1"))

(setq pt2 (Getpoint "pick point 2"))

(setq x1 (car pt1)) x value of pt1

(setq y1 (cadr pt1)) y value of pt1

 

keep going got you started

Link to comment
Share on other sites

Well, thanks for the start, but when I said I enjoy a challenge I also mentioned this was above me. I can write scripts (who can't?), write code for toolbar buttons and know some diesel expressions but I can't write lisp files. So, maybe I am asking for too much, if I am, I am sorry. :)

Link to comment
Share on other sites

Just noticed this thread - request doesn't seem too bad - but I can't view the drawing with only '04 at my disposal - would it be possible to upload an '04 compatable drawing please :)

Link to comment
Share on other sites

Perhaps something like this to start us off:

 

(defun c:pipetxt (/ *error* vlst ovar diam lEnt lObj lLen lAng lMid)
 (vl-load-com)

 (defun *error* (msg)
   (if ovar (mapcar 'setvar vlst ovar))
   (if tObj (entdel tObj))
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\nError: " (strcase msg)))
     (princ "\n<-- cancelled -->"))
   (princ))

 (setq vlst '("OSMODE" "CLAYER")
   ovar (mapcar 'getvar vlst))
 (setvar "OSMODE" 0)

 (or (tblsearch "LAYER" "TXT-100")
     (vla-add (vla-get-layers
        (vla-get-ActiveDocument
          (vlax-get-acad-object))) "TXT-100"))

 (or pip:dia (setq pip:dia )
 (initget 6)
 (setq diam (getreal (strcat "\nSepcify Diameter of Pipeline <"
                 (rtos pip:dia 2 0) "\">: ")))
 (or (not diam) (setq pip:dia diam))

 (while (and (setq lEnt (car (entsel "\nSelect Pipeline: ")))
         (eq "LINE" (cdadr (entget lEnt))))
   (setq lObj (vlax-ename->vla-object lEnt)
     lLen (vla-get-length lObj)
     lAng (angle (vlax-curve-getStartPoint lObj)
               (vlax-curve-getEndPoint lObj))
     lMid (vlax-curve-getPointatParam lObj
        (/ (vlax-curve-getEndParam lObj) 2.0)))
   (if (and (> lAng 0) (<= lAng (/ pi 2)))
   nil (setq lAng (+ lAng pi)))
   (Make_Text lMid (strcat (rtos lLen 2 0) " L.F. OF "
               (rtos pip:dia 2 0) "\"%%C P.V.C. @ "
               (angtos lAng 0 3) " SLOPE") lAng))
 (mapcar 'setvar vlst ovar)
 (princ))

(defun Make_Text  (pt val rot)
 (entmake (list '(0 . "TEXT")
        '(8 . "TXT-100")
        (cons 10 pt)
        (cons 40 (getvar "TEXTSIZE"))
        (cons 1 val)
        (cons 50 rot)
        (cons 7 (getvar "TEXTSTYLE"))
        '(71 . 0)
        '(72 . 1)
        '(73 . 1)
        (cons 11 pt))))



         

Link to comment
Share on other sites

:D This is an EXCELLENT start. I am not sure how to fix this so I will tell you the tweaking that needs to be done and see if it can be done. Only 3 things; First, the length is the total length of the line and I need the "x" distance only from center of manhole to center of manhole not the end of the line. Second, the slope in this lisp is giving me the xy angle of the line. I need rise over run as in "y / x = slope". Third and last, the text height is too tall in my other drawings. I have no idea what the problem is with the text height because it works fine in the drawing that I uploaded.

 

If it helps, and I said this above, our manholes are the same size in all drawings and you could just add the additional footage to the calculated "x" distance?

 

Also, a common mistake, I make it myself and I fixed it already but, the DAI. symbol is %%C instead of %%D. :wink:

 

Thank you very much for your help Lee Mac and looking forward to the finished product! As I have said above, if you need any more info from me just ask.

Link to comment
Share on other sites

:D This is an EXCELLENT start. I am not sure how to fix this so I will tell you the tweaking that needs to be done and see if it can be done.

 

Thanks Stryder - I knew there'd be a few things needed tweaking after reading a few of the previous posts - but I thought I'd start us off with something concrete first :)

 

Only 3 things; First, the length is the total length of the line and I need the "x" distance only from center of manhole to center of manhole not the end of the line.

 

Would you still prefer to select the line only, and have the "x" distance added on? (It would make the LISP more stable this way imo).

 

Second, the slope in this lisp is giving me the xy angle of the line. I need rise over run as in "y / x = slope".

 

This should be easily achieved.

 

Third and last, the text height is too tall in my other drawings. I have no idea what the problem is with the text height because it works fine in the drawing that I uploaded.

 

The text height I am using is just retrieved from the "TEXTSIZE" variable in whatever drawing you are working in - but I can modify this to whatever you desire.

 

Also, a common mistake, I make it myself and I fixed it already but, the DAI. symbol is %%C instead of %%D. :wink:

 

Coincidentally, I noticed this just before you posted this reply - I altered the code in my original post - but thanks for pointing it out all the same.

:thumbsup:

 

 

Cheers

 

Lee

Link to comment
Share on other sites

NICE fast response!!! Very much appreciate your help first off!!!

 

Ok, I agree that selecting the line and adding the "x" distance is the best way. So, that is fine with me.

 

I am not familiar with what sets the textsize variable. The text height that I will use for this callout everytime is 0.1 * Dimscale. In 95% of the time my dimscale is 50 so the height will be 5.

 

Thanks,

Stryder

Link to comment
Share on other sites

OK, this takes care of most of your original requests, let me know if you need anything else altered :thumbsup:

 

(defun c:pipetxt  (/ *error* vlst ovar scl diam manhol lEnt lObj lLen lSpt lEpt lAng lMid)
 (vl-load-com)

 (defun *error*  (msg)
   (if    ovar (mapcar 'setvar vlst ovar))
   (if    (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\nError: " (strcase msg)))
     (princ "\n<-- cancelled -->"))
   (princ))

 (setq    vlst '("OSMODE" "CLAYER")
   ovar (mapcar 'getvar vlst))
 (setvar "OSMODE" 0)

 (or (tblsearch "LAYER" "TXT-100")
     (vla-add (vla-get-layers
        (vla-get-ActiveDocument
          (vlax-get-acad-object)))
          "TXT-100"))

 (or (and (zerop (getvar "DIMSCALE")) (setq scl 1.0))
     (setq scl (getvar "DIMSCALE")))
 (or pip:dia (setq pip:dia )
 (or man:hol (setq man:hol 10.96))
 (initget 6)
 (setq    diam (getreal (strcat "\nSepcify Diameter of Pipeline <" (rtos pip:dia 2 0) "\">: ")))
 (or (not diam) (setq pip:dia diam))
 (initget 6)
 (setq manhol (getreal (strcat "\nSpecify Manhole Diameter <" (rtos man:hol 2 2) "'>: ")))
 (or (not manhol) (setq man:hol manhol))

 (while (and (setq lEnt (car (entsel "\nSelect Pipeline: ")))
         (eq "LINE" (cdadr (entget lEnt))))
   (setq lObj (vlax-ename->vla-object lEnt)
     lLen (+ (vla-get-length lObj) man:hol)
     lSpt (vlax-curve-getStartPoint lObj)
     lEpt (vlax-curve-getEndPoint lObj)
     lAng (angle lSpt lEpt)
     lSlp (/ (- (cadr lEpt) (cadr lSpt)) (- (car lEpt) (car lSpt)))
     lMid (vlax-curve-getPointatParam lObj
        (/ (vlax-curve-getEndParam lObj) 2.0)))
   (if    (and (> lAng 0) (<= lAng (/ pi 2)))
     nil
     (setq lAng (+ lAng pi)))
   (Make_Text lMid (strcat (rtos lLen 2 0) " L.F. OF "
               (rtos pip:dia 2 0) "\"%%C P.V.C. @ "
               (rtos lSlp 2 3) " SLOPE") lAng))
 (mapcar 'setvar vlst ovar)
 (princ))

(defun Make_Text  (pt val rot)
 (entmake (list '(0 . "TEXT")
        '(8 . "TXT-100")
        (cons 10 pt)
        (cons 40 (* 0.1 scl))
        (cons 1 val)
        (cons 50 rot)
        (cons 7 (getvar "TEXTSTYLE"))
        '(71 . 0)
        '(72 . 1)
        '(73 . 1)
        (cons 11 pt))))

Link to comment
Share on other sites

DANG you are FAST!!!! :D

 

Ok, I am still getting the overall length of the line instead of only the "x" distance and the slope (if it can be) needs to have a zero before the decimal and the decimal over one more place to the left, so multiply by 10?? or I can manually update that after I get the text in there. That is NO problem, this already speeds my process up tremendously!!!

 

Sorry I am such a pain!!! You are the greatest!!! :)

Link to comment
Share on other sites

Ok, I am still getting the overall length of the line instead of only the "x" distance

 

 

AHHH -- my misinterpretation! - sorry about that - will fix it now. :D

 

Sorry I am such a pain!!! You are the greatest!!! :)

 

Nah, you aren't a pain - at least you are appreciative :D

 

Thanks

 

Lee

Link to comment
Share on other sites

OK, I have modified a few things:

 

  • The zeros preceding your slope measurement are suppressed due to the setting of the DIMZIN variable in your drawings (set to 12), I have modified this in the LISP to overcome this setting, but restore it upon LISP completion.
  • I have modified the slope so that it is a factor of 10.0 smaller, but this is not the value of the measured slope as drawn in the drawings - just wanted to make you aware of this.

(defun c:pipetxt  (/ *error* vlst ovar scl diam manhol lEnt lObj lLen lSpt lEpt lAng lMid)
 (vl-load-com)

 (defun *error*  (msg)
   (if    ovar (mapcar 'setvar vlst ovar))
   (if    (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\nError: " (strcase msg)))
     (princ "\n<-- cancelled -->"))
   (princ))

 (setq    vlst '("CLAYER" "OSMODE" "DIMZIN")
   ovar (mapcar 'getvar vlst))
 (mapcar 'setvar (cdr vlst) '(0 1))

 (or (tblsearch "LAYER" "TXT-100")
     (vla-add (vla-get-layers
        (vla-get-ActiveDocument
          (vlax-get-acad-object))) "TXT-100"))

 (or (and (zerop (getvar "DIMSCALE")) (setq scl 1.0))
     (setq scl (getvar "DIMSCALE")))
 (or pip:dia (setq pip:dia )
 (or man:hol (setq man:hol 10.96))
 (initget 6)
 (setq diam (getreal (strcat "\nSepcify Diameter of Pipeline <" (rtos pip:dia 2 0) "\">: ")))
 (or (not diam) (setq pip:dia diam))
 (initget 6)
 (setq manhol (getreal (strcat "\nSpecify Manhole Diameter <" (rtos man:hol 2 2) "'>: ")))
 (or (not manhol) (setq man:hol manhol))

 (while (and (setq lEnt (car (entsel "\nSelect Pipeline: ")))
         (eq "LINE" (cdadr (entget lEnt))))
   (setq lObj (vlax-ename->vla-object lEnt)
     lSpt (vlax-curve-getStartPoint lObj)
     lEpt (vlax-curve-getEndPoint lObj)
     lAng (angle lSpt lEpt)
     lSlp (/ (- (cadr lEpt) (cadr lSpt)) (- (car lEpt) (car lSpt)))
     lLen (+ (abs (- (car lEpt) (car lSpt))) man:hol)
     lMid (vlax-curve-getPointatParam lObj
        (/ (vlax-curve-getEndParam lObj) 2.0)))
   (if    (and (> lAng 0) (<= lAng (/ pi 2))) nil
     (setq lAng (+ lAng pi)))
   (Make_Text lMid (strcat (rtos lLen 2 0) " L.F. OF "
              (rtos pip:dia 2 0) "\"%%C P.V.C. @ "
              (rtos (/ lSlp 10.0) 2 3) " SLOPE") lAng))
 (mapcar 'setvar vlst ovar)
 (princ))

(defun Make_Text  (pt val rot)
 (entmake (list '(0 . "TEXT")
        '(8 . "TXT-100")
        (cons 10 pt)
        (cons 40 (* 0.1 scl))
        (cons 1 val)
        (cons 50 rot)
        (cons 7 (getvar "TEXTSTYLE"))
        '(71 . 0)
        '(72 . 1)
        '(73 . 1)
        (cons 11 pt))))

Link to comment
Share on other sites

Actually, this is better:

 

I have modified a few more things:

 

  • If delta x is 0, then the slope will be just a dash. (indicating infinite slope).
  • Text will appear the correct way up, for every angle of line.

(defun c:pipetxt  (/ *error* vlst ovar scl diam manhol lEnt lObj lLen lSpt lEpt lAng lMid)
 (vl-load-com)

 (defun *error*  (msg)
   (if    ovar (mapcar 'setvar vlst ovar))
   (if    (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\nError: " (strcase msg)))
     (princ "\n<-- cancelled -->"))
   (princ))

 (setq    vlst '("CLAYER" "OSMODE" "DIMZIN")
   ovar (mapcar 'getvar vlst))
 (mapcar 'setvar (cdr vlst) '(0 1))

 (or (tblsearch "LAYER" "TXT-100")
     (vla-add (vla-get-layers
        (vla-get-ActiveDocument
          (vlax-get-acad-object))) "TXT-100"))

 (or (and (zerop (getvar "DIMSCALE")) (setq scl 1.0))
     (setq scl (getvar "DIMSCALE")))
 (or pip:dia (setq pip:dia )
 (or man:hol (setq man:hol 10.96))
 (initget 6)
 (setq diam (getreal (strcat "\nSepcify Diameter of Pipeline <" (rtos pip:dia 2 0) "\">: ")))
 (or (not diam) (setq pip:dia diam))
 (initget 6)
 (setq manhol (getreal (strcat "\nSpecify Manhole Diameter <" (rtos man:hol 2 2) "'>: ")))
 (or (not manhol) (setq man:hol manhol))

 (while (and (setq lEnt (car (entsel "\nSelect Pipeline: ")))
         (eq "LINE" (cdadr (entget lEnt))))
   (setq lObj (vlax-ename->vla-object lEnt)
     lSpt (vlax-curve-getStartPoint lObj)
     lEpt (vlax-curve-getEndPoint lObj)
     lAng (angle lSpt lEpt)
     xdis (- (car lEpt) (car lSpt)))
   (if (zerop xdis) (setq lSlp "-")
     (setq lSlp (rtos (/ (- (cadr lEpt) (cadr lSpt)) (* 10.0 xdis)) 2 3)))
   (setq lLen (+ (abs (- (car lEpt) (car lSpt))) man:hol)
     lMid (vlax-curve-getPointatParam lObj
        (/ (vlax-curve-getEndParam lObj) 2.0)))
   (cond ((and (> lAng (/ pi 2)) (<= lAng pi))
      (setq lAng (- lAng pi)))
     ((and (> lAng pi) (<= lAng (/ (* 3 pi) 2)))
      (setq lAng (+ lAng pi)))
     ((or (> lAng (/ (* 3 pi) 2)) (<= lAng (/ pi 2)))
      nil))
   (Make_Text lMid (strcat (rtos lLen 2 0) " L.F. OF "
              (rtos pip:dia 2 0) "\"%%C P.V.C. @ "
              lSlp " SLOPE") lAng))
 (mapcar 'setvar vlst ovar)
 (princ))

(defun Make_Text  (pt val rot)
 (entmake (list '(0 . "TEXT")
        '(8 . "TXT-100")
        (cons 10 pt)
        (cons 40 (* 0.1 scl))
        (cons 1 val)
        (cons 50 rot)
        (cons 7 (getvar "TEXTSTYLE"))
        '(71 . 0)
        '(72 . 1)
        '(73 . 1)
        (cons 11 pt))))

Link to comment
Share on other sites

:D WOW!!! Thank you very much!!! And I really appreciate the additional info about the last few things you modified. This is AWESOME!!! I may have some more projects in the future, if you are interested. I really wish we lived closer so you could teach me how to write lisp files! :D

 

Thanks,

Stryder

Link to comment
Share on other sites

:D WOW!!! Thank you very much!!! And I really appreciate the additional info about the last few things you modified. This is AWESOME!!! I may have some more projects in the future, if you are interested. I really wish we lived closer so you could teach me how to write lisp files! :D

 

Thanks,

Stryder

 

No Problem at all - happy to help you out :)

 

If you need anything in the future, just ask. :P

 

LISP really does make the process much faster - so learning the code is a real benefit - there are tons of tutorial sites out there, just search the threads on here, or google such names as: AfraLISP, JefferySanders, RonLeigh... etc

 

Cheers

 

Lee

Link to comment
Share on other sites

Well, after using this lisp for a while, I love it!! However, the guys that I work with and I have been discussing just a few minor changes. We would like to have mtext instead of dtext, the bottom center is still good on the justification but we will need to give an offset value from the line. This is because mtext bottom center is different than dtext bottom center, the mtext bc will put the text right on the line. We would also like to be able to adjust the distance before placing the text, like you did with the pipe dia and the mh dia. Give it a default of something that looks good but then allow us to change it if we need to. The reason for the mtext is because sometimes the distance between the manholes is so close that we want to be able to adjust the width of the text. We were doing this by converting the dtext to mtext but then it adjusted the position and we had to move it back... and we are lazy!!! :)

 

So, is this possible?

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