Jump to content
Sheep

Make line by user input (length) and add text under the line.

Recommended Posts

Sheep

Hi to all.

I've learned alot from this forum and i manage to make a lisp by reading this forum. But for this matter (refer image), i have no idea how to do it. I know about GETDIST to get the distance (setq Dd (getdist "\nPick first point)) and it will print out 30.

1. How do i make a line with length (user input) with datum of a value (user input)?

2. How do i created the text ( distance, level and additional text such as cut area) under the line? Let say i want to enter the length (or height?) as 20.0 with a caption. I want to enter the value and caption with a comma between the word (e.g: 20.0,borderline).

3. If i only enter only the value (no caption), how do i use the value ( car, caddr ?) and LISP will still accept it.

4. How do i space the gap between distance (0.00) and height ( 20.0).

5. Should i use GETPOINT fot the first point or straight away GETDIST to create the text?

Thank for your answer and time. I've no knowledge on VL@ActiveX, can you please guide me using non VL sample.

0.PNG

Edited by Sheep
Typo

Share this post


Link to post
Share on other sites
dlanorh

To entmake a line you need two points. To entmake a line from a start point of a set length you need one point, a distance and an angle. With these you can calculate the second point using

 

(setq pt2 (polar pt1 angle distance); where angle should be in radians

look  HERE for Lee's excellent minimum requiirements to entmake objects.

 

The easiest way to space a gap in text is using a space " ", but since most text styles are not monospace this changes for each text style. It is probably better to make three text items having calculated the maximum length for the middle piece of text, then right justify numbers. In your example the "additional" text if it is present goes a set distance from the top of the line (left justified) whilst the distance and datum go below (right justified) with each having a set distance below. The justifications are controlled by the dxf code groups 72 and 73 in the entmake process.

 

car cadr and caddr are list functions to return the first, second and third items in a list, so given a point list car returns x, cadr y and caddr z

Edited by dlanorh
spelling
  • Thanks 1

Share this post


Link to post
Share on other sites
BIGAL

Quick answer,s I have draw line L U D R so l50 draws a line 50 units to left that answers your 1st problem,

re the text use (getstring "pick text or blank scrren for non") the string will be returned as nil if you press enter or pick screen then use a If and strcat to make string,

re gap as you have made a line a (entlast will return the start and end points so add a X or Y value depending on L U D R,

the 1st point will be be up to you for method can use the text as an option but it will not be used as text so pick again.

 

LUDR-pline.lsp

  • Thanks 1

Share this post


Link to post
Share on other sites
Sheep
2 hours ago, BIGAL said:

Quick answer,s I have draw line L U D R so l50 draws a line 50 units to left that answers your 1st problem........

Thanks @BIGAL for your answer. I want the line to be always UP and i dont have to type U (just a plain number). For example: Line length is 50 (user input) it will create the line at (e.g 0,0,0) at 90 degree and i can pick another point (a loop?) and it will create a new line next to it ( distance first point and second point).

Actually i want to learn how to create an earth profile (existing level and then create proposed level).

I found a LISP that creates earth profile from Pedro in Autodesk forum, but it's far too advance for me to understand. That's way i asked part by part so i can understand the routine part by part.

Also thank you to @dlanorh for your tips.

Share this post


Link to post
Share on other sites
Sheep

@dlanorh@BIGAL, i've managed to create the line using (* PI (/ a 180.0) and put it as (setq p1 (polar PP (DTR 90.0) PP1)) and create the line by using (command "LINE" TP p1).

So my next question

1.how do i loop so i can pick another point? (SOLVED)

2. How do create the profile next ( or anywhere) to the plan? All the point picking on the site plan. (ALMOST SOLVE)

0.PNG

Edited by Sheep
Solved No.1 (just add "while" function)

Share this post


Link to post
Share on other sites
dlanorh

1. You don't need to convert the angle to radians if it is always up. The angle will always be (* pi 0.5) radians

 

2.If you calculate the points for the end of the line in order then store the point in a list. It would be prudent to strip the z coord whilst doing it

 

(setq pt_lst (cons (reverse (cdr (reverse pt))) pt_lst)) ;cdr returns the rest of a list minus the first entry

3. The list (x y) can now be fed into Lee's minimal entmake LWPolyline function

 

(lwpoly pt_lst 0) ; the 0 is for the group code 70 and denotes an open polyline

 

(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))

 

  • Thanks 1

Share this post


Link to post
Share on other sites
BIGAL

My version of pline from points. Lee;s is faster.

 

; create pline from a list of points
; By Alan H March 2019

(defun AHpllst ( lst / x)
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(repeat (setq x (length lst))
(command (nth (setq x (- x 1)) lst))
)
(command "")
)
)

 

Edited by BIGAL
  • Thanks 1

Share this post


Link to post
Share on other sites
Sheep

Thank you @dlanorh and @BIGAL for your jump starts. My previous question about creating the profile at@next to the site plan, i can call it ALMOST SOLVED ( i think i can figure it out). But i just bumped into a new problem:

1. How to i create the distance? Should i do put the code provided by @dlanorh in the same DEFUN or should i crate a new DEFUN just for the next point onwards?

Please comment my try thank you.

(defun TitikPertama () ;First point.
(setq LokasiTP (getpoint "\nPick the first point: "))
(setq TinggiTP (getreal "\nEnter the existing level: "))
(setq KorTPxy '(0 0 0))				
(setq TitikTP (	polar KorTPxy (DTR 90.0) TinggiTP))
(command "LINE" KorTPxy TitikTP "")
(command "CIRCLE"KorTPxy "D" "1" "")
(entmake (list (cons 0 "text")(cons 10(list  -0.71 -7.98 0.0))(cons 40 1) (cons 50 1.57143)(cons 1 "TinggiTP" ))))
(princ)

 

Share this post


Link to post
Share on other sites
BIGAL

You can pick numerical text and get its value "\nEnter the existing level: "

 

;;-------------------=={ Parse Numbers }==--------------------;;`
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)

(setq RL (car (LM:ParseNumbers (cdr (assoc 1 (entget (car (entsel "\nPick  text"))))))))
 

  • Thanks 1

Share this post


Link to post
Share on other sites
Sheep
1 hour ago, BIGAL said:

You can pick numerical text and get its 

(setq RL (car (LM:ParseNumbers (cdr (assoc 1 (entget (car (entsel "\nPick  text"))))))))
 

Thank you. Great, now im getting somewhere.

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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