Jump to content

Recommended Posts

Posted (edited)

Hello! I've recently discovered AutoLisp and am getting the hang of it. To start off, I want to make a simple program that shouldn't be too difficult to write, but I currently su_k at Lisp syntax. could anyone help me out with my code?

 

The program is designed for aid with descriptive geometry, so here is what I want the program to do:

 

define a point A

- I assign it 3 separate variables. These are the x, y, z coordinates of point A.

 

i then translate these 3D coordinates into 2D space, onto the first and second 'drawing plane'

 

- from the X and Y coord., i want to make the point A1 (X1, Y1)

- from the X and Z coord., i want to make the point A2 (X1, Y2=-Z)

- then insert a predefined block onto point A1 and A2

 

repeat for point B

 

draw the line AB in each plane

 

- draw a line between A1 and B1

- draw a line between A2 and B2

 

that is pretty much all I want to accomplish right now, as I just started yesterday. I currently need help with:

- making a coordinate (x/y/z) a usable variable

- error: not enough/too many arguments. not sure how to get that right..

 

here is the code i have written so far, to clarify my progress.

 

(defun c: ADefXYZ ()
;define the position of point A

(setq Ax (getreal "\specify first coordinate of point A: "))
(setq Ay (getreal "\specify second coordinate of point A: "))
(setq Az (getreal "\specify third coordinate of point A: "))

(defun c: DefPos (Ax Ay Az \ a1 a2)
		(setq a1 (Ax Ay))
		;get the coordinates of A' 

		(setq a2 (Ax Az))
		;get the coordinates of A''
)
)
(defun c:d1a (\)
(command "insert" "ta1" a1 1 1 0)
;draw the A1 point
)

(defun c:d2a (\)
(command "insert" "ta2" a2 1 1 0)
;draw the A2 point
)	

(defun c:lnp1 (\)
(command "xline" a1 b1 "")
;draw the line on the first plane
)	

