Jump to content
TheyCallMeJohn

Modify an X, Y, X Point Using Math

Recommended Posts

TheyCallMeJohn

Hey Guys,

Its been a awhile since I have done any Autolisp programming and I am stuck...

 

I am using a conditional statement to generate a number i.e. 1.625 and then I want to add that to the Z elevation of a point but it keep erroring out at this line. I have spent about an hour and half looking back thru resources and haven't been able to find the correct syntax.

 

This is the line erroring out:

 

(setq NEWPT1 (APPEND (LIST (CAR USRP1) (CADR USRP1)) (+ (CDDR USRP3) TRAP_Z_OFF))) ; ERRORS OUT HERE 

 

Here is the full code.

 

(defun C:droptrap()
(command "UNDO" "BEGIN")
(initerr)
(setvar "lunits" 2)
   (setvar "luprec" 4)
(setvar "attreq" 0)
(command "UNDO" "BEGIN")
(setq OLDCMD (GETVAR "CMDECHO"))
(setvar "CMDECHO" 0)
(setq OLDOSMODE (GETVAR "OSMODE"))
(setvar "OSMODE" 0)
(setq OLDORTHOMODE (GETVAR "ORTHOMODE"))
(vl-load-com)
(setq thisdrawing (vla-get-activedocument (vlax-get-acad-object)))
(initget "1 2 3 4")
(setq TRAP_TYPE (getkword "\n Select trapeze type: ([1]:1-5/8x1-5/8, [2]:1-5/8x1-5/8 B2B, [3]1-5/8x13/16, [4]1-5/8x13/16 B2B):  "))
(if (or (= TRAP_TYPE "1")(= TRAP_TYPE "3"))
	(progn
		(initget "1 2")
		(setq FACE_DIR (getkword "\n Trapeze opening up or down?: ([1]:UP [2]:Down):  "))
	)
	(setq FACE_DIR "1")
)
(cond
	((and (= TRAP_TYPE "1")(= FACE_DIR "2"))
		(setq TRAP_Z_OFF 1.625))
	((and (= TRAP_TYPE "3")(= FACE_DIR "2"))
		(setq TRAP_Z_OFF 0.8125))
	(T (setq TRAP_Z_OFF 0.0))
)
(setq blockname "TRAP-XDATA-T1_1.625")
(setq USRP1 (GETPOINT "\n Select center point of rod 1: "))
(setq USRP2 (GETPOINT "\n Select center point of rod 2: "))
(setq USRP3 (getpoint "\n Select elevation of attachment point: "))
(setq NEWPT1 (APPEND (LIST (CAR USRP1) (CADR USRP1)) (+ (CDDR USRP3) TRAP_Z_OFF))) ; ERRORS OUT HERE 
(setq NEWPT2 (APPEND (LIST (CAR USRP2) (CADR USRP2)) (+ (CDDR USRP3) TRAP_Z_OFF))) ; ERRORS OUT HERE TOO
(setq MIDPT (POLAR NEWPT1 (ANGLE NEWPT1 NEWPT2) (* (DISTANCE NEWPT1 NEWPT2) 0.5)))
(setvar "ORTHOMODE" 1)
(COMMAND "-INSERT" BLOCKNAME MIDPT "1" "1" NEWPT2)
(command "rotate3d" (entlast) "" 2 NEWPT1 NEWPT2 90)
(setvar "OSMODE" OLDOSMODE)
(setvar "CMDECHO" OLDCMD)
(setvar "CLAYER" LAYNAME)
(COMMAND "UNDO" "END")
(PRINC)
)

 

 

The code is unfinished so I am trying to keep it working as I build it.

Share this post


Link to post
Share on other sites
Lee Mac

Without looking over all of your code:

(setq NEWPT1 (LIST (CAR USRP1) (CADR USRP1) (+ (CADDR USRP3) TRAP_Z_OFF)))

Share this post


Link to post
Share on other sites
BIGAL

Like Lee spotted the missing "A" very quickly another way is you can use

 

(nth 0 pt); X
(nth 1 pt); Y
(nth 2 pt); Z

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×