Jump to content

Draw vertical line


robertbon

Recommended Posts

Help please! I am trying to write a quick lisp routine to draw a vertical line from a user selected point:

 

(defun c:lz()
(setq pt1 (getpoint " Pick Point: "))
(setq x (rtos (car pt1)))
(setq y (rtos (cadr pt1))) 
(setq pt2 (strcat x "," y ",100"))
(command "line" pt1 pt2 "")
)

 

e.g. if I click on point 10,20 it will draw a line from 10,20,0 to 10,20,100.

 

How do I get the pt2 variable into the line command without it being a string?

 

Thanks,

 

Rob

Link to comment
Share on other sites

Thanks, 7o7.

 

That was stage 1 of 2 for what I am trying to achieve:

 

I have 2 view ports, 1 for plan and 1 for elevation. I draw the vertical line in the plan using lz routine above. I then switch to the elevation vport and I want to change the z value of the line I just created line to 0, relative to the elevation vport.

 

How can I do this?

 

Thanks,

 

Rob

 

1. Line is drawn vertically from plan

2. I switch to vport in front view.

3. I want to change the z value of the line to 0

Link to comment
Share on other sites


(defun c:lz()
(setq SnapVal (getvar "osmode"))
(setq pt1 (getpoint " Pick Point: "))
(command "osmode" "0")
(setq pt2 (list (car pt1) (cadr pt1) 100))
(command "line" pt1 pt2 "")
(command "osmode" SnapVal)
)

 

2 refinements required:

 

1. If I click on an end point of a line in plan it creates a zero-length line? I added osmode 0 to code but it does not overcome this.

2. Due to rounding precision the lines aren't truly vertical - if I wanted to use @0,0,100 for pt2 instead how would I implement that?

Link to comment
Share on other sites

Consider this mod .

 

(defun c:lz (/ p1 )
 (while (setq p1 (getpoint "\n Pick Point: "))
   (entmake (list '(0 . "LINE")(cons 10 p1) (cons 11 (polar p1 (/ pi 2.) 100.))))
   )
 (princ)
 )

Link to comment
Share on other sites

Thanks Tharwat,

 

I have tried this and a couple of variations but I am still having the same problems as above:

 

1. If I have snaps on and click on an end point of a line in plan it creates a zero-length line? I added osmode 0 to code after selecting pick point but it does not overcome this.

2. Due to rounding precision the lines aren't truly vertical - (command "line" pt1 "@0,0,100" "") still gives me slightly non-vertical lines, though it works fine when I do it manually in the command line

 

Can anyone shed some light on this for me? I am drawing lots of elevations based on floor plans and typing @0,0,100 for every vertical line from plan is sending me slowly mad!

 

Rob

Link to comment
Share on other sites

Vertical line relative to UCS:

(defun c:vl1 ( / p )
   (if (setq p (getpoint "\nSpecify point for line: "))
       (entmake
           (list
              '(0 . "LINE")
               (cons 10 (trans p 1 0))
               (cons 11 (trans (mapcar '+ p '(0 100 0)) 1 0))
           )
       )
   )
   (princ)
)

 

Vertical line relative to WCS:

(defun c:vl2 ( / p )
   (if (setq p (getpoint "\nSpecify point for line: "))
       (entmake
           (list
              '(0 . "LINE")
               (cons 10 (trans p 1 0))
               (cons 11 (mapcar '+ (trans p 1 0) '(0 100 0)))
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

  • 8 years later...

Hi,

 

I'm trying to alter Lee's lisp vl1 so that the length of the line can be set on the go.

Its currently defined as 100

(cons 11 (trans (mapcar '+ p '(0 100 0)) 1 0))

 

This is where I have got to, but I'm not sure what I am doing, its probably not the right way, it errors:

 

Command: VLE2
Specify point for line: Enter Y Value: 44.51
; error: bad argument type: numberp: V

 

;;;Vertical line relative to UCS:

(defun c:vle2 ( / p )
   (setq p (getpoint "\nSpecify point for line: "))
		(if (setq v (getreal "\Enter Y Value: "))
       (entmake
           (list
              '(0 . "LINE")
               (cons 10 (trans p 1 0))
               (cons 11 (trans (mapcar '+ p '(0 v 0)) 1 0))
           )
       )
   )
   (princ)
)

 

Pleas can you show me where I'm going wrong?

 

Thanks

 

Link to comment
Share on other sites

You're almost right. Your error results in the sense that you are using the quoted expression: '(0 v 0). When you quote an expression, everything is interpreted as its face-value, meaning the variable v is not evaluated to what the value is supposed to be and is read as a symbol. That's why the error you're encountering indicates that the symbol V has been passed when a number is to be expected.

 

To fix it, you will need to open a list. So instead of '(0 v 0), you should write (list 0 v 0) instead, so that v is evaluated to your user input.

  • Like 3
Link to comment
Share on other sites

Ah balls.  I thought I had it.

 

Looks like

(cons 11 (trans (mapcar '+ p (list 0 v 0)) 1 0))

adds the value of 'v' to the existing 'p' coordinates, so it is all relative to 'p', whereas i want 'v' to be an absolute value.

 

so I need to take 'p' and substitute the Y value for the value of 'v'

 

;;;Vertical line relative to UCS:

(defun c:vlu ( /  )
   (setq p (getpoint "\nSpecify point for line: "))
		(setq v (getreal "\nEnter Y Value: "))
		(setq p2 (list (car p) v (caddr p)))
       (entmake
           (list
              '(0 . "LINE")
               (cons 10 (trans p 1 0))
               (cons 11 (trans p2 1 0))
           )
       )
   (princ)
)

 

Seems to be working..  I removed the if statement as I'm not sure how to make it work for more than one statement.

Link to comment
Share on other sites

8 hours ago, Least said:

Ah balls.  I thought I had it.

 

Looks like

(cons 11 (trans (mapcar '+ p (list 0 v 0)) 1 0))

adds the value of 'v' to the existing 'p' coordinates, so it is all relative to 'p', whereas i want 'v' to be an absolute value.

 

so I need to take 'p' and substitute the Y value for the value of 'v'

 

;;;Vertical line relative to UCS:

(defun c:vlu ( /  )
   (setq p (getpoint "\nSpecify point for line: "))
		(setq v (getreal "\nEnter Y Value: "))
		(setq p2 (list (car p) v (caddr p)))
       (entmake
           (list
              '(0 . "LINE")
               (cons 10 (trans p 1 0))
               (cons 11 (trans p2 1 0))
           )
       )
   (princ)
)

 

Seems to be working..  I removed the if statement as I'm not sure how to make it work for more than one statement.

 

Use the PROGN function to group multiple expressions whilst only returning the last evaluated expression:

(if (setq p2 (getreal ...))
  (progn
    ;; Everything true here
  )
  (progn
    ;; Everything false here
  )
)


In your case, you don't need the false statement.

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