(defun c:lnp2 (\)
(command "xline" a2 b2 "")
;draw the line on the second plane

(defun *ERROR* (ErrStr)
(print ErrStr)
)
;end of defun
(princ)

 

any help is greatly appreciated!

cheers

Edited by popey3
  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • popey3

    8

  • CADWarrior

    6

  • David Bethel

    2

  • Lee Mac

    2

Posted

Welcome aboard

 

I'd look into a bit of a different approach:

 

[b][color=BLACK]([/color][/b]defun c:test [b][color=FUCHSIA]([/color][/b]/ p1 p2 x1 y1 z1 x2 y2 z2[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq p1 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\n1st Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq x1 [b][color=NAVY]([/color][/b]nth 0 p1[b][color=NAVY])[/color][/b]
       y1 [b][color=NAVY]([/color][/b]nth 1 p1[b][color=NAVY])[/color][/b]
       z1 [b][color=NAVY]([/color][/b]nth 2 p1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq p2 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\n2nd Point:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq x2 [b][color=NAVY]([/color][/b]nth 0 p2[b][color=NAVY])[/color][/b]
       y2 [b][color=NAVY]([/color][/b]nth 1 p2[b][color=NAVY])[/color][/b]
       z2 [b][color=NAVY]([/color][/b]nth 2 p2[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq a1 [b][color=NAVY]([/color][/b]list x1 y1 0[b][color=NAVY])[/color][/b]
       a2 [b][color=NAVY]([/color][/b]list x1 y2 0[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
[b][color=BLACK])[/color][/b]

 

 

While I don't quite understand your need with this

- from the X and Z coord., i want to make the point A2 (X1, Y2=-Z)

 

I would definitely recommend assigning values to all 3 axis.

 

You'll probably get a nudge to use code tags around any snippets of autolisp code.

 

Hope this gets you started. -David

Posted

Not 100% sure what you are looking for or the purpose of this lisp but this should get you started.

 

(defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
      (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
 ;;(169.433 44.3076 0.0)   This is a List of points ( X Y Z )
 (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
 (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
 (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
 (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
 (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
 (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 (list Ax Ay Az)) ;;1st point if you would not like to specify Az replace with 0.0
	 (cons 11 (list Bx By Bz)) ;;2nd point if you would not like to specify Az replace with 0.0
	 (cons 210 (list 0.0 0.0 1.0))))
 )

 

It is the same basic thing as David's lisp just explains things a bit more.

Posted

thank you, i will look into it!

 

the (y2=-z) is because the point's projected Z coordinate corresponds to the negative value of Z applied to the Y axis.

 

basically what is happening is a point is taken from 3D space and drawn onto two planes that overlap, but show a top and side view respectively, separated by the X axis.

some visual aid:

http://www.grad.hr/geomteh3d/Monge/02tocka/05.png

Posted

 

Not going to lie that made my head hurt a little bit. That goes against everything I have ever learned in drafting and 3D modeling. But with that picture it brings up the questions. If you have a -z or -y coord will it leak into the Y or Z planes respectively?

Posted

Sorry for double post just encase he had already been here still kind of scratching my head over this one.

 

This is my best guesses for what you are looking for

 

;;different graphs
(defun c:ADefXYZ1 (/ pointA pointB Ax Ay Az Bx By Bz)
 (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
 (setq Startpoint1 (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
 (setq Startpoint2 (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
 ;;(169.433 44.3076 0.0)   This is a List of points ( X Y Z )
 (setq Xoff1 (nth 0 Startpoint1));;selects the 1st variable in the list 
 (setq Yoff1 (nth 1 Startpoint1));;selects the 2nd variable in the list 
 (setq Zoff1 (nth 2 Startpoint1));;selects the 3rd variable in the list 
 (setq Xoff2 (nth 0 Startpoint2));;selects the 1st variable in the list 
 (setq Yoff2 (nth 1 Startpoint2));;selects the 2nd variable in the list 
 (setq Zoff2 (nth 2 Startpoint2));;selects the 3rd variable in the list 
 (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
 (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
 (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
 (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
 (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
 (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
 (setq A1 (list (+ Ax Xoff1) (+ Ay Yoff1) 0.0)) ;; finds coords based on startpoint offset
 (setq A2 (list (+ Ax Xoff2) (+ (* -1 Az) Yoff2) 0.0));; finds coords based on startpoint offset
 (setq B1 (list (+ Bx Xoff1) (+ By Yoff1) 0.0));; finds coords based on startpoint offset
 (setq B2 (list (+ Bx Xoff2) (+ (* -1 Bz) Yoff2) 0.0));; finds coords based on startpoint offset
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 A1) ;;1st point if you would not like to specify Az replace with 0.0
	 (cons 11 B1) ;;2nd point if you would not like to specify Bz replace with 0.0
	 (cons 210 (list 0.0 0.0 1.0))))
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 A2) ;;1st point if you would not like to specify Az replace with 0.0
	 (cons 11 B2) ;;2nd point if you would not like to specify Bz replace with 0.0
	 (cons 210 (list 0.0 0.0 1.0))))
 )


;;same graph
(defun c:ADefXYZ2 (/ pointA pointB Ax Ay Az Bx By Bz)
 (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
 (setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
 ;;(169.433 44.3076 0.0)   This is a List of points ( X Y Z )
 (setq Xoff (nth 0 Startpoint1));;selects the 1st variable in the list 
 (setq Yoff (nth 1 Startpoint1));;selects the 2nd variable in the list 
 (setq Zoff (nth 2 Startpoint1));;selects the 3rd variable in the list 
 (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
 (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
 (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
 (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
 (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
 (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
 (setq A1 (list (+ Ax Xoff) (+ Ay Yoff) 0.0));; finds coords based on startpoint offset
 (setq A2 (list (+ Ax Xoff) (+ (* -1 Az) Yoff) 0.0));; finds coords based on startpoint offset
 (setq B1 (list (+ Bx Xoff) (+ By Yoff) 0.0));; finds coords based on startpoint offset
 (setq B2 (list (+ Bx Xoff) (+ (* -1 Bz) Yoff) 0.0));; finds coords based on startpoint offset
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 A1) ;;1st point if you would not like to specify Az replace with 0.0
	 (cons 11 B1) ;;2nd point if you would not like to specify Bz replace with 0.0
	 (cons 210 (list 0.0 0.0 1.0))))
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 A2) ;;1st point if you would not like to specify Az replace with 0.0
	 (cons 11 B2) ;;2nd point if you would not like to specify Bz replace with 0.0
	 (cons 210 (list 0.0 0.0 1.0))))
 )

Posted (edited)

hey! yea it's a really painful subject at my UNI. Gets even worse when you project 4+ drawing planes onto the drawing... As almost a rule, the points and lines always bleed across the X axis, making it very difficult to distinguish what is on which plane. Mostly, this is countered by color-coding your drawing.

 

basically it's the fossil remains of a subject from when everything was drawn by hand and this is where you learned to draw geometrically correct shadows. Totally redundant knowledge, but I will take this opportunity to learn AutoLISP, since the tasks to be performed are still quite basic, mostly 'place points and draw lines'.

 

I will check out and try the code you suggested and get back to you. Thank you for help!

 

Edit:

Ok, i've checked it out. This whole concept of drawing is pretty alien and I don't even want you to think about it too much, there are enough people hitting their head against the wall already:)

here is a visual presentation:

http://imageshack.us/photo/my-images/545/dgeometry.jpg/

the Y and Z axis lie on the same line, but are pointed in reverse directions. therefore, when i draw on XZ plane, i just take the -Z value and apply it to Y axis.

Edited by popey3
Posted

Maybe also

 

(setq XYZ (getpoint "\nEnter X,Y,Z"))
(setq x (car xyz))
(setq y (cadr xyz))
(setq z (caddr xyz))

Posted
Maybe also

 

(setq XYZ (getpoint "\nEnter X,Y,Z"))
(setq x (car xyz))
(setq y (cadr xyz))
(setq z (caddr xyz))

 

i see, these are the first, second and third items on the list. one question thoughh, how could I make the third value negative?

Posted

Stop posting pictures your making my head hurt even worse :P

 

I think the part that I dont understand is how you convert a 3D point to a 2D point.....

Only thing i can think of is when a 3D Point is converted to 2D object of 1 dimension higher then what you are trying to represent is required. So, you would draw a line from (X Y) to (X Z). So say you had a point at (3.00 2.00 2.00) and a graph where Positive Y = Z and Negative Y= Y

 

Z
|
|
|      P1 (3.00 2.00)
|
---------------X
|
|      P2 (3.00 2.00)
|
|
Y

 

A line is drawn P1 > P2 creating a Line (1D) from 2 points (0D).

 

But now the question is how do you draw a line between two given points on a graph? We would then go to the next dimension higher 0D (Point) 1D (Line) 2D (Closed Shape)?

 

For the next example lets say we have a point at (3.00 2.00 2.00) and (5.00 4.00 3.00). Would it look like the following?

 

Z
|              P2
|
|      P1
|
---------------X
|
|      P4
|              P3
|
Y  

 

A line is drawn P1 > P2 > P3 > P4 > P1 creating a closed shape.

 

If this is what you are looking for use:

 

(defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
 (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
 (setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
 (setq Xoff (nth 0 Startpoint));;selects the 1st variable in the list 
 (setq Yoff (nth 1 Startpoint));;selects the 2nd variable in the list 
 (setq Zoff (nth 2 Startpoint));;selects the 3rd variable in the list 
 (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
 (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
 (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
 (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
 (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
 (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
 (setq p1 (list (+ Ax Xoff) (+ (* -1 Ay) Yoff)));; finds coords based on startpoint offset
 (setq p2 (list (+ Ax Xoff) (+ Az Yoff)));; finds coords based on startpoint offset
 (setq p3 (list (+ Bx Xoff) (+ Bz Yoff)));; finds coords based on startpoint offset
 (setq p4 (list (+ Bx Xoff) (+ (* -1 By) Yoff)));; finds coords based on startpoint offset
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 P1)
	 (cons 11 P2)
	 ))
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 P2)
	 (cons 11 P3)
	 ))
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 P3) 
	 (cons 11 P4) 
	 ))
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 P4)
	 (cons 11 P1)
	 ))
 )

 

 

***Note that this is based off of the current UCS coords if the UCS is 10k units away from your current points the x y and z are going to be off the charts

 

This picture is an example of what it will do (does not add leaders)

 

adefxyz.png

Posted
i see, these are the first, second and third items on the list. one question thoughh, how could I make the third value negative?

 

I was never a fan of remembering

car cadr caddr and so on i just use nth

(car xyz) = (nth 0 xyz)

(cadr xyz) = (nth 1 xyz)

(caddr xyz) = (nth 2 xyz)

 

i cant remember if there is a command to do the inverse of a number but i just use (* -1 (nth 2 xyz)) which is basically -1*Z

Posted

i know this is getting confusing, but this is what the procedure should do:

 

the points P and T are projected onto two planes, so it becomes 4 points. we never really draw the 3D space, just in the coordinates.

 

the point P(x,y,z) gets broken down into 2 points with coordinates:

P1 (x,y,0)

P2 (x,-z,0)

 

the other point T(x1,y1,z1) also

T1(x1,y1,0)

T2(x1,-z1,0)

 

then i can make 2 lines:

L1 (P1,T1)

L2 (P2,T2)

Posted

Not sure if Z is up or down anymore so just erase the one part that you dont want.

 

(defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
 (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
 (setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
 (setq Xoff (nth 0 Startpoint));;selects the 1st variable in the list 
 (setq Yoff (nth 1 Startpoint));;selects the 2nd variable in the list 
 (setq Zoff (nth 2 Startpoint));;selects the 3rd variable in the list 
 (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
 (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
 (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
 (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
 (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
 (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB

;;if Z is down keep here
 (setq p1 (list (+ Ax Xoff) (+ Ay Yoff)));; finds coords based on startpoint offset
 (setq p2 (list (+ Ax Xoff) (+ (* -1 Az) Yoff)));; finds coords based on startpoint offset
 (setq T1 (list (+ Bx Xoff) (+ By Yoff)));; finds coords based on startpoint offset
 (setq T2 (list (+ Bx Xoff) (+ (* -1 Bz) Yoff)));; finds coords based on startpoint offset
;;if Z is down to here

;;if Z is up keep here
 (setq p1 (list (+ Ax Xoff) (+ (* -1 Ay) Yoff)));; finds coords based on startpoint offset
 (setq p2 (list (+ Ax Xoff) (+ Az Yoff)));; finds coords based on startpoint offset
 (setq T1 (list (+ Bx Xoff) (+ (* -1 By) Yoff)));; finds coords based on startpoint offset
 (setq T2 (list (+ Bx Xoff) (+ Bz Yoff)));; finds coords based on startpoint offset
;;if Z is up to here

 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 P1)
	 (cons 11 T1)
	 ))
 (entmake (list (cons 0 "LINE") ;; Creates a Line
	 (cons 10 P2)
	 (cons 11 T2)
	 ))
 )

 

Why couldnt you have just said all that the first time :lol:

 

The outcome of this code will look the same as above just without the vertical lines connecting the lines between the coords

Posted
FYI: to negate a value:

 

_$ (setq x 10)
10
_$ (- x)
-10

Strange how that works isn't it?
(- 10 2) ;Returns 8
;; BUT!!
(- 10) ;Returns -10

As if there's an implied 0 for a first argument if you only send one argument to the minus function.

 

As for how to change an item in a list, generally you don't do that in lisp. You'd rather just recreate the list. In some cases, like association lists (like DXF code . data pairs) you can use subst with assoc. But using subst basically substitutes one item for something new throughout the list - e.g.

(subst 2 1 '(1 2 3 1 2 3 1 2 3)) ;Returns (2 2 3 2 2 3 2 2 3)

 

You might want to look at a ReplaceNth function: http://www.theswamp.org/index.php?topic=41680.0

 

Though for these point lists, I'd not bother. It's not too difficult to simply do something like this:

;; Say originalPoint = (X Y Z)
(setq newPoint1 (list (car originalPoint) (cadr originalPoint) 0.0)) ; (X Y 0)
(setq newPoint2 (list (car originalPoint) (- (caddr originalPoint)) 0.0)) ; (X -Z 0)

Posted

thanks everybody for the help! i managed to write what i wanted based on what was posted. It now looks like this:

 

(defun c:DrawAB ( / pointA pointB Axx Ayy Azz Byy Bzz)

 (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point

 (setq Axx (nth 0 PointA)) 			;;selects the 1st variable in the list pointA
 (setq Ayy (nth 1 PointA)) 			;;selects the 2nd variable in the list pointA
 (setq Azz (nth 2 PointA)) 			;;selects the 3rd variable in the list pointA

 (setq Bxx (nth 0 PointB)) 			;;selects the 1st variable in the list pointB
 (setq Byy (nth 1 PointB)) 			;;selects the 2nd variable in the list pointB
 (setq Bzz (nth 2 PointB))			;;selects the 3rd variable in the list pointB

 (setq P1 (list (* Axx -1) (* -1 Ayy)))	;;sets coords for p on plane (x-y)
 (setq P2 (list (* Axx -1) Azz))		;;sets coords for p on plane (x-z)
 (setq T1 (list (* Bxx -1) (* -1 Byy)))	;;sets coords for T on plane (x-y)
 (setq T2 (list (* Bxx -1) Bzz))		;;sets coords for T on plane (x-z)

 (command "line" P1 T1 "")			;;draws the line on plane (x-y)
 (command "line" P2 T2 "")			;;draws the line on plane (x-z)
 (command "insert" "tA1" P1 1 1 0)		;;inserts the mark for P on plane (x-y)
 (command "insert" "tA2" P2 1 1 0)		;;inserts the mark for P on plane (x-z)
 (command "insert" "tb1" T1 1 1 0)		;;inserts the mark for T on plane (x-y)
 (command "insert" "tb2" T2 1 1 0)		;;inserts the mark for T on plane (x-z)
 (princ)
)

 

I took out the 'offset from original point' part for now, because I am trying to stay as basic as possible and will keep everything on the original world UCS for now, axis orientation included (the reason for negating the values). I will look into it more once the drawing gets more advanced, so still thanks for the future heads up.

 

I wanted to replace the "line" with "xline", but that gave me mistakes every time (blocks didn't insert on proper position, lines wouldn't reference 2 points, but just a single coordinate). Is there something I should know about the xline command that distorts values?

 

cheers

Posted

Any time that you a use (command ) call and only supply the x & y values, you risk a chance of flakey results. It should default to the current sysvar "ELEVATION" value. But depending on you snap settings, ucs values etc, there is no real good way predicting the exact outcome. You could add "_non" to the point inputs, but that is no gaurntee -David

Posted

ok, i've tried inputing the Z as 0.0, but the xline still gives me schizo results, while the basic line works reliably every time. Therefore I've decided to just extend the generated line to a predefined rectangle edge instead that serves as the printing margin. So far, I think I have renamed the lines and rectangle to VLA-objects, but now there is a whole new VLA-command spectrum to understand:P

 

could someone show me a mock up of how to extend (or lengthen) a VLA-line?

also, is there a way to input a X coordinate and receive the point on the line with that coordinate?

 

so right now my code looks like this:

 (vl-load-com)

;;********************************************************************************************

(defun c:frame ( / )				;;Draw the frame for the entire drawing

 (setq corner1 (list -15.5 15 0))
 (setq corner3 (list 5.5 -14 0))
 (command "rectangle" corner1 corner3)
 (setq F1 (entlast))
 (setq FrameO(vlax-ename->vla-object F1))
)

;;********************************************************************************************

;;Define the coordinates of point A

(defun c:defA ( / )				

 (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point

 (setq Axx (nth 0 PointA)) 			;;selects the 1st variable in the list pointA
 (setq Ayy (nth 1 PointA)) 			;;selects the 2nd variable in the list pointA
 (setq Azz (nth 2 PointA)) 			;;selects the 3rd variable in the list pointA

 (setq A1 (list (* Axx -1) (* -1 Ayy) 0.0))	;;sets coords for p on plane (x-y)
 (setq A2 (list (* Axx -1) Azz 0.0))		;;sets coords for p on plane (x-z)
)


;;********************************************************************************************

;;Define the coordinates of point B

(defun c:defB ( / )				

 (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point

 (setq Bxx (nth 0 PointB)) 			;;selects the 1st variable in the list pointB
 (setq Byy (nth 1 PointB)) 			;;selects the 2nd variable in the list pointB
 (setq Bzz (nth 2 PointB))			;;selects the 3rd variable in the list pointB

 (setq B1 (list (* Bxx -1) (* -1 Byy) 0.0))	;;sets coords for T on plane (x-y)
 (setq B2 (list (* Bxx -1) Bzz 0.0))		;;sets coords for T on plane (x-z)
)


;;********************************************************************************************

;;Draw line with (X,Y) coordinates

(defun c:DrawP1 ( / pointA pointB Axx Ayy Azz Bxx Byy Bzz p1)

 (entmake (list (cons 0 "LINE")(cons 10 A1)(cons 11 B1)))
 (setq p1 (entlast))
 (setq p1i(vlax-ename->vla-object p1))
)


;;********************************************************************************************

;;Draw line with (X,Z) coordinates

(defun c:DrawP2 ( / pointA pointB Axx Ayy Azz Bxx Byy Bzz p2)
					;;
 (entmake (list (cons 0 "LINE")(cons 10 A2)(cons 11 B2)))
 (setq p2 (entlast))
 (setq p2i(vlax-ename->vla-object p2))
 (vla-lengthen p2 "dy" 5)
 (vla-lengthen p2 "dy" -5)
)


;;********************************************************************************************

(defun c:insA ( / )

 (command "insert" "tA1" A1 1 1 0)		;;inserts the mark for P on plane (x-y)
 (command "insert" "tA2" A2 1 1 0)		;;inserts the mark for P on plane (x-z)
)


;;********************************************************************************************

(defun c:insB ( / )
 (command "insert" "tb1" B1 1 1 0)		;;inserts the mark for T on plane (x-y)
 (command "insert" "tb2" B2 1 1 0)		;;inserts the mark for T on plane (x-z)
)

;;********************************************************************************************


(princ)

Posted (edited)
could someone show me a mock up of how to extend (or lengthen) a VLA-line?

 

You would need to calculate the coordinates of the new start & end points of the line, then alter the Startpoint & Endpoint properties of the VLA Line Object. However, this is unnecessary, since you may as well create a Line of the correct length and position in the first place.

 

also, is there a way to input a X coordinate and receive the point on the line with that coordinate?

 

For an arbitrary line in 3D, you could either calculate the line vector (using the start & end points of the line) and then calculate the coordinate of the point with the given X-coordinate (if it exists) using the equation of the line; or, you could calculate the intersection between the line vector and the Y-Z plane with origin (or 'elevation') at the given X-coordinate.

e.g. using my Line-Plane Intersection function from here:

 

[color=GREEN];; Line-Plane Intersection  -  Lee Mac[/color]
[color=GREEN];; Returns the point of intersection of a line defined by[/color]
[color=GREEN];; points p1,p2 and a plane defined by its origin and normal[/color]

([color=BLUE]defun[/color] LM:IntersLinePlane ( p1 p2 org nm )
   ([color=BLUE]setq[/color] org ([color=BLUE]trans[/color] org 0 nm)
         p1  ([color=BLUE]trans[/color] p1  0 nm)
         p2  ([color=BLUE]trans[/color] p2  0 nm)
   )
   ([color=BLUE]trans[/color]
       ([color=BLUE]inters[/color] p1 p2
           ([color=BLUE]list[/color] ([color=BLUE]car[/color] p1) ([color=BLUE]cadr[/color] p1) ([color=BLUE]caddr[/color] org))
           ([color=BLUE]list[/color] ([color=BLUE]car[/color] p2) ([color=BLUE]cadr[/color] p2) ([color=BLUE]caddr[/color] org))
           [color=BLUE]nil[/color]
       )
       nm 0
   )
)

(LM:IntersLinePlane [color=red]<line-startpoint>[/color] [color=red]<line-endpoint>[/color] ([color=BLUE]list[/color] [color=red]<X-coord>[/color] 0.0 0.0) '(1.0 0.0 0.0))

Or, for a 2D line in the plane, you could use the inters function (with onseg parameter set to nil), to find the intersection between the line vector and a vector extending from a point in the plane with the given X-coordinate, e.g. for a line in the X-Y plane:

 

([color=blue]inters [/color][color=red]<line-startpoint> <line-endpoint>[/color] ([color=blue]list [/color][color=red]<X-coord>[/color] 0.0 0.0) ([color=blue]list [/color][color=red]<X-coord>[/color] 1.0 0.0) [color=blue]nil[/color])

Or even with a touch of trigonometry:

 

([color=blue]if [/color]([color=blue]not [/color]([color=blue]equal [/color]0.0 ([color=blue]cos [/color]([color=blue]setq [/color]ang ([color=blue]angle [/color][color=red]<line-startpoint>[/color] [color=red]<line-endpoint>[/color]))) 1e-)
   ([color=blue]list[/color]
       [color=red]<X-coord>[/color]
       ([color=blue]+ [/color]([color=blue]cadr [/color][color=red]<line-startpoint>[/color]) ([color=blue]*[/color] ([color=blue]- [/color][color=red]<X-coord>[/color] ([color=blue]car [/color][color=red]<line-startpoint>[/color])) ([color=blue]/[/color] ([color=blue]sin [/color]ang) ([color=blue]cos[/color] ang))))
       0.0
   )
)

For what its worth, here are my thoughts on a program based on your last code:

 

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] a1 a2 b1 b2 pa pb )
   
   (myrectangle '(-15.5 15.0) '(5.5 -14.0))
   
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] pa ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify Point A: "[/color]))
           ([color=BLUE]setq[/color] pb ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify Point B: "[/color]))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] a1 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pa)) ([color=BLUE]-[/color] ([color=BLUE]cadr[/color] pa)) 0.0)
                 b1 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pb)) ([color=BLUE]-[/color] ([color=BLUE]cadr[/color] pb)) 0.0)
                 a2 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pa)) ([color=BLUE]caddr[/color] pa) 0.0)
                 b2 ([color=BLUE]list[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] pb)) ([color=BLUE]caddr[/color] pb) 0.0)
                 a2 ([color=BLUE]polar[/color] a2 ([color=BLUE]angle[/color] b2 a2) 5)
                 b2 ([color=BLUE]polar[/color] b2 ([color=BLUE]angle[/color] a2 b2) 5)
           )
           (myline a1 b1)
           (myline a2 b2)
           ([color=BLUE]foreach[/color] bk '([color=MAROON]"ta1"[/color] [color=MAROON]"ta2"[/color] [color=MAROON]"tb1"[/color] [color=MAROON]"tb2"[/color])
               (myblock bk ([color=BLUE]eval[/color] ([color=BLUE]read[/color] ([color=BLUE]substr[/color] bk 2))))
           )
       )
   )
   ([color=BLUE]princ[/color])
)

([color=BLUE]defun[/color] myline ( a b )
   ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"LINE"[/color]) ([color=BLUE]cons[/color] 10 a) ([color=BLUE]cons[/color] 11 b)))
)

([color=BLUE]defun[/color] myrectangle ( a b )
   ([color=BLUE]entmakex[/color]
       ([color=BLUE]list[/color]
          '(000 . [color=MAROON]"LWPOLYLINE"[/color])
          '(100 . [color=MAROON]"AcDbEntity"[/color])
          '(100 . [color=MAROON]"AcDbPolyline"[/color])
          '(090 . 4)
          '(070 . 1)
           ([color=BLUE]cons[/color] 10 a)
           ([color=BLUE]list[/color] 10 ([color=BLUE]car[/color] b) ([color=BLUE]cadr[/color] a))
           ([color=BLUE]cons[/color] 10 b)
           ([color=BLUE]list[/color] 10 ([color=BLUE]car[/color] a) ([color=BLUE]cadr[/color] b))
       )
   )
)

([color=BLUE]defun[/color] myblock ( n p )
   ([color=BLUE]if[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] n)
       ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]cons[/color] 2 n) ([color=BLUE]cons[/color] 10 p)))
       ([color=BLUE]prompt[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nBlock "[/color] n [color=MAROON]" undefined."[/color]))
   )
)

([color=BLUE]princ[/color])

Though, I haven't read this thread in its entirety, so there may well be a better method to achieve the result you are looking to obtain.

 

Note that the above does not account for UCS variation.

Edited by Lee Mac

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